This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JavaEscapeUtil { | |
/** | |
* Replaces unprintable characters by their escaped (or unicode escaped) | |
* equivalents in the given string | |
*/ | |
public static String escapeJava(String str) { | |
StringBuilder retval = new StringBuilder(); | |
for (int i = 0; i < str.length(); i++) { | |
final char ch = str.charAt(i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Unescapes a string that contains standard Java escape sequences. | |
* <ul> | |
* <li><strong>\b \f \n \r \t \" \'</strong> : | |
* BS, FF, NL, CR, TAB, double and single quote.</li> | |
* <li><strong>\X \XX \XXX</strong> : Octal character | |
* specification (0 - 377, 0x00 - 0xFF).</li> | |
* <li><strong>\uXXXX</strong> : Hexadecimal based Unicode character.</li> | |
* </ul> |