Class StringEscapeUtils
Escapes and unescapes String
s for
Java, Java Script, HTML and XML.
#ThreadSafe#
This code has been adapted from Apache Commons Lang 3.5.
- Since:
- 1.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Convenience wrapper forStringBuilder
providing escape methods. -
Field Summary
Modifier and TypeFieldDescriptionstatic final CharSequenceTranslator
Translator object for escaping Java. -
Constructor Summary
ConstructorDescriptionStringEscapeUtils
instances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringEscapeUtils.Builder
builder
(CharSequenceTranslator translator) Get aStringEscapeUtils.Builder
.static final String
escapeJava
(String input) Escapes the characters in aString
using Java String rules.
-
Field Details
-
ESCAPE_JAVA
Translator object for escaping Java.While
escapeJava(String)
is the expected method of use, this object allows the Java escaping functionality to be used as the foundation for a custom translator.
-
-
Constructor Details
-
StringEscapeUtils
public StringEscapeUtils()StringEscapeUtils
instances should NOT be constructed in standard programming.Instead, the class should be used as:
StringEscapeUtils.escapeJava("foo");
This constructor is public to permit tools that require a JavaBean instance to operate.
-
-
Method Details
-
builder
Get aStringEscapeUtils.Builder
.- Parameters:
translator
- the text translator- Returns:
StringEscapeUtils.Builder
-
escapeJava
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!\"
- Parameters:
input
- String to escape values in, may be null- Returns:
- String with escaped values,
null
if null string input
-