public class StringEscapeUtils
extends java.lang.Object
Unescapes escaped chars in strings.
Modifier and Type | Class and Description |
---|---|
private static class |
StringEscapeUtils.AggregateTranslator
Adapted from apache commons-lang3 project.
|
private static class |
StringEscapeUtils.CharSequenceTranslator
Adapted from apache commons-lang3 project.
|
private static class |
StringEscapeUtils.LookupTranslator
Adapted from apache commons-lang3 project.
|
private static class |
StringEscapeUtils.OctalUnescaper
Adapted from apache commons-lang3 project.
|
private static class |
StringEscapeUtils.UnicodeUnescaper
Adapted from apache commons-lang3 project.
|
Modifier and Type | Field and Description |
---|---|
private static StringEscapeUtils.CharSequenceTranslator |
ESCAPE_JAVA |
private static java.lang.String[][] |
JAVA_CTRL_CHARS_ESCAPE |
private static java.lang.String[][] |
JAVA_CTRL_CHARS_UNESCAPE |
private static StringEscapeUtils.CharSequenceTranslator |
UNESCAPE_JAVA |
Modifier | Constructor and Description |
---|---|
private |
StringEscapeUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
escapeJava(java.lang.String input)
Escapes the characters in a
String using Java String rules. |
static java.lang.String |
unescapeJava(java.lang.String input)
Unescapes any Java literals found in the
String . |
private static final java.lang.String[][] JAVA_CTRL_CHARS_UNESCAPE
private static final java.lang.String[][] JAVA_CTRL_CHARS_ESCAPE
private static final StringEscapeUtils.CharSequenceTranslator ESCAPE_JAVA
private static final StringEscapeUtils.CharSequenceTranslator UNESCAPE_JAVA
public static java.lang.String escapeJava(java.lang.String input)
Escapes the characters in a String
using Java String rules.
Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
So a tab becomes the characters '\\'
and
't'
.
The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote and forward-slash (/) are escaped.
Example:
input string: He didn't say, "Stop!" output string: He didn't say, \"Stop!\"
input
- String to escape values in, may be nullnull
if null string inputpublic static java.lang.String unescapeJava(java.lang.String input)
Unescapes any Java literals found in the String
.
For example, it will turn a sequence of '\'
and
'n'
into a newline character, unless the '\'
is preceded by another '\'
.
input
- the String
to unescape, may be nullString
, null
if null string input