chore(#871-strictMode): reverted refactor in JSONTokener

This commit is contained in:
rikkarth 2024-03-16 01:13:52 +00:00
parent e2fe14d951
commit f3b3491f4d
No known key found for this signature in database
GPG Key ID: 11E5F28B0AED6AC7

View File

@ -311,7 +311,7 @@ public class JSONTokener {
public String nextString(char quote) throws JSONException { public String nextString(char quote) throws JSONException {
char c; char c;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (; ; ) { for (;;) {
c = this.next(); c = this.next();
switch (c) { switch (c) {
case 0: case 0:
@ -542,6 +542,8 @@ public class JSONTokener {
} }
Object nextSimpleValue(char c, boolean strictMode) { Object nextSimpleValue(char c, boolean strictMode) {
String string;
if (c == '"' || c == '\'') { if (c == '"' || c == '\'') {
String str = this.nextString(c); String str = this.nextString(c);
if (strictMode) { if (strictMode) {
@ -550,19 +552,6 @@ public class JSONTokener {
return str; return str;
} }
return parsedUnquotedText(c);
}
/**
* Parses unquoted text from the JSON input. This could be the values true, false, or null, or it can be a number.
* Non-standard forms are also accepted. Characters are accumulated until the end of the text or a formatting
* character is reached.
*
* @param c The starting character.
* @return The parsed object.
* @throws JSONException If the parsed string is empty.
*/
private Object parsedUnquotedText(char c) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
sb.append(c); sb.append(c);
@ -572,8 +561,8 @@ public class JSONTokener {
this.back(); this.back();
} }
String string = sb.toString().trim(); string = sb.toString().trim();
if (string.isEmpty()) { if ("".equals(string)) {
throw this.syntaxError("Missing value"); throw this.syntaxError("Missing value");
} }
return JSONObject.stringToValue(string); return JSONObject.stringToValue(string);