For example, an XML escaper would convert the literal string "Foo<Bar>" into "Foo<Bar>" to prevent "<Bar>" from being confused with an XML tag. When the
resulting XML document is parsed, the parser API will return this text as the original literal
string "Foo<Bar>".
A CharEscaper instance is required to be stateless, and safe when used concurrently by
multiple threads.
Popular escapers are defined as constants in classes like com. and com.. To create
your own escapers extend this class and implement the escape(char) method.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | DEST_PAD_MULTIPLIER
The multiplier for padding to use when growing the escape buffer. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the escaped form ofstringthe literal string to be escaped string)Implements abstract com. |
| protected abstract char[] | Returns: the replacement characters, ornull if no escaping was neededthe character to escape if necessary c)Returns the escaped form of the given character, or |
| protected final String | Returns: the escaped form ofstringthe literal string to be escaped s, int the index to start escaping from index)Returns the escaped form of a given literal string, starting at the given index. |
| private static char[] | growBuffer(char[] dest, int index, int size)
Helper method to grow the character buffer as needed, this only happens once in a while so it's ok if it's in a method call. |
| DEST_PAD_MULTIPLIER | back to summary |
|---|---|
| private static final int DEST_PAD_MULTIPLIER The multiplier for padding to use when growing the escape buffer. | |
| CharEscaper | back to summary |
|---|---|
| protected CharEscaper() Constructor for use by subclasses. | |
| escape | back to summary |
|---|---|
| public String escape(String string) Implements abstract com. Returns the escaped form of a given literal string.
| |
| escape | back to summary |
|---|---|
| protected abstract char[] escape(char c) Returns the escaped form of the given character, or If the character does not need to be escaped, this method should return An escaper is expected to be able to deal with any
| |
| escapeSlow | back to summary |
|---|---|
| protected final String escapeSlow(String s, int index) Returns the escaped form of a given literal string, starting at the given index. This method is
called by the
| |
| growBuffer | back to summary |
|---|---|
| private static char[] growBuffer(char[] dest, int index, int size) Helper method to grow the character buffer as needed, this only happens once in a while so it's ok if it's in a method call. If the index passed in is 0 then no copying will be done. | |