mirror of
https://github.com/lightbend/config.git
synced 2025-01-16 07:10:21 +08:00
Merge pull request #210 from chris-martin/pull-quoted-string-do-while
Avoid awkward do-while in Tokenizer.pullQuotedString
This commit is contained in:
commit
741b14ec6b
@ -457,23 +457,22 @@ final class Tokenizer {
|
|||||||
private Token pullQuotedString() throws ProblemException {
|
private Token pullQuotedString() throws ProblemException {
|
||||||
// the open quote has already been consumed
|
// the open quote has already been consumed
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
int c = '\0'; // value doesn't get used
|
while (true) {
|
||||||
do {
|
int c = nextCharRaw();
|
||||||
c = nextCharRaw();
|
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
throw problem("End of input but string quote was still open");
|
throw problem("End of input but string quote was still open");
|
||||||
|
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
pullEscapeSequence(sb);
|
pullEscapeSequence(sb);
|
||||||
} else if (c == '"') {
|
} else if (c == '"') {
|
||||||
// end the loop, done!
|
break;
|
||||||
} else if (Character.isISOControl(c)) {
|
} else if (Character.isISOControl(c)) {
|
||||||
throw problem(asString(c), "JSON does not allow unescaped " + asString(c)
|
throw problem(asString(c), "JSON does not allow unescaped " + asString(c)
|
||||||
+ " in quoted strings, use a backslash escape");
|
+ " in quoted strings, use a backslash escape");
|
||||||
} else {
|
} else {
|
||||||
sb.appendCodePoint(c);
|
sb.appendCodePoint(c);
|
||||||
}
|
}
|
||||||
} while (c != '"');
|
}
|
||||||
|
|
||||||
// maybe switch to triple-quoted string, sort of hacky...
|
// maybe switch to triple-quoted string, sort of hacky...
|
||||||
if (sb.length() == 0) {
|
if (sb.length() == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user