in smithy-jmespath/src/main/java/software/amazon/smithy/jmespath/Lexer.java [304:393]
private String consumeInsideString() {
StringBuilder builder = new StringBuilder();
loop: while (!eof()) {
switch (peek()) {
case '"':
skip();
return builder.toString();
case '\\':
skip();
switch (peek()) {
case '"':
builder.append('"');
skip();
break;
case 'n':
builder.append('\n');
skip();
break;
case 't':
builder.append('\t');
skip();
break;
case 'r':
builder.append('\r');
skip();
break;
case 'f':
builder.append('\f');
skip();
break;
case 'b':
builder.append('\b');
skip();
break;
case '/':
builder.append('/');
skip();
break;
case '\\':
builder.append('\\');
skip();
break;
case 'u':
// Read \ u XXXX
skip();
int unicode = 0;
for (int i = 0; i < 4; i++) {
char c = peek();
skip();
if (c >= '0' && c <= '9') {
unicode = (unicode << 4) | (c - '0');
} else if (c >= 'a' && c <= 'f') {
unicode = (unicode << 4) | (10 + c - 'a');
} else if (c >= 'A' && c <= 'F') {
unicode = (unicode << 4) | (10 + c - 'A');
} else {
throw syntax("Invalid unicode escape character: `" + c + "`");
}
}
builder.append((char) unicode);
break;
case '`':
// Ticks can be escaped when parsing literals.
if (currentlyParsingLiteral) {
builder.append('`');
skip();
break;
}
// fall-through.
default:
throw syntax("Invalid escape: " + peek());
}
break;
case '`':
// If parsing a literal and an unescaped "`" is encountered,
// then the literal was erroneously closed while parsing a string.
if (currentlyParsingLiteral) {
skip();
break loop;
} // fall-through
default:
builder.append(peek());
skip();
break;
}
}
throw syntax("Unclosed quotes");
}