Skip to content

Commit df5a75d

Browse files
committed
Strip JSONTokener#isAtStart()
1 parent d0e0688 commit df5a75d

3 files changed

Lines changed: 2 additions & 24 deletions

File tree

src/main/java/org/json/JSONArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public JSONArray(JSONTokener x) throws JSONException {
9494
* @throws JSONException If a syntax error occurs during the construction of the JSONArray.
9595
*/
9696
public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
97-
this(x, jsonParserConfiguration, x.isAtStart());
97+
this(x, jsonParserConfiguration, true);
9898
}
9999

100100
/**

src/main/java/org/json/JSONObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public JSONObject(JSONTokener x) throws JSONException {
214214
* duplicated key.
215215
*/
216216
public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
217-
this(x, jsonParserConfiguration, x.isAtStart());
217+
this(x, jsonParserConfiguration, true);
218218
}
219219

220220
/**

src/main/java/org/json/JSONTokener.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public class JSONTokener {
3131
private boolean usePrevious;
3232
/** the number of characters read in the previous line. */
3333
private long characterPreviousLine;
34-
/** number of non-whitespace characters read from the source. */
35-
private long contentCharCount;
3634

3735
// access to this object is required for strict mode checking
3836
private JSONParserConfiguration jsonParserConfiguration;
@@ -62,7 +60,6 @@ public JSONTokener(Reader reader, JSONParserConfiguration jsonParserConfiguratio
6260
this.usePrevious = false;
6361
this.previous = 0;
6462
this.index = 0;
65-
this.contentCharCount = 0;
6663
this.character = 1;
6764
this.characterPreviousLine = 0;
6865
this.line = 1;
@@ -123,17 +120,6 @@ public void setJsonParserConfiguration(JSONParserConfiguration jsonParserConfigu
123120
this.jsonParserConfiguration = jsonParserConfiguration;
124121
}
125122

126-
/**
127-
* Returns whether the tokener is positioned at the beginning,
128-
* i.e. only whitespace characters (or no characters at all) have been read so far.
129-
* Consuming and backing up over the first characters does not change the result.
130-
*
131-
* @return true if no non-whitespace character has been read
132-
*/
133-
protected boolean isAtStart() {
134-
return this.contentCharCount == 0;
135-
}
136-
137123
/**
138124
* Back up one character. This provides a sort of lookahead capability,
139125
* so that you can test for a digit or letter before attempting to parse
@@ -145,9 +131,6 @@ public void back() throws JSONException {
145131
if (this.usePrevious || this.index <= 0) {
146132
throw new JSONException("Stepping back two steps is not supported");
147133
}
148-
if (this.previous > ' ') {
149-
this.contentCharCount--;
150-
}
151134
this.decrementIndexes();
152135
this.usePrevious = true;
153136
this.eof = false;
@@ -248,9 +231,6 @@ public char next() throws JSONException {
248231
return 0;
249232
}
250233
this.incrementIndexes(c);
251-
if (c > ' ') {
252-
this.contentCharCount++;
253-
}
254234
this.previous = (char) c;
255235
return this.previous;
256236
}
@@ -569,7 +549,6 @@ public char skipTo(char to) throws JSONException {
569549
long startIndex = this.index;
570550
long startCharacter = this.character;
571551
long startLine = this.line;
572-
long startContentCharCount = this.contentCharCount;
573552
this.reader.mark(1000000);
574553
do {
575554
c = this.next();
@@ -581,7 +560,6 @@ public char skipTo(char to) throws JSONException {
581560
this.index = startIndex;
582561
this.character = startCharacter;
583562
this.line = startLine;
584-
this.contentCharCount = startContentCharCount;
585563
return 0;
586564
}
587565
} while (c != to);

0 commit comments

Comments
 (0)