in tapestry-json/src/main/java/org/apache/tapestry5/json/JSONTokener.java [267:320]
private char readEscapeCharacter() {
char escaped = in.charAt(pos++);
switch (escaped) {
case 'u': {
if (pos + 4 > in.length()) {
throw syntaxError("Unterminated escape sequence");
}
String hex = in.substring(pos, pos + 4);
try {
return (char) Integer.parseInt(hex, 16);
} catch (NumberFormatException nfe) {
throw syntaxError("Invalid escape sequence: " + hex);
}
finally {
pos += 4;
}
}
case 'x': {
if (pos + 2 > in.length()) {
throw syntaxError("Unterminated escape sequence");
}
String hex = in.substring(pos, pos + 2);
try {
return (char) Integer.parseInt(hex, 16);
} catch (NumberFormatException nfe) {
throw syntaxError("Invalid escape sequence: " + hex);
}
finally {
pos += 2;
}
}
case 't':
return '\t';
case 'b':
return '\b';
case 'n':
return '\n';
case 'r':
return '\r';
case 'f':
return '\f';
case '\'':
case '"':
case '\\':
default:
return escaped;
}
}