Java Utililty Methods Java String Unescape

List of utility methods to do Java String Unescape

Description

The list of methods to do Java String Unescape are organized into topic(s).

Method

StringunescapeJava(final String s)
unescape java strings well enough for our purposes.
final StringBuilder b = new StringBuilder();
final int n = s.length();
for (int i = 0; i < n;) {
    final char c = s.charAt(i++);
    if (c == '\\' && i < n) {
        final char e = s.charAt(i++);
        switch (e) {
        case 'u': {
...
StringunescapeJava(final String str)
unescape Java
final char[] chars = str.toCharArray();
final StringBuilder sb = new StringBuilder(str.length());
for (int i = 0; i < chars.length; ++i) {
    char c = chars[i];
    if (c != '\\') {
        sb.append(c);
    } else {
        ++i;
...
StringunescapeJava(final String str)
Unescape java.
if (str == null) {
    return null;
StringBuilder writer = new StringBuilder(str.length());
unescapeJava(writer, str);
String result = writer.toString();
writer.setLength(0);
return result;
...
StringunescapeJava(String escaped)
unescape Java
if (escaped.indexOf("\\u") == -1)
    return escaped;
String processed = "";
int position = escaped.indexOf("\\u");
while (position != -1) {
    if (position != 0)
        processed += escaped.substring(0, position);
    String token = escaped.substring(position + 2, position + 6);
...
StringunescapeJava(String s)
Turns a printable Java string literal (minus the quotes) into a string.
final int sLength = s.length();
final StringBuilder result = new StringBuilder(sLength);
for (int i = 0; i < sLength; ++i) {
    final char c = s.charAt(i);
    if (c == '\\' && i < sLength - 1) {
        char next = s.charAt(++i);
        if (next == 'n') {
            result.append('\n');
...
StringunescapeJava(String str)

Unescapes any Java literals found in the String to a Writer.

This is a slightly modified version of the StringEscapeUtils.unescapeJava() function in commons-lang that doesn't drop escaped separators (i.e '\,').
if (str == null) {
    return null;
int sz = str.length();
StringBuffer out = new StringBuffer(sz);
StringBuffer unicode = new StringBuffer(UNICODE_LEN);
boolean hadSlash = false;
boolean inUnicode = false;
...
StringunescapeJava(String value)
unescape Java
if (value == null || value.length() == 0) {
    return value;
StringBuilder buf = null;
int len = value.length();
int len1 = len - 1;
for (int i = 0; i < len; i++) {
    char ch = value.charAt(i);
...