Skip to content

Commit

Permalink
stleary#863 replace short switch statements with if-else
Browse files Browse the repository at this point in the history
  • Loading branch information
Simulant87 committed Mar 5, 2024
1 parent 5407423 commit c010033
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/json/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,11 @@ public JSONObject(JSONTokener x) throws JSONException {
}
c = x.nextClean();
for (;;) {
switch (c) {
case 0:
if (c == 0) {
throw x.syntaxError("A JSONObject text must end with '}'");
case '}':
} else if (c == '}') {
return;
default:
} else {
key = x.nextSimpleValue(c).toString();
}

Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/json/JSONTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,14 @@ public String nextTo(String delimiters) throws JSONException {
*/
public Object nextValue() throws JSONException {
char c = this.nextClean();
switch (c) {
case '{':
if (c == '{') {
this.back();
try {
return new JSONObject(this);
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
case '[':
} else if (c == '[') {
this.back();
try {
return new JSONArray(this);
Expand All @@ -419,9 +418,7 @@ public Object nextValue() throws JSONException {
Object nextSimpleValue(char c) {
String string;

switch (c) {
case '"':
case '\'':
if (c == '"' || c == '\'') {
return this.nextString(c);
}

Expand Down

0 comments on commit c010033

Please sign in to comment.