|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dellroad.stuff.string.StringEncoder
public final class StringEncoder
Encodes/decodes Java strings, escaping control and XML-invalid characters.
| Method Summary | |
|---|---|
static String |
decode(String text)
Decode a string encoded by encode(java.lang.String, boolean). |
static String |
dequote(String quotedString)
Dequote a string previously enquoted by enquote(java.lang.String). |
static String |
encode(String value,
boolean escapeTABNLCR)
Encode a string, escaping control and XML-invalid characters. |
static String |
enquote(byte[] data,
int off,
int len)
Enquote bytes, treating them as an ASCII string. |
static String |
enquote(String string)
Enquote a string. |
static int |
enquotedLength(String string)
Determine the length of a string previously enquoted by enquote(java.lang.String) when it appears
as the prefix of a longer string. |
static boolean |
isValidXMLChar(char ch)
Determine if the given character is a valid XML character according to the XML 1.0 specification. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static String encode(String value,
boolean escapeTABNLCR)
\uNNNN notation like Java unicode characters,
e.g., 0x001f would appear in the encoded string as \u001f.
Normal Java backslash escapes are used for tab, newline, carriage return, backspace, and formfeed.
Backslash characters are themselves encoded with a double backslash.
value - string to encode (possibly null)escapeTABNLCR - escape tab, newline, and carriage return characters as well
value, or null if value was nulldecode(java.lang.String),
isValidXMLChar(char)public static String decode(String text)
encode(java.lang.String, boolean).
The parsing is strict; any ill-formed backslash escape sequence (i.e., not of the form
\uNNNN, \b, \t, \n, \f, \r
or \\) will cause an exception to be thrown.
text - string to decode (possibly null)
text, or null if text was null
IllegalArgumentException - if text contains an invalid escape sequenceencode(java.lang.String, boolean)public static String enquote(String string)
encode(string, true) but in addition the resulting
string is surrounded by double quotes and double quotes in the string are backslash-escaped.
Note: the strings returned by this method are not suitable for decoding by decode(java.lang.String).
Use dequote(java.lang.String) instead.
public static String enquote(byte[] data,
int off,
int len)
enquote(String)public static String dequote(String quotedString)
enquote(java.lang.String).
quotedString - a string returned by enquote(java.lang.String)
IllegalArgumentException - if quotedString has an invalid format (i.e., it could not have
ever been returned by enquote(java.lang.String))public static int enquotedLength(String string)
enquote(java.lang.String) when it appears
as the prefix of a longer string. This method assumes that the prefix is a valid quoted
string; use dequote(java.lang.String) to verify.
string - a string containing a prefix returned by enquote(java.lang.String)
IllegalArgumentException - if a starting or terminating quote character is not foundpublic static boolean isValidXMLChar(char ch)
Valid characters are tab, newline, carriage return, and characters in the ranges
\u0020 - \ud7ff and \ue000 - \fffdf (inclusive).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||