@@ -325,77 +325,66 @@ public char nextClean() throws JSONException {
325325
326326
327327 /**
328- * Return the characters up to the next close quote character.
329- * Backslash processing is done. The formal JSON format does not
330- * allow strings in single quotes, but an implementation is allowed to
331- * accept them.
332- * If strictMode is true, this implementation will not accept unbalanced quotes (e.g will not accept <code>"test'</code>).
328+ * Return the characters up to the next close quote character. Backslash processing is done. The formal JSON format
329+ * does not allow strings in single quotes, but an implementation is allowed to accept them.
330+ *
333331 * @param quote The quoting character, either
334332 * <code>"</code> <small>(double quote)</small> or
335333 * <code>'</code> <small>(single quote)</small>.
336- * @param strictMode If true, this implementation will not accept unbalanced quotes (e.g will not accept <code>"test'</code>).
337334 * @return A String.
338335 * @throws JSONException Unterminated string or unbalanced quotes if strictMode == true.
339336 */
340- public String nextString (char quote , boolean strictMode ) throws JSONException {
337+ public String nextString (char quote ) throws JSONException {
341338 char c ;
342339 StringBuilder sb = new StringBuilder ();
343340 for (;;) {
344341 c = this .next ();
345342 switch (c ) {
346- case 0 :
347- case '\n' :
348- case '\r' :
349- throw this .syntaxError ("Unterminated string. " +
343+ case 0 :
344+ case '\n' :
345+ case '\r' :
346+ throw this .syntaxError ("Unterminated string. " +
350347 "Character with int code " + (int ) c + " is not allowed within a quoted string." );
351- case '\\' :
352- c = this .next ();
353- switch (c ) {
354- case 'b' :
355- sb .append ('\b' );
356- break ;
357- case 't' :
358- sb .append ('\t' );
359- break ;
360- case 'n' :
361- sb .append ('\n' );
362- break ;
363- case 'f' :
364- sb .append ('\f' );
365- break ;
366- case 'r' :
367- sb .append ('\r' );
368- break ;
369- case 'u' :
370- String next = this .next (4 );
371- try {
372- sb .append ((char )Integer .parseInt (next , 16 ));
373- } catch (NumberFormatException e ) {
374- throw this .syntaxError ("Illegal escape. " +
375- "\\ u must be followed by a 4 digit hexadecimal number. \\ " + next + " is not valid." , e );
376- }
377- break ;
378- case '"' :
379- case '\'' :
380348 case '\\' :
381- case '/' :
382- sb .append (c );
349+ c = this .next ();
350+ switch (c ) {
351+ case 'b' :
352+ sb .append ('\b' );
353+ break ;
354+ case 't' :
355+ sb .append ('\t' );
356+ break ;
357+ case 'n' :
358+ sb .append ('\n' );
359+ break ;
360+ case 'f' :
361+ sb .append ('\f' );
362+ break ;
363+ case 'r' :
364+ sb .append ('\r' );
365+ break ;
366+ case 'u' :
367+ String next = this .next (4 );
368+ try {
369+ sb .append ((char ) Integer .parseInt (next , 16 ));
370+ } catch (NumberFormatException e ) {
371+ throw this .syntaxError ("Illegal escape. " +
372+ "\\ u must be followed by a 4 digit hexadecimal number. \\ " + next
373+ + " is not valid." ,
374+ e );
375+ }
376+ break ;
377+ case '"' :
378+ case '\'' :
379+ case '\\' :
380+ case '/' :
381+ sb .append (c );
382+ break ;
383+ default :
384+ throw this .syntaxError ("Illegal escape. Escape sequence \\ " + c + " is not valid." );
385+ }
383386 break ;
384387 default :
385- throw this .syntaxError ("Illegal escape. Escape sequence \\ " + c + " is not valid." );
386- }
387- break ;
388- default :
389- if (strictMode && c == '\"' && quote != c ) {
390- throw this .syntaxError (String .format (
391- "Field contains unbalanced quotes. Starts with %s but ends with double quote." , quote ));
392- }
393-
394- if (strictMode && c == '\'' && quote != c ) {
395- throw this .syntaxError (String .format (
396- "Field contains unbalanced quotes. Starts with %s but ends with single quote." , quote ));
397- }
398-
399388 if (c == quote ) {
400389 return sb .toString ();
401390 }
@@ -404,7 +393,6 @@ public String nextString(char quote, boolean strictMode) throws JSONException {
404393 }
405394 }
406395
407-
408396 /**
409397 * Get the text up but not including the specified character or the
410398 * end of line, whichever comes first.
@@ -528,15 +516,24 @@ private JSONArray getJsonArray() {
528516 }
529517 }
530518
519+ /**
520+ * Get the next simple value from the JSON input. Simple values include strings (wrapped in single or double
521+ * quotes), numbers, booleans, and null. This method is called when the next character is not '{' or '['.
522+ *
523+ * @param c The starting character.
524+ * @param jsonParserConfiguration The configuration object containing parsing options.
525+ * @return The parsed simple value.
526+ * @throws JSONException If there is a syntax error or the value does not adhere to the configuration rules.
527+ */
531528 Object nextSimpleValue (char c , JSONParserConfiguration jsonParserConfiguration ) {
532529 boolean strictMode = jsonParserConfiguration .isStrictMode ();
533530
534- if (strictMode && c == '\'' ){
531+ if (strictMode && c == '\'' ) {
535532 throw this .syntaxError ("Single quote wrap not allowed in strict mode" );
536533 }
537534
538535 if (c == '"' || c == '\'' ) {
539- return this .nextString (c , strictMode );
536+ return this .nextString (c );
540537 }
541538
542539 return parsedUnquotedText (c , strictMode );
0 commit comments