Apply corner-case fixes under instruction
This commit is contained in:
@@ -31,6 +31,8 @@ public class JSONTokener {
|
||||
private boolean usePrevious;
|
||||
/** the number of characters read in the previous line. */
|
||||
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
|
||||
private JSONParserConfiguration jsonParserConfiguration;
|
||||
@@ -60,6 +62,7 @@ public class JSONTokener {
|
||||
this.usePrevious = false;
|
||||
this.previous = 0;
|
||||
this.index = 0;
|
||||
this.contentCharCount = 0;
|
||||
this.character = 1;
|
||||
this.characterPreviousLine = 0;
|
||||
this.line = 1;
|
||||
@@ -121,12 +124,14 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the tokener is currently positioned at the beginning,
|
||||
* 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 the current input position is the beginning
|
||||
* @return true if no non-whitespace character has been read
|
||||
*/
|
||||
public boolean isAtStart() {
|
||||
return this.index == 0;
|
||||
protected boolean isAtStart() {
|
||||
return this.contentCharCount == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,6 +145,9 @@ public class JSONTokener {
|
||||
if (this.usePrevious || this.index <= 0) {
|
||||
throw new JSONException("Stepping back two steps is not supported");
|
||||
}
|
||||
if (this.previous > ' ') {
|
||||
this.contentCharCount--;
|
||||
}
|
||||
this.decrementIndexes();
|
||||
this.usePrevious = true;
|
||||
this.eof = false;
|
||||
@@ -240,6 +248,9 @@ public class JSONTokener {
|
||||
return 0;
|
||||
}
|
||||
this.incrementIndexes(c);
|
||||
if (c > ' ') {
|
||||
this.contentCharCount++;
|
||||
}
|
||||
this.previous = (char) c;
|
||||
return this.previous;
|
||||
}
|
||||
@@ -558,6 +569,7 @@ public class JSONTokener {
|
||||
long startIndex = this.index;
|
||||
long startCharacter = this.character;
|
||||
long startLine = this.line;
|
||||
long startContentCharCount = this.contentCharCount;
|
||||
this.reader.mark(1000000);
|
||||
do {
|
||||
c = this.next();
|
||||
@@ -569,6 +581,7 @@ public class JSONTokener {
|
||||
this.index = startIndex;
|
||||
this.character = startCharacter;
|
||||
this.line = startLine;
|
||||
this.contentCharCount = startContentCharCount;
|
||||
return 0;
|
||||
}
|
||||
} while (c != to);
|
||||
|
||||
Reference in New Issue
Block a user