public class JavaScriptEscaper extends Object
| Constructor and Description |
|---|
JavaScriptEscaper() |
| Modifier and Type | Method and Description |
|---|---|
static String |
escape(String str)
Escapes the characters in a
String using JavaScript String
rules. |
static void |
escape(Writer out,
String str)
Escapes the characters in a
String using JavaScript String
rules to a Writer. |
static String |
hex(char ch)
Returns an upper case hexadecimal
String for the given
character. |
public static String escape(String str)
String using JavaScript String
rules.
Escapes any values it finds into their JavaScript String literal form. 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 must be escaped.
Example:
input string: He didn't say, "Stop!" output string: He didn\'t say, \"Stop!\"
str - String to escape values in, may be nullnull if null string
inputpublic static void escape(Writer out, String str) throws IOException
String using JavaScript String
rules to a Writer.
A null string input has no effect.
out - Writer to write escaped string intostr - String to escape values in, may be nullIllegalArgumentException - if the Writer is nullIOException - if error occurs on underlying Writerescape(java.lang.String)public static String hex(char ch)
String for the given
character.ch - The character to convert.StringCopyright © 2020 Atlassian. All rights reserved.