@@ -805,15 +805,15 @@ public JsonToken nextToken() throws IOException
805
805
t = _parsePosNumber (i );
806
806
break ;
807
807
case 'f' :
808
- _matchToken ( "false" , 1 );
808
+ _matchFalse ( );
809
809
t = JsonToken .VALUE_FALSE ;
810
810
break ;
811
811
case 'n' :
812
- _matchToken ( "null" , 1 );
812
+ _matchNull ( );
813
813
t = JsonToken .VALUE_NULL ;
814
814
break ;
815
815
case 't' :
816
- _matchToken ( "true" , 1 );
816
+ _matchTrue ( );
817
817
t = JsonToken .VALUE_TRUE ;
818
818
break ;
819
819
case '[' :
@@ -844,13 +844,13 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
844
844
_parsingContext = _parsingContext .createChildObjectContext (_tokenInputRow , _tokenInputCol );
845
845
return (_currToken = JsonToken .START_OBJECT );
846
846
case 't' :
847
- _matchToken ( "true" , 1 );
847
+ _matchTrue ( );
848
848
return (_currToken = JsonToken .VALUE_TRUE );
849
849
case 'f' :
850
- _matchToken ( "false" , 1 );
850
+ _matchFalse ( );
851
851
return (_currToken = JsonToken .VALUE_FALSE );
852
852
case 'n' :
853
- _matchToken ( "null" , 1 );
853
+ _matchNull ( );
854
854
return (_currToken = JsonToken .VALUE_NULL );
855
855
case '-' :
856
856
return (_currToken = _parseNegNumber ());
@@ -1073,15 +1073,15 @@ public String nextFieldName() throws IOException
1073
1073
t = _parsePosNumber (i );
1074
1074
break ;
1075
1075
case 'f' :
1076
- _matchToken ( "false" , 1 );
1076
+ _matchFalse ( );
1077
1077
t = JsonToken .VALUE_FALSE ;
1078
1078
break ;
1079
1079
case 'n' :
1080
- _matchToken ( "null" , 1 );
1080
+ _matchNull ( );
1081
1081
t = JsonToken .VALUE_NULL ;
1082
1082
break ;
1083
1083
case 't' :
1084
- _matchToken ( "true" , 1 );
1084
+ _matchTrue ( );
1085
1085
t = JsonToken .VALUE_TRUE ;
1086
1086
break ;
1087
1087
case '[' :
@@ -1164,15 +1164,15 @@ private final void _isNextTokenNameYes(int i) throws IOException
1164
1164
_nextToken = JsonToken .START_OBJECT ;
1165
1165
return ;
1166
1166
case 't' :
1167
- _matchToken ( "true" , 1 );
1167
+ _matchTrue ( );
1168
1168
_nextToken = JsonToken .VALUE_TRUE ;
1169
1169
return ;
1170
1170
case 'f' :
1171
- _matchToken ( "false" , 1 );
1171
+ _matchFalse ( );
1172
1172
_nextToken = JsonToken .VALUE_FALSE ;
1173
1173
return ;
1174
1174
case 'n' :
1175
- _matchToken ( "null" , 1 );
1175
+ _matchNull ( );
1176
1176
_nextToken = JsonToken .VALUE_NULL ;
1177
1177
return ;
1178
1178
case '-' :
@@ -1221,15 +1221,15 @@ private final boolean _isNextTokenNameMaybe(int i, SerializableString str) throw
1221
1221
t = JsonToken .START_OBJECT ;
1222
1222
break ;
1223
1223
case 't' :
1224
- _matchToken ( "true" , 1 );
1224
+ _matchTrue ( );
1225
1225
t = JsonToken .VALUE_TRUE ;
1226
1226
break ;
1227
1227
case 'f' :
1228
- _matchToken ( "false" , 1 );
1228
+ _matchFalse ( );
1229
1229
t = JsonToken .VALUE_FALSE ;
1230
1230
break ;
1231
1231
case 'n' :
1232
- _matchToken ( "null" , 1 );
1232
+ _matchNull ( );
1233
1233
t = JsonToken .VALUE_NULL ;
1234
1234
break ;
1235
1235
case '-' :
@@ -2616,17 +2616,15 @@ protected void _skipString() throws IOException
2616
2616
* Method for handling cases where first non-space character
2617
2617
* of an expected value token is not legal for standard JSON content.
2618
2618
*/
2619
- protected JsonToken _handleUnexpectedValue (int c )
2620
- throws IOException
2619
+ protected JsonToken _handleUnexpectedValue (int c ) throws IOException
2621
2620
{
2622
2621
// Most likely an error, unless we are to allow single-quote-strings
2623
2622
switch (c ) {
2624
- /*
2625
- * This check proceeds only if the Feature.ALLOW_MISSING_VALUES is enabled
2626
- * The Check is for missing values. Incase of missing values in an array, the next token will be either ',' or ']'.
2627
- * This case, decrements the already incremented _inputPtr in the buffer in case of comma(,)
2628
- * so that the existing flow goes back to checking the next token which will be comma again and
2629
- * it continues the parsing.
2623
+ /* This check proceeds only if `Feature.ALLOW_MISSING_VALUES` is enabled;
2624
+ * it is for missing values. In case of missing values in an array the next token
2625
+ * will be either ',' or ']'. This case, decrements the already incremented _inputPtr
2626
+ * in the buffer in case of comma (`,`) so that the existing flow goes back to checking
2627
+ * the next token which will be comma again and it parsing continues.
2630
2628
* Also the case returns NULL as current token in case of ',' or ']'.
2631
2629
*/
2632
2630
case ']' :
@@ -2635,13 +2633,12 @@ protected JsonToken _handleUnexpectedValue(int c)
2635
2633
}
2636
2634
// fall through
2637
2635
case ',' :
2638
- /* 28-Mar-2016: [core#116]: If Feature.ALLOW_MISSING_VALUES is enabled
2639
- * we may allow "missing values", that is, encountering a trailing
2640
- * comma or closing marker where value would be expected
2641
- */
2636
+ // 28-Mar-2016: [core#116]: If Feature.ALLOW_MISSING_VALUES is enabled
2637
+ // we may allow "missing values", that is, encountering a trailing
2638
+ // comma or closing marker where value would be expected
2642
2639
if (isEnabled (Feature .ALLOW_MISSING_VALUES )) {
2643
- _inputPtr -- ;
2644
- return JsonToken .VALUE_NULL ;
2640
+ -- _inputPtr ;
2641
+ return JsonToken .VALUE_NULL ;
2645
2642
}
2646
2643
// fall through
2647
2644
case '}' :
@@ -2684,8 +2681,7 @@ protected JsonToken _handleUnexpectedValue(int c)
2684
2681
return null ;
2685
2682
}
2686
2683
2687
- protected JsonToken _handleApos ()
2688
- throws IOException
2684
+ protected JsonToken _handleApos () throws IOException
2689
2685
{
2690
2686
int c = 0 ;
2691
2687
// Otherwise almost verbatim copy of _finishString()
@@ -2773,13 +2769,18 @@ protected JsonToken _handleApos()
2773
2769
2774
2770
return JsonToken .VALUE_STRING ;
2775
2771
}
2776
-
2772
+
2773
+ /*
2774
+ /**********************************************************
2775
+ /* Internal methods, well-known token decoding
2776
+ /**********************************************************
2777
+ */
2778
+
2777
2779
/**
2778
2780
* Method called if expected numeric value (due to leading sign) does not
2779
2781
* look like a number
2780
2782
*/
2781
- protected JsonToken _handleInvalidNumberStart (int ch , boolean neg )
2782
- throws IOException
2783
+ protected JsonToken _handleInvalidNumberStart (int ch , boolean neg ) throws IOException
2783
2784
{
2784
2785
while (ch == 'I' ) {
2785
2786
if (_inputPtr >= _inputEnd ) {
@@ -2800,12 +2801,72 @@ protected JsonToken _handleInvalidNumberStart(int ch, boolean neg)
2800
2801
if (isEnabled (Feature .ALLOW_NON_NUMERIC_NUMBERS )) {
2801
2802
return resetAsNaN (match , neg ? Double .NEGATIVE_INFINITY : Double .POSITIVE_INFINITY );
2802
2803
}
2803
- _reportError ("Non-standard token '" +match +"': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow" );
2804
+ _reportError ("Non-standard token '%s': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow" ,
2805
+ match );
2804
2806
}
2805
2807
reportUnexpectedNumberChar (ch , "expected digit (0-9) to follow minus sign, for valid numeric value" );
2806
2808
return null ;
2807
2809
}
2808
2810
2811
+ // NOTE: first character already decoded
2812
+ protected final void _matchTrue () throws IOException
2813
+ {
2814
+ int ptr = _inputPtr ;
2815
+ if ((ptr + 3 ) < _inputEnd ) {
2816
+ byte [] buf = _inputBuffer ;
2817
+ if ((buf [ptr ++] == 'r' )
2818
+ && (buf [ptr ++] == 'u' )
2819
+ && (buf [ptr ++] == 'e' )) {
2820
+ int ch = buf [ptr ] & 0xFF ;
2821
+ _inputPtr = ptr ;
2822
+ if (ch >= INT_0 && ch != INT_RBRACKET && ch != INT_RCURLY ) { // expected/allowed chars
2823
+ _checkMatchEnd ("true" , 4 , ch );
2824
+ }
2825
+ return ;
2826
+ }
2827
+ }
2828
+ _matchToken2 ("true" , 1 );
2829
+ }
2830
+
2831
+ protected final void _matchFalse () throws IOException
2832
+ {
2833
+ int ptr = _inputPtr ;
2834
+ if ((ptr + 4 ) < _inputEnd ) {
2835
+ byte [] buf = _inputBuffer ;
2836
+ if ((buf [ptr ++] == 'a' )
2837
+ && (buf [ptr ++] == 'l' )
2838
+ && (buf [ptr ++] == 's' )
2839
+ && (buf [ptr ++] == 'e' )) {
2840
+ int ch = buf [ptr ] & 0xFF ;
2841
+ _inputPtr = ptr ;
2842
+ if (ch >= INT_0 && ch != INT_RBRACKET && ch != INT_RCURLY ) { // expected/allowed chars
2843
+ _checkMatchEnd ("false" , 5 , ch );
2844
+ }
2845
+ return ;
2846
+ }
2847
+ }
2848
+ _matchToken2 ("false" , 1 );
2849
+ }
2850
+
2851
+ protected final void _matchNull () throws IOException
2852
+ {
2853
+ int ptr = _inputPtr ;
2854
+ if ((ptr + 3 ) < _inputEnd ) {
2855
+ byte [] buf = _inputBuffer ;
2856
+ if ((buf [ptr ++] == 'u' )
2857
+ && (buf [ptr ++] == 'l' )
2858
+ && (buf [ptr ++] == 'l' )) {
2859
+ int ch = buf [ptr ] & 0xFF ;
2860
+ _inputPtr = ptr ;
2861
+ if (ch >= INT_0 && ch != INT_RBRACKET && ch != INT_RCURLY ) { // expected/allowed chars
2862
+ _checkMatchEnd ("null" , 4 , ch );
2863
+ }
2864
+ return ;
2865
+ }
2866
+ }
2867
+ _matchToken2 ("null" , 1 );
2868
+ }
2869
+
2809
2870
protected final void _matchToken (String matchStr , int i ) throws IOException
2810
2871
{
2811
2872
final int len = matchStr .length ();
@@ -3491,6 +3552,11 @@ private int nextByte() throws IOException
3491
3552
/**********************************************************
3492
3553
*/
3493
3554
3555
+ protected void _reportInvalidToken (String matchedPart , int ptr ) throws IOException {
3556
+ _inputPtr = ptr ;
3557
+ _reportInvalidToken (matchedPart , "'null', 'true', 'false' or NaN" );
3558
+ }
3559
+
3494
3560
protected void _reportInvalidToken (String matchedPart ) throws IOException {
3495
3561
_reportInvalidToken (matchedPart , "'null', 'true', 'false' or NaN" );
3496
3562
}
0 commit comments