public final class CharEscapers extends Object
CharEscapers, and some commonly
used CharEscaper instances.| Modifier and Type | Method and Description |
|---|---|
static CharEscaper |
asciiHtmlEscaper()
Returns a
CharEscaper instance that escapes special characters in a
string so it can safely be included in an HTML document in either element
content or attribute values. |
static CharEscaper |
htmlEscaper()
Returns a
CharEscaper instance that escapes special characters in a
string so it can safely be included in an HTML document in either element
content or attribute values. |
static CharEscaper |
javaStringEscaper()
Returns a
CharEscaper instance that escapes special characters in a
string so it can safely be included in a Java string literal. |
static Escaper |
uriEscaper(boolean plusForSpace)
Returns a
Escaper instance that escapes Java characters so they can
be safely included in URIs. |
static CharEscaper |
xmlContentEscaper()
Returns a
CharEscaper instance that escapes special characters in a
string so it can safely be included in an XML document in element content. |
static CharEscaper |
xmlEscaper()
Returns a
CharEscaper instance that escapes special characters in a
string so it can safely be included in an XML document in either element
content or attribute values. |
public static CharEscaper xmlEscaper()
CharEscaper instance that escapes special characters in a
string so it can safely be included in an XML document in either element
content or attribute values.
Note
: silently removes null-characters and control characters, as there is no way to represent them in XML.public static CharEscaper xmlContentEscaper()
CharEscaper instance that escapes special characters in a
string so it can safely be included in an XML document in element content.
Note
: double and single quotes are not escaped, so it is not safe to use this escaper to escape attribute values. Use thexmlEscaper() escaper to escape attribute values or if you are
unsure. Also silently removes non-whitespace control characters, as there
is no way to represent them in XML.public static CharEscaper htmlEscaper()
CharEscaper instance that escapes special characters in a
string so it can safely be included in an HTML document in either element
content or attribute values.
Note
: alters non-ASCII and control characters. The entity list was taken from: herepublic static CharEscaper asciiHtmlEscaper()
CharEscaper instance that escapes special characters in a
string so it can safely be included in an HTML document in either element
content or attribute values.
Note
: does not alter non-ASCII and control characters.public static Escaper uriEscaper(boolean plusForSpace)
Escaper instance that escapes Java characters so they can
be safely included in URIs. For details on escaping URIs, see section 2.4
of RFC 2396.
When encoding a String, the following rules apply:
plusForSpace was specified, the space character " " is
converted into a plus sign "+". Otherwise it is converted into "%20".
Note: Unlike other escapers, URI escapers produce uppercase
hexadecimal sequences. From
RFC 3986:
"URI producers and normalizers should use uppercase hexadecimal digits
for all percent-encodings."
plusForSpace - if true space is escaped to + otherwise
it is escaped to %20. Although common, the escaping of
spaces as plus signs has a very ambiguous status in the relevant
specifications. You should prefer %20 unless you are doing
exact character-by-character comparisons of URLs and backwards
compatibility requires you to use plus signs.#uriEscaper()public static CharEscaper javaStringEscaper()
CharEscaper instance that escapes special characters in a
string so it can safely be included in a Java string literal.
Note
: does not escape single quotes, so use the escaper returned by#javaCharEscaper() if you are generating char
literals or if you are unsure.