Strip JSONTokener#isAtStart()

This commit is contained in:
XIAYM-gh
2026-09-11 03:57:03 +08:00
parent 359b43d8df
commit a25f83a0e4
3 changed files with 2 additions and 24 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ public class JSONArray implements Iterable<Object> {
* @throws JSONException If a syntax error occurs during the construction of the JSONArray. * @throws JSONException If a syntax error occurs during the construction of the JSONArray.
*/ */
public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException { public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
this(x, jsonParserConfiguration, x.isAtStart()); this(x, jsonParserConfiguration, true);
} }
/** /**
+1 -1
View File
@@ -214,7 +214,7 @@ public class JSONObject {
* duplicated key. * duplicated key.
*/ */
public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException { public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
this(x, jsonParserConfiguration, x.isAtStart()); this(x, jsonParserConfiguration, true);
} }
/** /**
-22
View File
@@ -31,8 +31,6 @@ public class JSONTokener {
private boolean usePrevious; private boolean usePrevious;
/** the number of characters read in the previous line. */ /** the number of characters read in the previous line. */
private long characterPreviousLine; private long characterPreviousLine;
/** number of non-whitespace characters read from the source. */
private long contentCharCount;
// access to this object is required for strict mode checking // access to this object is required for strict mode checking
private JSONParserConfiguration jsonParserConfiguration; private JSONParserConfiguration jsonParserConfiguration;
@@ -62,7 +60,6 @@ public class JSONTokener {
this.usePrevious = false; this.usePrevious = false;
this.previous = 0; this.previous = 0;
this.index = 0; this.index = 0;
this.contentCharCount = 0;
this.character = 1; this.character = 1;
this.characterPreviousLine = 0; this.characterPreviousLine = 0;
this.line = 1; this.line = 1;
@@ -123,17 +120,6 @@ public class JSONTokener {
this.jsonParserConfiguration = jsonParserConfiguration; this.jsonParserConfiguration = jsonParserConfiguration;
} }
/**
* Returns whether the tokener is positioned at the beginning,
* i.e. only whitespace characters (or no characters at all) have been read so far.
* Consuming and backing up over the first characters does not change the result.
*
* @return true if no non-whitespace character has been read
*/
protected boolean isAtStart() {
return this.contentCharCount == 0;
}
/** /**
* Back up one character. This provides a sort of lookahead capability, * Back up one character. This provides a sort of lookahead capability,
* so that you can test for a digit or letter before attempting to parse * so that you can test for a digit or letter before attempting to parse
@@ -145,9 +131,6 @@ public class JSONTokener {
if (this.usePrevious || this.index <= 0) { if (this.usePrevious || this.index <= 0) {
throw new JSONException("Stepping back two steps is not supported"); throw new JSONException("Stepping back two steps is not supported");
} }
if (this.previous > ' ') {
this.contentCharCount--;
}
this.decrementIndexes(); this.decrementIndexes();
this.usePrevious = true; this.usePrevious = true;
this.eof = false; this.eof = false;
@@ -248,9 +231,6 @@ public class JSONTokener {
return 0; return 0;
} }
this.incrementIndexes(c); this.incrementIndexes(c);
if (c > ' ') {
this.contentCharCount++;
}
this.previous = (char) c; this.previous = (char) c;
return this.previous; return this.previous;
} }
@@ -569,7 +549,6 @@ public class JSONTokener {
long startIndex = this.index; long startIndex = this.index;
long startCharacter = this.character; long startCharacter = this.character;
long startLine = this.line; long startLine = this.line;
long startContentCharCount = this.contentCharCount;
this.reader.mark(1000000); this.reader.mark(1000000);
do { do {
c = this.next(); c = this.next();
@@ -581,7 +560,6 @@ public class JSONTokener {
this.index = startIndex; this.index = startIndex;
this.character = startCharacter; this.character = startCharacter;
this.line = startLine; this.line = startLine;
this.contentCharCount = startContentCharCount;
return 0; return 0;
} }
} while (c != to); } while (c != to);