Package com.google.common.escape
Class ArrayBasedCharEscaper
- java.lang.Object
-
- com.google.common.escape.Escaper
-
- com.google.common.escape.CharEscaper
-
- com.google.common.escape.ArrayBasedCharEscaper
-
@Beta @GwtCompatible public abstract class ArrayBasedCharEscaper extends CharEscaper
ACharEscaper
that uses an array to quickly look up replacement characters for a givenchar
value. An additional safe range is provided that determines whetherchar
values without specific replacements are to be considered safe and left unescaped or should be escaped in a general way.A good example of usage of this class is for Java source code escaping where the replacement array contains information about special ASCII characters such as
\\t
and\\n
whileescapeUnsafe(char)
is overridden to handle general escaping of the form\\uxxxx
.The size of the data structure used by
ArrayBasedCharEscaper
is proportional to the highest valued character that requires escaping. For example a replacement map containing the single character '\
u1000
' will require approximately 16K of memory. If you need to create multiple escaper instances that have the same character replacement mapping consider usingArrayBasedEscaperMap
.- Since:
- 15.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
escape(java.lang.String s)
Returns the escaped form of a given literal string.-
Methods inherited from class com.google.common.escape.Escaper
asFunction
-
-
-
-
Method Detail
-
escape
public final 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 classCharEscaper
- Parameters:
s
- the literal string to be escaped- Returns:
- the escaped form of
string
-
-