Skip to content

Commit 77c899d

Browse files
authored
Merge pull request #858 from stleary/cleanup-after-commit
cleanup-after-commit for #854 and #856
2 parents 6358b7f + f164b8c commit 77c899d

File tree

2 files changed

+92
-53
lines changed

2 files changed

+92
-53
lines changed

pom.xml

-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@
126126
<groupId>org.apache.maven.plugins</groupId>
127127
<artifactId>maven-javadoc-plugin</artifactId>
128128
<version>3.5.0</version>
129-
<configuration>
130-
<source>8</source>
131-
</configuration>
132129
<executions>
133130
<execution>
134131
<id>attach-javadocs</id>

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

+92-50
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,37 @@ private static String getValue(JSONTokener x, char delimiter) throws JSONExcepti
4040
do {
4141
c = x.next();
4242
} while (c == ' ' || c == '\t');
43-
if (c == 0) {
44-
return null;
45-
} else if (c == '"' || c == '\'') {
46-
q = c;
47-
sb = new StringBuilder();
48-
for (;;) {
49-
c = x.next();
50-
if (c == q) {
51-
//Handle escaped double-quote
52-
char nextC = x.next();
53-
if (nextC != '\"') {
54-
// if our quote was the end of the file, don't step
55-
if (nextC > 0) {
56-
x.back();
57-
}
58-
break;
59-
}
60-
}
61-
if (c == 0 || c == '\n' || c == '\r') {
62-
throw x.syntaxError("Missing close quote '" + q + "'.");
63-
}
64-
sb.append(c);
65-
}
66-
return sb.toString();
67-
} else if (c == delimiter) {
68-
x.back();
69-
return "";
70-
}
71-
x.back();
72-
return x.nextTo(delimiter);
73-
}
43+
if (c == 0) {
44+
return null;
45+
} else if (c == '"' || c == '\'') {
46+
q = c;
47+
sb = new StringBuilder();
48+
for (;;) {
49+
c = x.next();
50+
if (c == q) {
51+
//Handle escaped double-quote
52+
char nextC = x.next();
53+
if (nextC != '\"') {
54+
// if our quote was the end of the file, don't step
55+
if (nextC > 0) {
56+
x.back();
57+
}
58+
break;
59+
}
60+
}
61+
if (c == 0 || c == '\n' || c == '\r') {
62+
throw x.syntaxError("Missing close quote '" + q + "'.");
63+
}
64+
sb.append(c);
65+
}
66+
return sb.toString();
67+
} else if (c == delimiter) {
68+
x.back();
69+
return "";
70+
}
71+
x.back();
72+
return x.nextTo(delimiter);
73+
}
7474

7575
/**
7676
* Produce a JSONArray of strings from a row of comma delimited values.
@@ -83,8 +83,11 @@ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
8383
}
8484

8585
/**
86-
* Same as {@link #rowToJSONArray(JSONTokener)}, but with a custom delimiter.
87-
* @see #rowToJSONArray(JSONTokener)
86+
* Produce a JSONArray of strings from a row of comma delimited values.
87+
* @param x A JSONTokener of the source text.
88+
* @param delimiter custom delimiter char
89+
* @return A JSONArray of strings.
90+
* @throws JSONException if a called function fails
8891
*/
8992
public static JSONArray rowToJSONArray(JSONTokener x, char delimiter) throws JSONException {
9093
JSONArray ja = new JSONArray();
@@ -127,9 +130,15 @@ public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) throws
127130
}
128131

129132
/**
130-
* Same as {@link #rowToJSONObject(JSONArray, JSONTokener)}, but with a custom {@code delimiter}.
131-
*
132-
* @see #rowToJSONObject(JSONArray, JSONTokener)
133+
* Produce a JSONObject from a row of comma delimited text, using a
134+
* parallel JSONArray of strings to provides the names of the elements.
135+
* @param names A JSONArray of names. This is commonly obtained from the
136+
* first row of a comma delimited text file using the rowToJSONArray
137+
* method.
138+
* @param x A JSONTokener of the source text.
139+
* @param delimiter custom delimiter char
140+
* @return A JSONObject combining the names and values.
141+
* @throws JSONException if a called function fails
133142
*/
134143
public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x, char delimiter) throws JSONException {
135144
JSONArray ja = rowToJSONArray(x, delimiter);
@@ -148,8 +157,12 @@ public static String rowToString(JSONArray ja) {
148157
}
149158

150159
/**
151-
* Same as {@link #rowToString(JSONArray)}, but with a custom delimiter.
152-
* @see #rowToString(JSONArray)
160+
* Produce a comma delimited text row from a JSONArray. Values containing
161+
* the comma character will be quoted. Troublesome characters may be
162+
* removed.
163+
* @param ja A JSONArray of strings.
164+
* @param delimiter custom delimiter char
165+
* @return A string ending in NEWLINE.
153166
*/
154167
public static String rowToString(JSONArray ja, char delimiter) {
155168
StringBuilder sb = new StringBuilder();
@@ -193,8 +206,12 @@ public static JSONArray toJSONArray(String string) throws JSONException {
193206
}
194207

195208
/**
196-
* Same as {@link #toJSONArray(String)}, but with a custom delimiter.
197-
* @see #toJSONArray(String)
209+
* Produce a JSONArray of JSONObjects from a comma delimited text string,
210+
* using the first row as a source of names.
211+
* @param string The comma delimited text.
212+
* @param delimiter custom delimiter char
213+
* @return A JSONArray of JSONObjects.
214+
* @throws JSONException if a called function fails
198215
*/
199216
public static JSONArray toJSONArray(String string, char delimiter) throws JSONException {
200217
return toJSONArray(new JSONTokener(string), delimiter);
@@ -212,8 +229,12 @@ public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
212229
}
213230

214231
/**
215-
* Same as {@link #toJSONArray(JSONTokener)}, but with a custom delimiter.
216-
* @see #toJSONArray(JSONTokener)
232+
* Produce a JSONArray of JSONObjects from a comma delimited text string,
233+
* using the first row as a source of names.
234+
* @param x The JSONTokener containing the comma delimited text.
235+
* @param delimiter custom delimiter char
236+
* @return A JSONArray of JSONObjects.
237+
* @throws JSONException if a called function fails
217238
*/
218239
public static JSONArray toJSONArray(JSONTokener x, char delimiter) throws JSONException {
219240
return toJSONArray(rowToJSONArray(x, delimiter), x, delimiter);
@@ -232,8 +253,13 @@ public static JSONArray toJSONArray(JSONArray names, String string) throws JSONE
232253
}
233254

234255
/**
235-
* Same as {@link #toJSONArray(JSONArray, String)}, but with a custom delimiter.
236-
* @see #toJSONArray(JSONArray, String)
256+
* Produce a JSONArray of JSONObjects from a comma delimited text string
257+
* using a supplied JSONArray as the source of element names.
258+
* @param names A JSONArray of strings.
259+
* @param string The comma delimited text.
260+
* @param delimiter custom delimiter char
261+
* @return A JSONArray of JSONObjects.
262+
* @throws JSONException if a called function fails
237263
*/
238264
public static JSONArray toJSONArray(JSONArray names, String string, char delimiter) throws JSONException {
239265
return toJSONArray(names, new JSONTokener(string), delimiter);
@@ -252,8 +278,13 @@ public static JSONArray toJSONArray(JSONArray names, JSONTokener x) throws JSONE
252278
}
253279

254280
/**
255-
* Same as {@link #toJSONArray(JSONArray, JSONTokener)}, but with a custom delimiter.
256-
* @see #toJSONArray(JSONArray, JSONTokener)
281+
* Produce a JSONArray of JSONObjects from a comma delimited text string
282+
* using a supplied JSONArray as the source of element names.
283+
* @param names A JSONArray of strings.
284+
* @param x A JSONTokener of the source text.
285+
* @param delimiter custom delimiter char
286+
* @return A JSONArray of JSONObjects.
287+
* @throws JSONException if a called function fails
257288
*/
258289
public static JSONArray toJSONArray(JSONArray names, JSONTokener x, char delimiter) throws JSONException {
259290
if (names == null || names.length() == 0) {
@@ -287,8 +318,13 @@ public static String toString(JSONArray ja) throws JSONException {
287318
}
288319

289320
/**
290-
* Same as {@link #toString(JSONArray)}, but with a custom delimiter.
291-
* @see #toString(JSONArray)
321+
* Produce a comma delimited text from a JSONArray of JSONObjects. The
322+
* first row will be a list of names obtained by inspecting the first
323+
* JSONObject.
324+
* @param ja A JSONArray of JSONObjects.
325+
* @param delimiter custom delimiter char
326+
* @return A comma delimited text.
327+
* @throws JSONException if a called function fails
292328
*/
293329
public static String toString(JSONArray ja, char delimiter) throws JSONException {
294330
JSONObject jo = ja.optJSONObject(0);
@@ -315,8 +351,14 @@ public static String toString(JSONArray names, JSONArray ja) throws JSONExceptio
315351
}
316352

317353
/**
318-
* Same as {@link #toString(JSONArray,JSONArray)}, but with a custom delimiter.
319-
* @see #toString(JSONArray,JSONArray)
354+
* Produce a comma delimited text from a JSONArray of JSONObjects using
355+
* a provided list of names. The list of names is not included in the
356+
* output.
357+
* @param names A JSONArray of strings.
358+
* @param ja A JSONArray of JSONObjects.
359+
* @param delimiter custom delimiter char
360+
* @return A comma delimited text.
361+
* @throws JSONException if a called function fails
320362
*/
321363
public static String toString(JSONArray names, JSONArray ja, char delimiter) throws JSONException {
322364
if (names == null || names.length() == 0) {

0 commit comments

Comments
 (0)