Skip to content

Commit f57ad50

Browse files
committed
Merged douglascrockford/JSON-java master.
2 parents f50f4cc + 5b18f02 commit f57ad50

30 files changed

Lines changed: 9502 additions & 682 deletions

.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/java"/>
4+
<classpathentry kind="src" path="test/java"/>
5+
<classpathentry kind="lib" path="lib/junit-4.4.jar"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JSON-java</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<fileset dir="${dir.src.test}">
9292
<include name="**/*Test.java"/>
9393
<include name="**/*TestCase.java"/>
94+
<include name="**/Test*.java"/>
9495
</fileset>
9596
</batchtest>
9697
</junit>

src/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/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));

0 commit comments

Comments
 (0)