public class StringEscaper extends Object implements Cloneable
StringEscaper
is a utility for replacing special characters
with escape sequences in strings. Initially, a StringEscaper starts out as
an identity transform in the "mutable" state. Call defineEscape as many
times as necessary to set up mappings, and then call makeImmutable() before
using appendEscapedString to actually apply the defined transform. Or, use one of
the global mappings pre-defined here.
Modifier and Type | Field and Description |
---|---|
static StringEscaper |
htmlEscaper |
static StringEscaper |
urlArgEscaper |
static StringEscaper |
urlEscaper |
static StringEscaper |
xmlEscaper |
static StringEscaper |
xmlNumericEscaper |
Constructor and Description |
---|
StringEscaper()
Identity transform
|
Modifier and Type | Method and Description |
---|---|
void |
appendEscapedString(String s,
StringBuffer sb)
Apply an immutable transformation to the given string, writing the
results to a string buffer.
|
protected Object |
clone() |
void |
defineEscape(char from,
String to)
Map character "from" to escape sequence "to"
|
String |
escapeString(String s)
Apply an immutable transformation to the given string.
|
StringEscaper |
getMutableClone()
Create a mutable escaper from an existing escaper, which may
already be immutable.
|
void |
makeImmutable()
Call this before attempting to escape strings; after this,
defineEscape may not be called again.
|
public static StringEscaper xmlEscaper
public static StringEscaper xmlNumericEscaper
public static StringEscaper htmlEscaper
public static StringEscaper urlArgEscaper
public static StringEscaper urlEscaper
public StringEscaper()
public void defineEscape(char from, String to)
public void makeImmutable()
public String escapeString(String s)
public void appendEscapedString(String s, StringBuffer sb)
public StringEscaper getMutableClone()