Skip to content

Commit 60dd538

Browse files
author
Stefan Hoth
committed
Merge from upstream/master (original repo)
2 parents 910b161 + 92038ce commit 60dd538

28 files changed

+9339
-1403
lines changed

src/main/java/org/json/CDL.java

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ private static String getValue(JSONTokener x) throws JSONException {
6464
return null;
6565
case '"':
6666
case '\'':
67-
q = c;
68-
sb = new StringBuffer();
69-
for (;;) {
70-
c = x.next();
71-
if (c == q) {
72-
break;
73-
}
67+
q = c;
68+
sb = new StringBuffer();
69+
for (;;) {
70+
c = x.next();
71+
if (c == q) {
72+
break;
73+
}
7474
if (c == 0 || c == '\n' || c == '\r') {
7575
throw x.syntaxError("Missing close quote '" + q + "'.");
7676
}
7777
sb.append(c);
78-
}
78+
}
7979
return sb.toString();
8080
case ',':
8181
x.back();
@@ -98,7 +98,7 @@ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
9898
String value = getValue(x);
9999
char c = x.next();
100100
if (value == null ||
101-
(ja.length() == 0 && value.length() == 0 && c != ',')) {
101+
(ja.length() == 0 && value.length() == 0 && c != ',')) {
102102
return null;
103103
}
104104
ja.put(value);
@@ -135,43 +135,43 @@ public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)
135135
}
136136

137137
/**
138-
* Produce a comma delimited text row from a JSONArray. Values containing
139-
* the comma character will be quoted. Troublesome characters may be
140-
* removed.
141-
* @param ja A JSONArray of strings.
142-
* @return A string ending in NEWLINE.
143-
*/
144-
public static String rowToString(JSONArray ja) {
145-
StringBuffer sb = new StringBuffer();
146-
for (int i = 0; i < ja.length(); i += 1) {
147-
if (i > 0) {
148-
sb.append(',');
149-
}
150-
Object object = ja.opt(i);
151-
if (object != null) {
152-
String string = object.toString();
153-
if (string.length() > 0 && (string.indexOf(',') >= 0 ||
154-
string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 ||
155-
string.indexOf(0) >= 0 || string.charAt(0) == '"')) {
156-
sb.append('"');
157-
int length = string.length();
158-
for (int j = 0; j < length; j += 1) {
159-
char c = string.charAt(j);
160-
if (c >= ' ' && c != '"') {
161-
sb.append(c);
162-
}
163-
}
164-
sb.append('"');
165-
} else {
166-
sb.append(string);
167-
}
168-
}
169-
}
170-
sb.append('\n');
171-
return sb.toString();
172-
}
138+
* Produce a comma delimited text row from a JSONArray. Values containing
139+
* the comma character will be quoted. Troublesome characters may be
140+
* removed.
141+
* @param ja A JSONArray of strings.
142+
* @return A string ending in NEWLINE.
143+
*/
144+
public static String rowToString(JSONArray ja) {
145+
StringBuffer sb = new StringBuffer();
146+
for (int i = 0; i < ja.length(); i += 1) {
147+
if (i > 0) {
148+
sb.append(',');
149+
}
150+
Object object = ja.opt(i);
151+
if (object != null) {
152+
String string = object.toString();
153+
if (string.length() > 0 && (string.indexOf(',') >= 0 ||
154+
string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 ||
155+
string.indexOf(0) >= 0 || string.charAt(0) == '"')) {
156+
sb.append('"');
157+
int length = string.length();
158+
for (int j = 0; j < length; j += 1) {
159+
char c = string.charAt(j);
160+
if (c >= ' ' && c != '"') {
161+
sb.append(c);
162+
}
163+
}
164+
sb.append('"');
165+
} else {
166+
sb.append(string);
167+
}
168+
}
169+
}
170+
sb.append('\n');
171+
return sb.toString();
172+
}
173173

174-
/**
174+
/**
175175
* Produce a JSONArray of JSONObjects from a comma delimited text string,
176176
* using the first row as a source of names.
177177
* @param string The comma delimited text.

src/main/java/org/json/HTTP.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ public static String toString(JSONObject jo) throws JSONException {
148148
sb.append(CRLF);
149149
while (keys.hasNext()) {
150150
string = keys.next().toString();
151-
if (!string.equals("HTTP-Version") && !string.equals("Status-Code") &&
152-
!string.equals("Reason-Phrase") && !string.equals("Method") &&
153-
!string.equals("Request-URI") && !jo.isNull(string)) {
151+
if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) &&
152+
!"Reason-Phrase".equals(string) && !"Method".equals(string) &&
153+
!"Request-URI".equals(string) && !jo.isNull(string)) {
154154
sb.append(string);
155155
sb.append(": ");
156156
sb.append(jo.getString(string));

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

100755100644
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ of this software and associated documentation files (the "Software"), to deal
7676
* </ul>
7777
7878
* @author JSON.org
79-
* @version 2011-11-24
79+
* @version 2011-12-19
8080
*/
8181
public class JSONArray {
8282

@@ -105,29 +105,29 @@ public JSONArray(JSONTokener x) throws JSONException {
105105
throw x.syntaxError("A JSONArray text must start with '['");
106106
}
107107
if (x.nextClean() != ']') {
108-
x.back();
109-
for (;;) {
110-
if (x.nextClean() == ',') {
111-
x.back();
112-
this.myArrayList.add(JSONObject.NULL);
113-
} else {
114-
x.back();
115-
this.myArrayList.add(x.nextValue());
116-
}
117-
switch (x.nextClean()) {
118-
case ';':
119-
case ',':
120-
if (x.nextClean() == ']') {
121-
return;
122-
}
123-
x.back();
124-
break;
125-
case ']':
126-
return;
127-
default:
128-
throw x.syntaxError("Expected a ',' or ']'");
129-
}
130-
}
108+
x.back();
109+
for (;;) {
110+
if (x.nextClean() == ',') {
111+
x.back();
112+
this.myArrayList.add(JSONObject.NULL);
113+
} else {
114+
x.back();
115+
this.myArrayList.add(x.nextValue());
116+
}
117+
switch (x.nextClean()) {
118+
case ';':
119+
case ',':
120+
if (x.nextClean() == ']') {
121+
return;
122+
}
123+
x.back();
124+
break;
125+
case ']':
126+
return;
127+
default:
128+
throw x.syntaxError("Expected a ',' or ']'");
129+
}
130+
}
131131
}
132132
}
133133

@@ -149,13 +149,13 @@ public JSONArray(String source) throws JSONException {
149149
* @param collection A Collection.
150150
*/
151151
public JSONArray(Collection collection) {
152-
this.myArrayList = new ArrayList();
153-
if (collection != null) {
154-
Iterator iter = collection.iterator();
155-
while (iter.hasNext()) {
152+
this.myArrayList = new ArrayList();
153+
if (collection != null) {
154+
Iterator iter = collection.iterator();
155+
while (iter.hasNext()) {
156156
this.myArrayList.add(JSONObject.wrap(iter.next()));
157-
}
158-
}
157+
}
158+
}
159159
}
160160

161161

@@ -555,8 +555,8 @@ public String optString(int index) {
555555
public String optString(int index, String defaultValue) {
556556
Object object = this.opt(index);
557557
return JSONObject.NULL.equals(object)
558-
? object.toString()
559-
: defaultValue;
558+
? defaultValue
559+
: object.toString();
560560
}
561561

562562

@@ -775,7 +775,7 @@ public JSONArray put(int index, Object value) throws JSONException {
775775
* or null if there was no value.
776776
*/
777777
public Object remove(int index) {
778-
Object o = this.opt(index);
778+
Object o = this.opt(index);
779779
this.myArrayList.remove(index);
780780
return o;
781781
}

src/main/java/org/json/JSONException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* @version 2010-12-24
77
*/
88
public class JSONException extends Exception {
9-
private static final long serialVersionUID = 0;
10-
private Throwable cause;
9+
private static final long serialVersionUID = 0;
10+
private Throwable cause;
1111

1212
/**
1313
* Constructs a JSONException with an explanatory message.

0 commit comments

Comments
 (0)