Class StringParser

  • Direct Known Subclasses:
    JexlParser

    public class StringParser
    extends java.lang.Object
    Common constant strings utilities.

    This package methods read JEXL string literals and handle escaping through the 'backslash' (ie: \) character. Escaping is used to neutralize string delimiters (the single and double quotes) and read Unicode hexadecimal encoded characters.

    The only escapable characters are the single and double quotes - ''' and '"' -, a Unicode sequence starting with 'u' followed by 4 hexadecimals and the backslash character - '\' - itself.

    A sequence where '\' occurs before any non-escapable character or sequence has no effect, the sequence output being the same as the input.

    • Constructor Summary

      Constructors 
      Constructor Description
      StringParser()
      Default constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildString​(java.lang.CharSequence str, boolean eatsep)
      Builds a string, handles escaping through '\' syntax.
      static java.lang.String escapeString​(java.lang.String str, char delim)
      Escapes a String representation, expand non-ASCII characters as Unicode escape sequence.
      static int readString​(java.lang.StringBuilder strb, java.lang.CharSequence str, int index, char sep)
      Read the remainder of a string till a given separator, handles escaping through '\' syntax.
      • Methods inherited from class java.lang.Object

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

    • Method Detail

      • buildString

        public static java.lang.String buildString​(java.lang.CharSequence str,
                                                   boolean eatsep)
        Builds a string, handles escaping through '\' syntax.
        Parameters:
        str - the string to build from
        eatsep - whether the separator, the first character, should be considered
        Returns:
        the built string
      • readString

        public static int readString​(java.lang.StringBuilder strb,
                                     java.lang.CharSequence str,
                                     int index,
                                     char sep)
        Read the remainder of a string till a given separator, handles escaping through '\' syntax.
        Parameters:
        strb - the destination buffer to copy characters into
        str - the origin
        index - the offset into the origin
        sep - the separator, single or double quote, marking end of string
        Returns:
        the offset in origin
      • escapeString

        public static java.lang.String escapeString​(java.lang.String str,
                                                    char delim)
        Escapes a String representation, expand non-ASCII characters as Unicode escape sequence.
        Parameters:
        str - the string to escape
        Returns:
        the escaped representation