Skip to content

Commit

Permalink
fix(stleary#871-strictMode): replaced stream with conventional loop f…
Browse files Browse the repository at this point in the history
…or 1.6 compatibility
  • Loading branch information
rikkarth committed Mar 16, 2024
1 parent 0ff368c commit e2fe14d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/org/json/JSONTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public String nextTo(char delimiter) throws JSONException {
public String nextTo(String delimiters) throws JSONException {
char c;
StringBuilder sb = new StringBuilder();
for (;;) {
for (; ; ) {
c = this.next();
if (delimiters.indexOf(c) >= 0 || c == 0 ||
c == '\n' || c == '\r') {
Expand Down Expand Up @@ -457,9 +457,9 @@ private Object getValue(char c, boolean strictMode) {
if (strictMode) {
Object valueToValidate = nextSimpleValue(c, true);

boolean isNumeric = valueToValidate.toString().chars().allMatch( Character::isDigit );
boolean isNumeric = checkIfValueIsNumeric(valueToValidate);

if(isNumeric){
if (isNumeric) {
return valueToValidate;
}

Expand All @@ -475,6 +475,15 @@ private Object getValue(char c, boolean strictMode) {
return nextSimpleValue(c);
}

private boolean checkIfValueIsNumeric(Object valueToValidate) {
for (char c : valueToValidate.toString().toCharArray()) {
if (!Character.isDigit(c)) {
return false;
}
}
return true;
}

/**
* This method is used to get a JSONObject from the JSONTokener. The strictMode parameter controls the behavior of
* the method when parsing the JSONObject.
Expand Down

0 comments on commit e2fe14d

Please sign in to comment.