in platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/KarafStringEscapeUtils.java [51:133]
public static String unescapeJava(String str) {
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;
for (int i = 0; i < sz; i++) {
char ch = str.charAt(i);
if (inUnicode) {
// if in unicode, then we're reading unicode
// values in somehow
unicode.append(ch);
if (unicode.length() == UNICODE_LEN) {
// unicode now contains the four hex digits
// which represents our unicode character
try {
int value = Integer.parseInt(unicode.toString(), HEX_RADIX);
out.append((char) value);
unicode.setLength(0);
inUnicode = false;
hadSlash = false;
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException("Unable to parse unicode value: " + unicode, nfe);
}
}
continue;
}
if (hadSlash) {
// handle an escaped value
hadSlash = false;
switch (ch) {
case '\\':
out.append('\\');
break;
case '\'':
out.append('\'');
break;
case '\"':
out.append('"');
break;
case 'r':
out.append('\r');
break;
case 'f':
out.append('\f');
break;
case 't':
out.append('\t');
break;
case 'n':
out.append('\n');
break;
case 'b':
out.append('\b');
break;
case 'u':
// uh-oh, we're in unicode country....
inUnicode = true;
break;
default:
out.append(ch);
break;
}
continue;
} else if (ch == '\\') {
hadSlash = true;
continue;
}
out.append(ch);
}
if (hadSlash) {
// then we're in the weird case of a \ at the end of the
// string, let's output it anyway.
out.append('\\');
}
return out.toString();
}