public class ValueXmlHelper
extends java.lang.Object
Constructor and Description |
---|
ValueXmlHelper() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
escapeResourceString(java.lang.String string)
Escapes a string resource value in compliance with the
rules
and
this Android Cookbook recipe.
|
static java.lang.String |
escapeResourceString(java.lang.String string,
boolean escapeMarkupDelimiters)
Escapes a string resource value in compliance with the
rules
and
this Android Cookbook recipe.
|
static java.lang.String |
escapeResourceStringAsXml(java.lang.String xml)
Escapes a string resource value in compliance with the
rules
and
this Android Cookbook recipe.
|
static java.lang.String |
unescapeResourceString(java.lang.String s,
boolean escapeEntities,
boolean trim)
Replaces escapes in an XML resource string with the actual characters, performing unicode
substitutions (replacing any
\\uNNNN references in the given string with the
corresponding unicode characters), etc. |
@Nullable public static java.lang.String unescapeResourceString(@Nullable java.lang.String s, boolean escapeEntities, boolean trim)
\\uNNNN
references in the given string with the
corresponding unicode characters), etc.s
- the string to unescapeescapeEntities
- XML entitiestrim
- whether surrounding space and quotes should be trimmed@NonNull public static java.lang.String escapeResourceString(@NonNull java.lang.String string)
Escapes a string resource value in compliance with the rules and this Android Cookbook recipe.
The entire string is escaped as follows:
'"'
and '\\'
are escaped with backslashes
'\n'
and '\t'
are escaped with "\\n"
and "\\t"
'"'
'\''
is escaped with a
backslash
'?'
or '@'
, that character is escaped with a
backslash
'&'
and '<'
are escaped with "&"
and "<"
If the string contains markup it will lose its semantics and become plain character data.
If that is not desired, use escapeResourceStringAsXml(String)
which is XML aware.
@NonNull public static java.lang.String escapeResourceString(@NonNull java.lang.String string, boolean escapeMarkupDelimiters)
Escapes a string resource value in compliance with the rules and this Android Cookbook recipe.
The entire string is escaped as follows:
'"'
and '\\'
are escaped with backslashes
'\n'
and '\t'
are escaped with "\\n"
and "\\t"
'"'
'\''
is escaped with a
backslash
'?'
or '@'
, that character is escaped with a
backslash
'&'
and '<'
are escaped with
"&"
and "<"
If the string contains markup with attributes, the quotes will be escaped which will
result in invalid XML. If escapeMarkupDelimiters is true, the markup will lose its semantics
and become plain character data. If that is not desired, use
escapeResourceStringAsXml(String)
which is XML aware.
escapeMarkupDelimiters
- if true escape '&'
and '<'
with their entity
references@NonNull public static java.lang.String escapeResourceStringAsXml(@NonNull java.lang.String xml)
Escapes a string resource value in compliance with the rules and this Android Cookbook recipe.
The argument is expected to be valid XML. Character data outside of CDATA sections is escaped as follows:
'"'
and '\\'
are escaped with backslashes
'\n'
and '\t'
are escaped with "\\n"
and "\\t"
'"'
'\''
is escaped with a
backslash
'?'
or '@'
, that character is escaped with a
backslash
java.lang.IllegalArgumentException
- If the XML is not valid