Class CharEscaperBuilder.CharArrayDecorator

  • Enclosing class:
    CharEscaperBuilder

    private static class CharEscaperBuilder.CharArrayDecorator
    extends CharEscaper
    Simple decorator that turns an array of replacement char[]s into a CharEscaper, this results in a very fast escape method.
    • Constructor Summary

      Constructors 
      Constructor Description
      CharArrayDecorator​(char[][] replacements)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected char[] escape​(char c)
      Returns the escaped form of the given character, or null if this character does not need to be escaped.
      java.lang.String escape​(java.lang.String s)
      Returns the escaped form of a given literal string.
      • Methods inherited from class java.lang.Object

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

      • replacements

        private final char[][] replacements
      • replaceLength

        private final int replaceLength
    • Constructor Detail

      • CharArrayDecorator

        CharArrayDecorator​(char[][] replacements)
    • Method Detail

      • escape

        public java.lang.String escape​(java.lang.String s)
        Description copied from class: CharEscaper
        Returns the escaped form of a given literal string.
        Overrides:
        escape in class CharEscaper
        Parameters:
        s - the literal string to be escaped
        Returns:
        the escaped form of string
      • escape

        @CheckForNull
        protected char[] escape​(char c)
        Description copied from class: CharEscaper
        Returns the escaped form of the given character, or null if this character does not need to be escaped. If an empty array is returned, this effectively strips the input character from the resulting text.

        If the character does not need to be escaped, this method should return null, rather than a one-character array containing the character itself. This enables the escaping algorithm to perform more efficiently.

        An escaper is expected to be able to deal with any char value, so this method should not throw any exceptions.

        Specified by:
        escape in class CharEscaper
        Parameters:
        c - the character to escape if necessary
        Returns:
        the replacement characters, or null if no escaping was needed