Package org.apache.karaf.util
Class StringEscapeUtils
- java.lang.Object
-
- org.apache.karaf.util.StringEscapeUtils
-
public class StringEscapeUtils extends Object
Util class to manipulate String, especially around escape/unescape.
-
-
Constructor Summary
Constructors Constructor Description StringEscapeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringescapeJava(String str)Escapes the characters in aStringusing Java String rules.static Stringhex(char ch)Returns an upper case hexadecimalStringfor the given character.static StringunescapeJava(String str)Unescapes any Java literals found in theStringto aWriter.
-
-
-
Method Detail
-
unescapeJava
public static String unescapeJava(String str)
Unescapes any Java literals found in the
This is a slightly modified version of the StringEscapeUtils.unescapeJava() function in commons-lang that doesn't drop escaped separators (i.e '\,').Stringto aWriter.- Parameters:
str- theStringto unescape, may be null- Returns:
- the processed string
- Throws:
IllegalArgumentException- if the Writer isnull
-
escapeJava
public static String escapeJava(String str)
Escapes the characters in a
Stringusing 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 must be escaped.
Example:input string: He didn't say, "Stop!" output string: He didn't say, \"Stop!\"
- Parameters:
str- String to escape values in, may be null- Returns:
- String with escaped values,
nullif null string input
-
hex
public static String hex(char ch)
Returns an upper case hexadecimal
Stringfor the given character.- Parameters:
ch- The character to convert.- Returns:
- An upper case hexadecimal
String
-
-