Class Escape


  • public class Escape
    extends java.lang.Object
    This class tries to define an interface to deal with quoting, escaping, and the way back. The quoting algorithm is safe to only itself. Thus,
     unescape( escape( s ) ) === s
     
    holds true, but
     escape( unescape( s ) ) =?= s
     
    does not necessarily hold.
    Version:
    $Revision: 1.1 $
    Author:
    Gaurang Mehta, Karan Vahi, Jens-S. Vöckler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String m_escapable
      Defines the set of characters that require escaping.
      private char m_escape
      Defines the character used to escape characters.
    • Constructor Summary

      Constructors 
      Constructor Description
      Escape()
      Defines the default quoting and escaping rules, escaping the apostrophe, double quote and backslash.
      Escape​(java.lang.String escapable, char escape)
      Constructs arbitrary escaping rules.
      Escape​(java.lang.String escapable, char escape, boolean escapeEscape)
      Constructs arbitrary escaping rules.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String escape​(java.lang.String s)
      Transforms a given string by escaping all characters inside the quotable characters set with the escape character.
      static void main​(java.lang.String[] args)
      Test program.
      java.lang.String unescape​(java.lang.String s)
      Transforms a given string by unescaping all characters that are prefixed with the escape character.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • m_escape

        private char m_escape
        Defines the character used to escape characters.
      • m_escapable

        private java.lang.String m_escapable
        Defines the set of characters that require escaping.
    • Constructor Detail

      • Escape

        public Escape()
        Defines the default quoting and escaping rules, escaping the apostrophe, double quote and backslash. The escape character is the backslash.
      • Escape

        public Escape​(java.lang.String escapable,
                      char escape)
        Constructs arbitrary escaping rules.
        Parameters:
        escapable - is the set of characters that require escaping
        escape - is the escape character itself.
      • Escape

        public Escape​(java.lang.String escapable,
                      char escape,
                      boolean escapeEscape)
        Constructs arbitrary escaping rules.
        Parameters:
        escapable - is the set of characters that require escaping
        escape - is the escape character itself.
        escapeEscape - boolean indicating whether escape character itself should be escaped if not present in escapable.
    • Method Detail

      • escape

        public java.lang.String escape​(java.lang.String s)
        Transforms a given string by escaping all characters inside the quotable characters set with the escape character. The escape character itself is also escaped.
        Parameters:
        s - is the string to escape.
        Returns:
        the quoted string
        See Also:
        unescape( String )
      • unescape

        public java.lang.String unescape​(java.lang.String s)
        Transforms a given string by unescaping all characters that are prefixed with the escape character.
        Parameters:
        s - is the string to remove escapes from.
        Returns:
        the quoted string
        See Also:
        unescape( String )
      • main

        public static void main​(java.lang.String[] args)
        Test program.
        Parameters:
        args - are command-line arguments