diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/json/simple/JSONArray.java | 3 | ||||
-rw-r--r-- | src/org/json/simple/JSONObject.java | 3 | ||||
-rw-r--r-- | src/org/json/simple/JSONValue.java | 4 | ||||
-rw-r--r-- | src/org/json/simple/parser/JSONParser.java | 39 | ||||
-rw-r--r-- | src/org/json/simple/parser/ParseException.java | 9 | ||||
-rw-r--r-- | src/org/json/simple/parser/Yylex.java | 68 |
6 files changed, 95 insertions, 31 deletions
diff --git a/src/org/json/simple/JSONArray.java b/src/org/json/simple/JSONArray.java index e2c7042..a71a221 100644 --- a/src/org/json/simple/JSONArray.java +++ b/src/org/json/simple/JSONArray.java | |||
@@ -49,7 +49,8 @@ public class JSONArray extends ArrayList<Object> implements JSONAware, JSONStrea | |||
49 | * @param collection | 49 | * @param collection |
50 | * @param out | 50 | * @param out |
51 | */ | 51 | */ |
52 | public static void writeJSONString(final Collection<?> collection, final Writer out) throws IOException { | 52 | public static void writeJSONString(final Collection<?> collection, final Writer out) |
53 | throws IOException { | ||
53 | if (collection == null) { | 54 | if (collection == null) { |
54 | out.write("null"); | 55 | out.write("null"); |
55 | return; | 56 | return; |
diff --git a/src/org/json/simple/JSONObject.java b/src/org/json/simple/JSONObject.java index 55eeeb6..ee6bf0a 100644 --- a/src/org/json/simple/JSONObject.java +++ b/src/org/json/simple/JSONObject.java | |||
@@ -19,7 +19,8 @@ import rejava.io.Writer; | |||
19 | * @author FangYidong<fangyidong@yahoo.com.cn> | 19 | * @author FangYidong<fangyidong@yahoo.com.cn> |
20 | */ | 20 | */ |
21 | @SuppressWarnings("rawtypes") | 21 | @SuppressWarnings("rawtypes") |
22 | public class JSONObject extends HashMap<String, Object> implements Map<String, Object>, JSONAware, JSONStreamAware { | 22 | public class JSONObject extends HashMap<String, Object> implements Map<String, Object>, JSONAware, |
23 | JSONStreamAware { | ||
23 | 24 | ||
24 | private static final long serialVersionUID = -503443796854799292L; | 25 | private static final long serialVersionUID = -503443796854799292L; |
25 | 26 | ||
diff --git a/src/org/json/simple/JSONValue.java b/src/org/json/simple/JSONValue.java index 3d42315..47a1abe 100644 --- a/src/org/json/simple/JSONValue.java +++ b/src/org/json/simple/JSONValue.java | |||
@@ -300,7 +300,9 @@ public class JSONValue { | |||
300 | break; | 300 | break; |
301 | default: | 301 | default: |
302 | // Reference: http://www.unicode.org/versions/Unicode5.1.0/ | 302 | // Reference: http://www.unicode.org/versions/Unicode5.1.0/ |
303 | if (((ch >= '\u0000') && (ch <= '\u001F')) || ((ch >= '\u007F') && (ch <= '\u009F')) || ((ch >= '\u2000') && (ch <= '\u20FF'))) { | 303 | if (((ch >= '\u0000') && (ch <= '\u001F')) |
304 | || ((ch >= '\u007F') && (ch <= '\u009F')) | ||
305 | || ((ch >= '\u2000') && (ch <= '\u20FF'))) { | ||
304 | final String ss = Integer.toHexString(ch); | 306 | final String ss = Integer.toHexString(ch); |
305 | sb.append("\\u"); | 307 | sb.append("\\u"); |
306 | for (int k = 0; k < (4 - ss.length()); k++) { | 308 | for (int k = 0; k < (4 - ss.length()); k++) { |
diff --git a/src/org/json/simple/parser/JSONParser.java b/src/org/json/simple/parser/JSONParser.java index 4874eea..85472bb 100644 --- a/src/org/json/simple/parser/JSONParser.java +++ b/src/org/json/simple/parser/JSONParser.java | |||
@@ -78,7 +78,8 @@ public class JSONParser { | |||
78 | return this.parse(s, (ContainerFactory) null); | 78 | return this.parse(s, (ContainerFactory) null); |
79 | } | 79 | } |
80 | 80 | ||
81 | public Object parse(final String s, final ContainerFactory containerFactory) throws ParseException { | 81 | public Object parse(final String s, final ContainerFactory containerFactory) |
82 | throws ParseException { | ||
82 | final StringReader in = new StringReader(s); | 83 | final StringReader in = new StringReader(s); |
83 | try { | 84 | try { |
84 | return this.parse(in, containerFactory); | 85 | return this.parse(in, containerFactory); |
@@ -109,7 +110,8 @@ public class JSONParser { | |||
109 | * @throws ParseException | 110 | * @throws ParseException |
110 | */ | 111 | */ |
111 | @SuppressWarnings({ "rawtypes", "unchecked" }) | 112 | @SuppressWarnings({ "rawtypes", "unchecked" }) |
112 | public Object parse(final Reader in, final ContainerFactory containerFactory) throws IOException, ParseException { | 113 | public Object parse(final Reader in, final ContainerFactory containerFactory) |
114 | throws IOException, ParseException { | ||
113 | this.reset(in); | 115 | this.reset(in); |
114 | final LinkedList statusStack = new LinkedList(); | 116 | final LinkedList statusStack = new LinkedList(); |
115 | final LinkedList valueStack = new LinkedList(); | 117 | final LinkedList valueStack = new LinkedList(); |
@@ -144,7 +146,8 @@ public class JSONParser { | |||
144 | if (this.token.type == Yytoken.TYPE_EOF) { | 146 | if (this.token.type == Yytoken.TYPE_EOF) { |
145 | return valueStack.removeFirst(); | 147 | return valueStack.removeFirst(); |
146 | } else { | 148 | } else { |
147 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | 149 | throw new ParseException(this.getPosition(), |
150 | ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | ||
148 | } | 151 | } |
149 | 152 | ||
150 | case S_IN_OBJECT: | 153 | case S_IN_OBJECT: |
@@ -250,17 +253,20 @@ public class JSONParser { | |||
250 | }// inner switch | 253 | }// inner switch |
251 | break; | 254 | break; |
252 | case S_IN_ERROR: | 255 | case S_IN_ERROR: |
253 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | 256 | throw new ParseException(this.getPosition(), |
257 | ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | ||
254 | }// switch | 258 | }// switch |
255 | if (this.status == JSONParser.S_IN_ERROR) { | 259 | if (this.status == JSONParser.S_IN_ERROR) { |
256 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | 260 | throw new ParseException(this.getPosition(), |
261 | ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | ||
257 | } | 262 | } |
258 | } while (this.token.type != Yytoken.TYPE_EOF); | 263 | } while (this.token.type != Yytoken.TYPE_EOF); |
259 | } catch (final IOException ie) { | 264 | } catch (final IOException ie) { |
260 | throw ie; | 265 | throw ie; |
261 | } | 266 | } |
262 | 267 | ||
263 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | 268 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, |
269 | this.token); | ||
264 | } | 270 | } |
265 | 271 | ||
266 | private void nextToken() throws ParseException, IOException { | 272 | private void nextToken() throws ParseException, IOException { |
@@ -298,7 +304,8 @@ public class JSONParser { | |||
298 | this.parse(s, contentHandler, false); | 304 | this.parse(s, contentHandler, false); |
299 | } | 305 | } |
300 | 306 | ||
301 | public void parse(final String s, final ContentHandler contentHandler, final boolean isResume) throws ParseException { | 307 | public void parse(final String s, final ContentHandler contentHandler, final boolean isResume) |
308 | throws ParseException { | ||
302 | final StringReader in = new StringReader(s); | 309 | final StringReader in = new StringReader(s); |
303 | try { | 310 | try { |
304 | this.parse(in, contentHandler, isResume); | 311 | this.parse(in, contentHandler, isResume); |
@@ -310,7 +317,8 @@ public class JSONParser { | |||
310 | } | 317 | } |
311 | } | 318 | } |
312 | 319 | ||
313 | public void parse(final Reader in, final ContentHandler contentHandler) throws IOException, ParseException { | 320 | public void parse(final Reader in, final ContentHandler contentHandler) throws IOException, |
321 | ParseException { | ||
314 | this.parse(in, contentHandler, false); | 322 | this.parse(in, contentHandler, false); |
315 | } | 323 | } |
316 | 324 | ||
@@ -331,7 +339,8 @@ public class JSONParser { | |||
331 | * @throws ParseException | 339 | * @throws ParseException |
332 | */ | 340 | */ |
333 | @SuppressWarnings({ "unchecked", "rawtypes" }) | 341 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
334 | public void parse(final Reader in, final ContentHandler contentHandler, boolean isResume) throws IOException, ParseException { | 342 | public void parse(final Reader in, final ContentHandler contentHandler, boolean isResume) |
343 | throws IOException, ParseException { | ||
335 | if (!isResume) { | 344 | if (!isResume) { |
336 | this.reset(in); | 345 | this.reset(in); |
337 | this.handlerStatusStack = new LinkedList<>(); | 346 | this.handlerStatusStack = new LinkedList<>(); |
@@ -386,7 +395,8 @@ public class JSONParser { | |||
386 | return; | 395 | return; |
387 | } else { | 396 | } else { |
388 | this.status = JSONParser.S_IN_ERROR; | 397 | this.status = JSONParser.S_IN_ERROR; |
389 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | 398 | throw new ParseException(this.getPosition(), |
399 | ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | ||
390 | } | 400 | } |
391 | 401 | ||
392 | case S_IN_OBJECT: | 402 | case S_IN_OBJECT: |
@@ -518,10 +528,12 @@ public class JSONParser { | |||
518 | return; | 528 | return; |
519 | 529 | ||
520 | case S_IN_ERROR: | 530 | case S_IN_ERROR: |
521 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | 531 | throw new ParseException(this.getPosition(), |
532 | ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | ||
522 | }// switch | 533 | }// switch |
523 | if (this.status == JSONParser.S_IN_ERROR) { | 534 | if (this.status == JSONParser.S_IN_ERROR) { |
524 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | 535 | throw new ParseException(this.getPosition(), |
536 | ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | ||
525 | } | 537 | } |
526 | } while (this.token.type != Yytoken.TYPE_EOF); | 538 | } while (this.token.type != Yytoken.TYPE_EOF); |
527 | } catch (final IOException ie) { | 539 | } catch (final IOException ie) { |
@@ -539,6 +551,7 @@ public class JSONParser { | |||
539 | } | 551 | } |
540 | 552 | ||
541 | this.status = JSONParser.S_IN_ERROR; | 553 | this.status = JSONParser.S_IN_ERROR; |
542 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, this.token); | 554 | throw new ParseException(this.getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, |
555 | this.token); | ||
543 | } | 556 | } |
544 | } | 557 | } |
diff --git a/src/org/json/simple/parser/ParseException.java b/src/org/json/simple/parser/ParseException.java index df1b1d1..6bd8d8c 100644 --- a/src/org/json/simple/parser/ParseException.java +++ b/src/org/json/simple/parser/ParseException.java | |||
@@ -75,13 +75,16 @@ public class ParseException extends Exception { | |||
75 | 75 | ||
76 | switch (this.errorType) { | 76 | switch (this.errorType) { |
77 | case ERROR_UNEXPECTED_CHAR: | 77 | case ERROR_UNEXPECTED_CHAR: |
78 | sb.append("Unexpected character (").append(this.unexpectedObject).append(") at position ").append(this.position).append("."); | 78 | sb.append("Unexpected character (").append(this.unexpectedObject).append( |
79 | ") at position ").append(this.position).append("."); | ||
79 | break; |