1 |
|
package org.json; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@author |
45 |
|
@version |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 151 (151) |
Complexity: 54 |
Complexity Density: 0.58 |
|
47 |
|
public class CDL |
48 |
|
{ |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
|
56 |
|
@return |
57 |
|
@throws |
58 |
|
|
59 |
|
|
|
|
| 0% |
Uncovered Elements: 40 (40) |
Complexity: 13 |
Complexity Density: 0.43 |
|
60 |
0 |
private static String getValue(JSONTokener x) throws JSONException... |
61 |
|
{ |
62 |
0 |
char c; |
63 |
0 |
char q; |
64 |
0 |
StringBuffer sb; |
65 |
0 |
do |
66 |
|
{ |
67 |
0 |
c = x.next(); |
68 |
0 |
} while (c == ' ' || c == '\t'); |
69 |
0 |
switch (c) |
70 |
|
{ |
71 |
0 |
case 0: |
72 |
0 |
return null; |
73 |
0 |
case '"': |
74 |
0 |
case '\'': |
75 |
0 |
q = c; |
76 |
0 |
sb = new StringBuffer(); |
77 |
0 |
for (;;) |
78 |
|
{ |
79 |
0 |
c = x.next(); |
80 |
0 |
if (c == q) |
81 |
|
{ |
82 |
|
|
83 |
0 |
char nextC = x.next(); |
84 |
0 |
if (nextC != '\"') |
85 |
|
{ |
86 |
|
|
87 |
0 |
if (nextC > 0) |
88 |
|
{ |
89 |
0 |
x.back(); |
90 |
|
} |
91 |
0 |
break; |
92 |
|
} |
93 |
|
} |
94 |
0 |
if (c == 0 || c == '\n' || c == '\r') |
95 |
|
{ |
96 |
0 |
throw x.syntaxError("Missing close quote '" + q + "'."); |
97 |
|
} |
98 |
0 |
sb.append(c); |
99 |
|
} |
100 |
0 |
return sb.toString(); |
101 |
0 |
case ',': |
102 |
0 |
x.back(); |
103 |
0 |
return ""; |
104 |
0 |
default: |
105 |
0 |
x.back(); |
106 |
0 |
return x.nextTo(','); |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
|
115 |
|
@return |
116 |
|
@throws |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 10 |
Complexity Density: 0.67 |
|
118 |
0 |
public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException... |
119 |
|
{ |
120 |
0 |
JSONArray ja = new JSONArray(); |
121 |
0 |
for (;;) |
122 |
|
{ |
123 |
0 |
String value = getValue(x); |
124 |
0 |
char c = x.next(); |
125 |
0 |
if (value == null |
126 |
|
|| (ja.length() == 0 && value.length() == 0 && c != ',')) |
127 |
|
{ |
128 |
0 |
return null; |
129 |
|
} |
130 |
0 |
ja.put(value); |
131 |
0 |
for (;;) |
132 |
|
{ |
133 |
0 |
if (c == ',') |
134 |
|
{ |
135 |
0 |
break; |
136 |
|
} |
137 |
0 |
if (c != ' ') |
138 |
|
{ |
139 |
0 |
if (c == '\n' || c == '\r' || c == 0) |
140 |
|
{ |
141 |
0 |
return ja; |
142 |
|
} |
143 |
0 |
throw x.syntaxError( |
144 |
|
"Bad character '" + c + "' (" + (int) c + ")."); |
145 |
|
} |
146 |
0 |
c = x.next(); |
147 |
|
} |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@param |
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
|
160 |
|
@return |
161 |
|
@throws |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
163 |
0 |
public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)... |
164 |
|
throws JSONException |
165 |
|
{ |
166 |
0 |
JSONArray ja = rowToJSONArray(x); |
167 |
0 |
return ja != null ? ja.toJSONObject(names) : null; |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
|
176 |
|
@return |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 13 |
Complexity Density: 0.72 |
|
178 |
0 |
public static String rowToString(JSONArray ja)... |
179 |
|
{ |
180 |
0 |
StringBuilder sb = new StringBuilder(); |
181 |
0 |
for (int i = 0; i < ja.length(); i += 1) |
182 |
|
{ |
183 |
0 |
if (i > 0) |
184 |
|
{ |
185 |
0 |
sb.append(','); |
186 |
|
} |
187 |
0 |
Object object = ja.opt(i); |
188 |
0 |
if (object != null) |
189 |
|
{ |
190 |
0 |
String string = object.toString(); |
191 |
0 |
if (string.length() > 0 && (string.indexOf(',') >= 0 |
192 |
|
|| string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 |
193 |
|
|| string.indexOf(0) >= 0 || string.charAt(0) == '"')) |
194 |
|
{ |
195 |
0 |
sb.append('"'); |
196 |
0 |
int length = string.length(); |
197 |
0 |
for (int j = 0; j < length; j += 1) |
198 |
|
{ |
199 |
0 |
char c = string.charAt(j); |
200 |
0 |
if (c >= ' ' && c != '"') |
201 |
|
{ |
202 |
0 |
sb.append(c); |
203 |
|
} |
204 |
|
} |
205 |
0 |
sb.append('"'); |
206 |
|
} |
207 |
|
else |
208 |
|
{ |
209 |
0 |
sb.append(string); |
210 |
|
} |
211 |
|
} |
212 |
|
} |
213 |
0 |
sb.append('\n'); |
214 |
0 |
return sb.toString(); |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
@param |
222 |
|
|
223 |
|
@return |
224 |
|
@throws |
225 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
0 |
public static JSONArray toJSONArray(String string) throws JSONException... |
227 |
|
{ |
228 |
0 |
return toJSONArray(new JSONTokener(string)); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
@param |
236 |
|
|
237 |
|
@return |
238 |
|
@throws |
239 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
0 |
public static JSONArray toJSONArray(JSONTokener x) throws JSONException... |
241 |
|
{ |
242 |
0 |
return toJSONArray(rowToJSONArray(x), x); |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
@param |
250 |
|
|
251 |
|
@param |
252 |
|
|
253 |
|
@return |
254 |
|
@throws |
255 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
256 |
0 |
public static JSONArray toJSONArray(JSONArray names, String string)... |
257 |
|
throws JSONException |
258 |
|
{ |
259 |
0 |
return toJSONArray(names, new JSONTokener(string)); |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
@param |
267 |
|
|
268 |
|
@param |
269 |
|
|
270 |
|
@return |
271 |
|
@throws |
272 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
273 |
0 |
public static JSONArray toJSONArray(JSONArray names, JSONTokener x)... |
274 |
|
throws JSONException |
275 |
|
{ |
276 |
0 |
if (names == null || names.length() == 0) |
277 |
|
{ |
278 |
0 |
return null; |
279 |
|
} |
280 |
0 |
JSONArray ja = new JSONArray(); |
281 |
0 |
for (;;) |
282 |
|
{ |
283 |
0 |
JSONObject jo = rowToJSONObject(names, x); |
284 |
0 |
if (jo == null) |
285 |
|
{ |
286 |
0 |
break; |
287 |
|
} |
288 |
0 |
ja.put(jo); |
289 |
|
} |
290 |
0 |
if (ja.length() == 0) |
291 |
|
{ |
292 |
0 |
return null; |
293 |
|
} |
294 |
0 |
return ja; |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
@param |
302 |
|
|
303 |
|
@return |
304 |
|
@throws |
305 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
306 |
0 |
public static String toString(JSONArray ja) throws JSONException... |
307 |
|
{ |
308 |
0 |
JSONObject jo = ja.optJSONObject(0); |
309 |
0 |
if (jo != null) |
310 |
|
{ |
311 |
0 |
JSONArray names = jo.names(); |
312 |
0 |
if (names != null) |
313 |
|
{ |
314 |
0 |
return rowToString(names) + toString(names, ja); |
315 |
|
} |
316 |
|
} |
317 |
0 |
return null; |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
@param |
325 |
|
|
326 |
|
@param |
327 |
|
|
328 |
|
@return |
329 |
|
@throws |
330 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
331 |
0 |
public static String toString(JSONArray names, JSONArray ja)... |
332 |
|
throws JSONException |
333 |
|
{ |
334 |
0 |
if (names == null || names.length() == 0) |
335 |
|
{ |
336 |
0 |
return null; |
337 |
|
} |
338 |
0 |
StringBuffer sb = new StringBuffer(); |
339 |
0 |
for (int i = 0; i < ja.length(); i += 1) |
340 |
|
{ |
341 |
0 |
JSONObject jo = ja.optJSONObject(i); |
342 |
0 |
if (jo != null) |
343 |
|
{ |
344 |
0 |
sb.append(rowToString(jo.toJSONArray(names))); |
345 |
|
} |
346 |
|
} |
347 |
0 |
return sb.toString(); |
348 |
|
} |
349 |
|
} |