Class TextUtils


  • public class TextUtils
    extends java.lang.Object
    Join/split and escape/unescape strings
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TextUtils.Partial
      A partial unescape result
    • Constructor Summary

      Constructors 
      Constructor Description
      TextUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String escape​(java.lang.String input, char echar, char[] special)
      Escape the input string using the escape delimiter for the given special chars
      static java.lang.String join​(java.lang.String[] input, char separator)
      Join an array of strings with the given separator, without escaping
      static java.lang.String joinEscaped​(java.lang.String[] input, char separator, char echar, char[] special)
      Join an array of strings with the given separator, escape char, and other special chars for escaping
      static java.lang.String[] splitUnescape​(java.lang.String input, char[] separators, char echar, char[] special)
      Split the input on the given separator char, and unescape each portion using the escape char and special chars
      static java.lang.String[] splitUnescape​(java.lang.String input, char separator, char echar, char[] special)
      Split the input on the given separator char, and unescape each portion using the escape char and special chars
      static java.lang.String unescape​(java.lang.String input, char echar, char[] allowEscaped)
      Unescape the input string by removing the escape char for allowed chars
      static TextUtils.Partial unescape​(java.lang.String input, char echar, char[] allowEscaped, char[] delimiter)
      Unescape the input string by removing the escape char for allowed chars
      • Methods inherited from class java.lang.Object

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

      • TextUtils

        public TextUtils()
    • Method Detail

      • escape

        public static java.lang.String escape​(java.lang.String input,
                                              char echar,
                                              char[] special)
        Escape the input string using the escape delimiter for the given special chars
        Parameters:
        input - input string
        echar - escape char
        special - all chars that should be escaped, the escape char itself will be automatically included
        Returns:
        escaped string
      • unescape

        public static java.lang.String unescape​(java.lang.String input,
                                                char echar,
                                                char[] allowEscaped)
        Unescape the input string by removing the escape char for allowed chars
        Parameters:
        input - input string
        echar - escape char
        allowEscaped - all chars that can be escaped by the escape char
        Returns:
        unescaped string
      • unescape

        public static TextUtils.Partial unescape​(java.lang.String input,
                                                 char echar,
                                                 char[] allowEscaped,
                                                 char[] delimiter)
        Unescape the input string by removing the escape char for allowed chars
        Parameters:
        input - input string
        echar - escape char
        allowEscaped - all chars that can be escaped by the escape char
        delimiter - all chars that indicate parsing should stop
        Returns:
        partial unescape result
      • join

        public static java.lang.String join​(java.lang.String[] input,
                                            char separator)
        Join an array of strings with the given separator, without escaping
        Parameters:
        input - input string
        separator - separator
        Returns:
        joined string
      • joinEscaped

        public static java.lang.String joinEscaped​(java.lang.String[] input,
                                                   char separator,
                                                   char echar,
                                                   char[] special)
        Join an array of strings with the given separator, escape char, and other special chars for escaping
        Parameters:
        input - input string
        separator - separator
        echar - escape char
        special - all special chars not necessarily including the echar or separator
        Returns:
        joined string
      • splitUnescape

        public static java.lang.String[] splitUnescape​(java.lang.String input,
                                                       char separator,
                                                       char echar,
                                                       char[] special)
        Split the input on the given separator char, and unescape each portion using the escape char and special chars
        Parameters:
        input - input string
        separator - char separating each component
        echar - escape char
        special - chars that are escaped
        Returns:
        results
      • splitUnescape

        public static java.lang.String[] splitUnescape​(java.lang.String input,
                                                       char[] separators,
                                                       char echar,
                                                       char[] special)
        Split the input on the given separator char, and unescape each portion using the escape char and special chars
        Parameters:
        input - input string with components separated by the the separator chars
        separators - chars separating each component
        echar - escape char
        special - additional chars that are escaped, does not need to include echar or separators
        Returns:
        the unescaped components of the input