Revert "#863 improve performance of JSONTokener#nextString"

This reverts commit 63625b3c622407273d2654660be7659ac5d74db7.
This commit is contained in:
Simulant 2024-03-10 21:12:28 +01:00
parent 5974fc1a38
commit 0c5cf18255

View File

@ -295,9 +295,12 @@ public class JSONTokener {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (;;) { for (;;) {
c = this.next(); c = this.next();
if (c == quote) { switch (c) {
return sb.toString(); case 0:
} else if (c == '\\') { case '\n':
case '\r':
throw this.syntaxError("Unterminated string");
case '\\':
c = this.next(); c = this.next();
switch (c) { switch (c) {
case 'b': case 'b':
@ -331,9 +334,11 @@ public class JSONTokener {
default: default:
throw this.syntaxError("Illegal escape."); throw this.syntaxError("Illegal escape.");
} }
} else if (c == 0 || c == '\n' || c == '\r') { break;
throw this.syntaxError("Unterminated string"); default:
} else { if (c == quote) {
return sb.toString();
}
sb.append(c); sb.append(c);
} }
} }