Skip to content

Commit

Permalink
Fix indentFactor
Browse files Browse the repository at this point in the history
Remove `length() == 1` conditional; fix indentFactor
Closes #29
tresf authored and dkulp committed Dec 12, 2019
1 parent da73aad commit d80e945
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions src/main/java/org/codehaus/jettison/json/JSONObject.java
Original file line number Diff line number Diff line change
@@ -1201,34 +1201,25 @@ String toString(int indentFactor, int indent) throws JSONException {
Iterator keys = keys();
StringBuilder sb = new StringBuilder("{");
int newindent = indent + indentFactor;
Object o;
if (n == 1) {
o = keys.next();
sb.append(quote(o.toString(), escapeForwardSlashAlways));
sb.append(": ");
sb.append(valueToString(this.myHashMap.get(o), indentFactor,
indent, escapeForwardSlashAlways));
} else {
while (keys.hasNext()) {
o = keys.next();
if (sb.length() > 1) {
sb.append(",\n");
} else {
sb.append('\n');
}
for (i = 0; i < newindent; i += 1) {
sb.append(' ');
}
sb.append(quote(o.toString()));
sb.append(": ");
sb.append(valueToString(this.myHashMap.get(o), indentFactor,
newindent, escapeForwardSlashAlways));
}
while (keys.hasNext()) {
Object o = keys.next();
if (sb.length() > 1) {
sb.append(",\n");
} else {
sb.append('\n');
for (i = 0; i < indent; i += 1) {
sb.append(' ');
}
}
for (i = 0; i < newindent; i += 1) {
sb.append(' ');
}
sb.append(quote(o.toString()));
sb.append(": ");
sb.append(valueToString(this.myHashMap.get(o), indentFactor,
newindent, escapeForwardSlashAlways));
}
if (sb.length() > 1) {
sb.append('\n');
for (i = 0; i < indent; i += 1) {
sb.append(' ');
}
}
sb.append('}');
@@ -1396,4 +1387,4 @@ public boolean isEscapeForwardSlashAlways() {
public void setEscapeForwardSlashAlways(boolean escapeForwardSlashAlways) {
this.escapeForwardSlashAlways = escapeForwardSlashAlways;
}
}
}

0 comments on commit d80e945

Please sign in to comment.