json 1.8.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -10
  3. data/CHANGES +12 -0
  4. data/Gemfile +1 -2
  5. data/{README.rdoc → README.md} +145 -111
  6. data/Rakefile +26 -29
  7. data/VERSION +1 -1
  8. data/ext/json/ext/generator/generator.c +38 -55
  9. data/ext/json/ext/generator/generator.h +7 -1
  10. data/ext/json/ext/parser/extconf.rb +3 -0
  11. data/ext/json/ext/parser/parser.c +309 -439
  12. data/ext/json/ext/parser/parser.h +0 -1
  13. data/ext/json/ext/parser/parser.rl +67 -160
  14. data/ext/json/extconf.rb +0 -1
  15. data/java/src/json/ext/ByteListTranscoder.java +1 -2
  16. data/java/src/json/ext/Generator.java +11 -12
  17. data/java/src/json/ext/GeneratorMethods.java +1 -2
  18. data/java/src/json/ext/GeneratorService.java +1 -2
  19. data/java/src/json/ext/GeneratorState.java +3 -56
  20. data/java/src/json/ext/OptionsReader.java +2 -3
  21. data/java/src/json/ext/Parser.java +110 -411
  22. data/java/src/json/ext/Parser.rl +25 -119
  23. data/java/src/json/ext/ParserService.java +1 -2
  24. data/java/src/json/ext/RuntimeInfo.java +1 -6
  25. data/java/src/json/ext/StringDecoder.java +1 -2
  26. data/java/src/json/ext/StringEncoder.java +5 -0
  27. data/java/src/json/ext/Utils.java +1 -2
  28. data/json-java.gemspec +15 -0
  29. data/json.gemspec +0 -0
  30. data/json_pure.gemspec +23 -26
  31. data/lib/json/add/bigdecimal.rb +1 -0
  32. data/lib/json/add/complex.rb +2 -1
  33. data/lib/json/add/core.rb +1 -0
  34. data/lib/json/add/date.rb +1 -1
  35. data/lib/json/add/date_time.rb +1 -1
  36. data/lib/json/add/exception.rb +1 -1
  37. data/lib/json/add/ostruct.rb +1 -1
  38. data/lib/json/add/range.rb +1 -1
  39. data/lib/json/add/rational.rb +1 -0
  40. data/lib/json/add/regexp.rb +1 -1
  41. data/lib/json/add/struct.rb +1 -1
  42. data/lib/json/add/symbol.rb +1 -1
  43. data/lib/json/add/time.rb +1 -1
  44. data/lib/json/common.rb +24 -52
  45. data/lib/json/ext.rb +0 -6
  46. data/lib/json/generic_object.rb +5 -4
  47. data/lib/json/pure/generator.rb +61 -125
  48. data/lib/json/pure/parser.rb +28 -80
  49. data/lib/json/pure.rb +2 -8
  50. data/lib/json/version.rb +2 -1
  51. data/lib/json.rb +1 -0
  52. data/references/rfc7159.txt +899 -0
  53. data/tests/fixtures/obsolete_fail1.json +1 -0
  54. data/tests/{test_json_addition.rb → json_addition_test.rb} +22 -25
  55. data/tests/json_common_interface_test.rb +126 -0
  56. data/tests/json_encoding_test.rb +105 -0
  57. data/tests/json_ext_parser_test.rb +15 -0
  58. data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +5 -8
  59. data/tests/{test_json_generate.rb → json_generator_test.rb} +76 -37
  60. data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
  61. data/tests/json_parser_test.rb +448 -0
  62. data/tests/json_string_matching_test.rb +38 -0
  63. data/tests/test_helper.rb +23 -0
  64. data/tools/diff.sh +18 -0
  65. data/tools/fuzz.rb +1 -9
  66. metadata +27 -42
  67. data/COPYING +0 -58
  68. data/COPYING-json-jruby +0 -57
  69. data/GPL +0 -340
  70. data/TODO +0 -1
  71. data/tests/fixtures/fail1.json +0 -1
  72. data/tests/setup_variant.rb +0 -11
  73. data/tests/test_json.rb +0 -553
  74. data/tests/test_json_encoding.rb +0 -65
  75. data/tests/test_json_string_matching.rb +0 -39
  76. data/tests/test_json_unicode.rb +0 -72
@@ -3,6 +3,28 @@
3
3
  #include "../fbuffer/fbuffer.h"
4
4
  #include "parser.h"
5
5
 
6
+ #if defined HAVE_RUBY_ENCODING_H
7
+ # define EXC_ENCODING rb_utf8_encoding(),
8
+ # ifndef HAVE_RB_ENC_RAISE
9
+ static void
10
+ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
11
+ {
12
+ va_list args;
13
+ VALUE mesg;
14
+
15
+ va_start(args, fmt);
16
+ mesg = rb_enc_vsprintf(enc, fmt, args);
17
+ va_end(args);
18
+
19
+ rb_exc_raise(rb_exc_new3(exc, mesg));
20
+ }
21
+ # define rb_enc_raise enc_raise
22
+ # endif
23
+ #else
24
+ # define EXC_ENCODING /* nothing */
25
+ # define rb_enc_raise rb_raise
26
+ #endif
27
+
6
28
  /* unicode */
7
29
 
8
30
  static const char digit_values[256] = {
@@ -67,28 +89,20 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
67
89
  return len;
68
90
  }
69
91
 
70
- #ifdef HAVE_RUBY_ENCODING_H
71
- static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
72
- CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
73
- static ID i_encoding, i_encode;
74
- #else
75
- static ID i_iconv;
76
- #endif
77
-
78
92
  static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
79
93
  static VALUE CNaN, CInfinity, CMinusInfinity;
80
94
 
81
95
  static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
82
- i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_quirks_mode,
96
+ i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
83
97
  i_object_class, i_array_class, i_key_p, i_deep_const_get, i_match,
84
98
  i_match_string, i_aset, i_aref, i_leftshift;
85
99
 
86
100
 
87
- #line 110 "parser.rl"
101
+ #line 124 "parser.rl"
88
102
 
89
103
 
90
104
 
91
- #line 92 "parser.c"
105
+ #line 106 "parser.c"
92
106
  enum {JSON_object_start = 1};
93
107
  enum {JSON_object_first_final = 27};
94
108
  enum {JSON_object_error = 0};
@@ -96,7 +110,7 @@ enum {JSON_object_error = 0};
96
110
  enum {JSON_object_en_main = 1};
97
111
 
98
112
 
99
- #line 151 "parser.rl"
113
+ #line 165 "parser.rl"
100
114
 
101
115
 
102
116
  static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -112,14 +126,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
112
126
  *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
113
127
 
114
128
 
115
- #line 116 "parser.c"
129
+ #line 130 "parser.c"
116
130
  {
117
131
  cs = JSON_object_start;
118
132
  }
119
133
 
120
- #line 166 "parser.rl"
134
+ #line 180 "parser.rl"
121
135
 
122
- #line 123 "parser.c"
136
+ #line 137 "parser.c"
123
137
  {
124
138
  if ( p == pe )
125
139
  goto _test_eof;
@@ -147,7 +161,7 @@ case 2:
147
161
  goto st2;
148
162
  goto st0;
149
163
  tr2:
150
- #line 133 "parser.rl"
164
+ #line 147 "parser.rl"
151
165
  {
152
166
  char *np;
153
167
  json->parsing_name = 1;
@@ -160,7 +174,7 @@ st3:
160
174
  if ( ++p == pe )
161
175
  goto _test_eof3;
162
176
  case 3:
163
- #line 164 "parser.c"
177
+ #line 178 "parser.c"
164
178
  switch( (*p) ) {
165
179
  case 13: goto st3;
166
180
  case 32: goto st3;
@@ -227,7 +241,7 @@ case 8:
227
241
  goto st8;
228
242
  goto st0;
229
243
  tr11:
230
- #line 118 "parser.rl"
244
+ #line 132 "parser.rl"
231
245
  {
232
246
  VALUE v = Qnil;
233
247
  char *np = JSON_parse_value(json, p, pe, &v);
@@ -247,7 +261,7 @@ st9:
247
261
  if ( ++p == pe )
248
262
  goto _test_eof9;
249
263
  case 9:
250
- #line 251 "parser.c"
264
+ #line 265 "parser.c"
251
265
  switch( (*p) ) {
252
266
  case 13: goto st9;
253
267
  case 32: goto st9;
@@ -336,14 +350,14 @@ case 18:
336
350
  goto st9;
337
351
  goto st18;
338
352
  tr4:
339
- #line 141 "parser.rl"
353
+ #line 155 "parser.rl"
340
354
  { p--; {p++; cs = 27; goto _out;} }
341
355
  goto st27;
342
356
  st27:
343
357
  if ( ++p == pe )
344
358
  goto _test_eof27;
345
359
  case 27:
346
- #line 347 "parser.c"
360
+ #line 361 "parser.c"
347
361
  goto st0;
348
362
  st19:
349
363
  if ( ++p == pe )
@@ -441,7 +455,7 @@ case 26:
441
455
  _out: {}
442
456
  }
443
457
 
444
- #line 167 "parser.rl"
458
+ #line 181 "parser.rl"
445
459
 
446
460
  if (cs >= JSON_object_first_final) {
447
461
  if (json->create_additions) {
@@ -466,15 +480,15 @@ case 26:
466
480
 
467
481
 
468
482
 
469
- #line 470 "parser.c"
483
+ #line 484 "parser.c"
470
484
  enum {JSON_value_start = 1};
471
- enum {JSON_value_first_final = 21};
485
+ enum {JSON_value_first_final = 29};
472
486
  enum {JSON_value_error = 0};
473
487
 
474
488
  enum {JSON_value_en_main = 1};
475
489
 
476
490
 
477
- #line 271 "parser.rl"
491
+ #line 285 "parser.rl"
478
492
 
479
493
 
480
494
  static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -482,265 +496,346 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
482
496
  int cs = EVIL;
483
497
 
484
498
 
485
- #line 486 "parser.c"
499
+ #line 500 "parser.c"
486
500
  {
487
501
  cs = JSON_value_start;
488
502
  }
489
503
 
490
- #line 278 "parser.rl"
504
+ #line 292 "parser.rl"
491
505
 
492
- #line 493 "parser.c"
506
+ #line 507 "parser.c"
493
507
  {
494
508
  if ( p == pe )
495
509
  goto _test_eof;
496
510
  switch ( cs )
497
511
  {
512
+ st1:
513
+ if ( ++p == pe )
514
+ goto _test_eof1;
498
515
  case 1:
499
516
  switch( (*p) ) {
500
- case 34: goto tr0;
501
- case 45: goto tr2;
502
- case 73: goto st2;
503
- case 78: goto st9;
504
- case 91: goto tr5;
505
- case 102: goto st11;
506
- case 110: goto st15;
507
- case 116: goto st18;
508
- case 123: goto tr9;
517
+ case 13: goto st1;
518
+ case 32: goto st1;
519
+ case 34: goto tr2;
520
+ case 45: goto tr3;
521
+ case 47: goto st6;
522
+ case 73: goto st10;
523
+ case 78: goto st17;
524
+ case 91: goto tr7;
525
+ case 102: goto st19;
526
+ case 110: goto st23;
527
+ case 116: goto st26;
528
+ case 123: goto tr11;
509
529
  }
510
- if ( 48 <= (*p) && (*p) <= 57 )
511
- goto tr2;
530
+ if ( (*p) > 10 ) {
531
+ if ( 48 <= (*p) && (*p) <= 57 )
532
+ goto tr3;
533
+ } else if ( (*p) >= 9 )
534
+ goto st1;
512
535
  goto st0;
513
536
  st0:
514
537
  cs = 0;
515
538
  goto _out;
516
- tr0:
517
- #line 219 "parser.rl"
539
+ tr2:
540
+ #line 233 "parser.rl"
518
541
  {
519
542
  char *np = JSON_parse_string(json, p, pe, result);
520
- if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
543
+ if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
521
544
  }
522
- goto st21;
523
- tr2:
524
- #line 224 "parser.rl"
545
+ goto st29;
546
+ tr3:
547
+ #line 238 "parser.rl"
525
548
  {
526
549
  char *np;
527
- if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
550
+ if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
528
551
  if (json->allow_nan) {
529
552
  *result = CMinusInfinity;
530
553
  {p = (( p + 10))-1;}
531
- p--; {p++; cs = 21; goto _out;}
554
+ p--; {p++; cs = 29; goto _out;}
532
555
  } else {
533
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
556
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
534
557
  }
535
558
  }
536
559
  np = JSON_parse_float(json, p, pe, result);
537
560
  if (np != NULL) {p = (( np))-1;}
538
561
  np = JSON_parse_integer(json, p, pe, result);
539
562
  if (np != NULL) {p = (( np))-1;}
540
- p--; {p++; cs = 21; goto _out;}
563
+ p--; {p++; cs = 29; goto _out;}
541
564
  }
542
- goto st21;
543
- tr5:
544
- #line 242 "parser.rl"
565
+ goto st29;
566
+ tr7:
567
+ #line 256 "parser.rl"
545
568
  {
546
569
  char *np;
547
570
  json->current_nesting++;
548
571
  np = JSON_parse_array(json, p, pe, result);
549
572
  json->current_nesting--;
550
- if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
573
+ if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
551
574
  }
552
- goto st21;
553
- tr9:
554
- #line 250 "parser.rl"
575
+ goto st29;
576
+ tr11:
577
+ #line 264 "parser.rl"
555
578
  {
556
579
  char *np;
557
580
  json->current_nesting++;
558
581
  np = JSON_parse_object(json, p, pe, result);
559
582
  json->current_nesting--;
560
- if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
583
+ if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
561
584
  }
562
- goto st21;
563
- tr16:
564
- #line 212 "parser.rl"
585
+ goto st29;
586
+ tr25:
587
+ #line 226 "parser.rl"
565
588
  {
566
589
  if (json->allow_nan) {
567
590
  *result = CInfinity;
568
591
  } else {
569
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
592
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
570
593
  }
571
594
  }
572
- goto st21;
573
- tr18:
574
- #line 205 "parser.rl"
595
+ goto st29;
596
+ tr27:
597
+ #line 219 "parser.rl"
575
598
  {
576
599
  if (json->allow_nan) {
577
600
  *result = CNaN;
578
601
  } else {
579
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
602
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
580
603
  }
581
604
  }
582
- goto st21;
583
- tr22:
584
- #line 199 "parser.rl"
605
+ goto st29;
606
+ tr31:
607
+ #line 213 "parser.rl"
585
608
  {
586
609
  *result = Qfalse;
587
610
  }
588
- goto st21;
589
- tr25:
590
- #line 196 "parser.rl"
611
+ goto st29;
612
+ tr34:
613
+ #line 210 "parser.rl"
591
614
  {
592
615
  *result = Qnil;
593
616
  }
594
- goto st21;
595
- tr28:
596
- #line 202 "parser.rl"
617
+ goto st29;
618
+ tr37:
619
+ #line 216 "parser.rl"
597
620
  {
598
621
  *result = Qtrue;
599
622
  }
600
- goto st21;
601
- st21:
602
- if ( ++p == pe )
603
- goto _test_eof21;
604
- case 21:
605
- #line 258 "parser.rl"
606
- { p--; {p++; cs = 21; goto _out;} }
607
- #line 608 "parser.c"
623
+ goto st29;
624
+ st29:
625
+ if ( ++p == pe )
626
+ goto _test_eof29;
627
+ case 29:
628
+ #line 272 "parser.rl"
629
+ { p--; {p++; cs = 29; goto _out;} }
630
+ #line 631 "parser.c"
631
+ switch( (*p) ) {
632
+ case 13: goto st29;
633
+ case 32: goto st29;
634
+ case 47: goto st2;
635
+ }
636
+ if ( 9 <= (*p) && (*p) <= 10 )
637
+ goto st29;
608
638
  goto st0;
609
639
  st2:
610
640
  if ( ++p == pe )
611
641
  goto _test_eof2;
612
642
  case 2:
613
- if ( (*p) == 110 )
614
- goto st3;
643
+ switch( (*p) ) {
644
+ case 42: goto st3;
645
+ case 47: goto st5;
646
+ }
615
647
  goto st0;
616
648
  st3:
617
649
  if ( ++p == pe )
618
650
  goto _test_eof3;
619
651
  case 3:
620
- if ( (*p) == 102 )
652
+ if ( (*p) == 42 )
621
653
  goto st4;
622
- goto st0;
654
+ goto st3;
623
655
  st4:
624
656
  if ( ++p == pe )
625
657
  goto _test_eof4;
626
658
  case 4:
627
- if ( (*p) == 105 )
628
- goto st5;
629
- goto st0;
659
+ switch( (*p) ) {
660
+ case 42: goto st4;
661
+ case 47: goto st29;
662
+ }
663
+ goto st3;
630
664
  st5:
631
665
  if ( ++p == pe )
632
666
  goto _test_eof5;
633
667
  case 5:
634
- if ( (*p) == 110 )
635
- goto st6;
636
- goto st0;
668
+ if ( (*p) == 10 )
669
+ goto st29;
670
+ goto st5;
637
671
  st6:
638
672
  if ( ++p == pe )
639
673
  goto _test_eof6;
640
674
  case 6:
641
- if ( (*p) == 105 )
642
- goto st7;
675
+ switch( (*p) ) {
676
+ case 42: goto st7;
677
+ case 47: goto st9;
678
+ }
643
679
  goto st0;
644
680
  st7:
645
681
  if ( ++p == pe )
646
682
  goto _test_eof7;
647
683
  case 7:
648
- if ( (*p) == 116 )
684
+ if ( (*p) == 42 )
649
685
  goto st8;
650
- goto st0;
686
+ goto st7;
651
687
  st8:
652
688
  if ( ++p == pe )
653
689
  goto _test_eof8;
654
690
  case 8:
655
- if ( (*p) == 121 )
656
- goto tr16;
657
- goto st0;
691
+ switch( (*p) ) {
692
+ case 42: goto st8;
693
+ case 47: goto st1;
694
+ }
695
+ goto st7;
658
696
  st9:
659
697
  if ( ++p == pe )
660
698
  goto _test_eof9;
661
699
  case 9:
662
- if ( (*p) == 97 )
663
- goto st10;
664
- goto st0;
700
+ if ( (*p) == 10 )
701
+ goto st1;
702
+ goto st9;
665
703
  st10:
666
704
  if ( ++p == pe )
667
705
  goto _test_eof10;
668
706
  case 10:
669
- if ( (*p) == 78 )
670
- goto tr18;
707
+ if ( (*p) == 110 )
708
+ goto st11;
671
709
  goto st0;
672
710
  st11:
673
711
  if ( ++p == pe )
674
712
  goto _test_eof11;
675
713
  case 11:
676
- if ( (*p) == 97 )
714
+ if ( (*p) == 102 )
677
715
  goto st12;
678
716
  goto st0;
679
717
  st12:
680
718
  if ( ++p == pe )
681
719
  goto _test_eof12;
682
720
  case 12:
683
- if ( (*p) == 108 )
721
+ if ( (*p) == 105 )
684
722
  goto st13;
685
723
  goto st0;
686
724
  st13:
687
725
  if ( ++p == pe )
688
726
  goto _test_eof13;
689
727
  case 13:
690
- if ( (*p) == 115 )
728
+ if ( (*p) == 110 )
691
729
  goto st14;
692
730
  goto st0;
693
731
  st14:
694
732
  if ( ++p == pe )
695
733
  goto _test_eof14;
696
734
  case 14:
697
- if ( (*p) == 101 )
698
- goto tr22;
735
+ if ( (*p) == 105 )
736
+ goto st15;
699
737
  goto st0;
700
738
  st15:
701
739
  if ( ++p == pe )
702
740
  goto _test_eof15;
703
741
  case 15:
704
- if ( (*p) == 117 )
742
+ if ( (*p) == 116 )
705
743
  goto st16;
706
744
  goto st0;
707
745
  st16:
708
746
  if ( ++p == pe )
709
747
  goto _test_eof16;
710
748
  case 16:
711
- if ( (*p) == 108 )
712
- goto st17;
749
+ if ( (*p) == 121 )
750
+ goto tr25;
713
751
  goto st0;
714
752
  st17:
715
753
  if ( ++p == pe )
716
754
  goto _test_eof17;
717
755
  case 17:
718
- if ( (*p) == 108 )
719
- goto tr25;
756
+ if ( (*p) == 97 )
757
+ goto st18;
720
758
  goto st0;
721
759
  st18:
722
760
  if ( ++p == pe )
723
761
  goto _test_eof18;
724
762
  case 18:
725
- if ( (*p) == 114 )
726
- goto st19;
763
+ if ( (*p) == 78 )
764
+ goto tr27;
727
765
  goto st0;
728
766
  st19:
729
767
  if ( ++p == pe )
730
768
  goto _test_eof19;
731
769
  case 19:
732
- if ( (*p) == 117 )
770
+ if ( (*p) == 97 )
733
771
  goto st20;
734
772
  goto st0;
735
773
  st20:
736
774
  if ( ++p == pe )
737
775
  goto _test_eof20;
738
776
  case 20:
777
+ if ( (*p) == 108 )
778
+ goto st21;
779
+ goto st0;
780
+ st21:
781
+ if ( ++p == pe )
782
+ goto _test_eof21;
783
+ case 21:
784
+ if ( (*p) == 115 )
785
+ goto st22;
786
+ goto st0;
787
+ st22:
788
+ if ( ++p == pe )
789
+ goto _test_eof22;
790
+ case 22:
791
+ if ( (*p) == 101 )
792
+ goto tr31;
793
+ goto st0;
794
+ st23:
795
+ if ( ++p == pe )
796
+ goto _test_eof23;
797
+ case 23:
798
+ if ( (*p) == 117 )
799
+ goto st24;
800
+ goto st0;
801
+ st24:
802
+ if ( ++p == pe )
803
+ goto _test_eof24;
804
+ case 24:
805
+ if ( (*p) == 108 )
806
+ goto st25;
807
+ goto st0;
808
+ st25:
809
+ if ( ++p == pe )
810
+ goto _test_eof25;
811
+ case 25:
812
+ if ( (*p) == 108 )
813
+ goto tr34;
814
+ goto st0;
815
+ st26:
816
+ if ( ++p == pe )
817
+ goto _test_eof26;
818
+ case 26:
819
+ if ( (*p) == 114 )
820
+ goto st27;
821
+ goto st0;
822
+ st27:
823
+ if ( ++p == pe )
824
+ goto _test_eof27;
825
+ case 27:
826
+ if ( (*p) == 117 )
827
+ goto st28;
828
+ goto st0;
829
+ st28:
830
+ if ( ++p == pe )
831
+ goto _test_eof28;
832
+ case 28:
739
833
  if ( (*p) == 101 )
740
- goto tr28;
834
+ goto tr37;
741
835
  goto st0;
742
836
  }
743
- _test_eof21: cs = 21; goto _test_eof;
837
+ _test_eof1: cs = 1; goto _test_eof;
838
+ _test_eof29: cs = 29; goto _test_eof;
744
839
  _test_eof2: cs = 2; goto _test_eof;
745
840
  _test_eof3: cs = 3; goto _test_eof;
746
841
  _test_eof4: cs = 4; goto _test_eof;
@@ -760,12 +855,20 @@ case 20:
760
855
  _test_eof18: cs = 18; goto _test_eof;
761
856
  _test_eof19: cs = 19; goto _test_eof;
762
857
  _test_eof20: cs = 20; goto _test_eof;
858
+ _test_eof21: cs = 21; goto _test_eof;
859
+ _test_eof22: cs = 22; goto _test_eof;
860
+ _test_eof23: cs = 23; goto _test_eof;
861
+ _test_eof24: cs = 24; goto _test_eof;
862
+ _test_eof25: cs = 25; goto _test_eof;
863
+ _test_eof26: cs = 26; goto _test_eof;
864
+ _test_eof27: cs = 27; goto _test_eof;
865
+ _test_eof28: cs = 28; goto _test_eof;
763
866
 
764
867
  _test_eof: {}
765
868
  _out: {}
766
869
  }
767
870
 
768
- #line 279 "parser.rl"
871
+ #line 293 "parser.rl"
769
872
 
770
873
  if (cs >= JSON_value_first_final) {
771
874
  return p;
@@ -775,7 +878,7 @@ case 20:
775
878
  }
776
879
 
777
880
 
778
- #line 779 "parser.c"
881
+ #line 882 "parser.c"
779
882
  enum {JSON_integer_start = 1};
780
883
  enum {JSON_integer_first_final = 3};
781
884
  enum {JSON_integer_error = 0};
@@ -783,7 +886,7 @@ enum {JSON_integer_error = 0};
783
886
  enum {JSON_integer_en_main = 1};
784
887
 
785
888
 
786
- #line 295 "parser.rl"
889
+ #line 309 "parser.rl"
787
890
 
788
891
 
789
892
  static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -791,15 +894,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
791
894
  int cs = EVIL;
792
895
 
793
896
 
794
- #line 795 "parser.c"
897
+ #line 898 "parser.c"
795
898
  {
796
899
  cs = JSON_integer_start;
797
900
  }
798
901
 
799
- #line 302 "parser.rl"
902
+ #line 316 "parser.rl"
800
903
  json->memo = p;
801
904
 
802
- #line 803 "parser.c"
905
+ #line 906 "parser.c"
803
906
  {
804
907
  if ( p == pe )
805
908
  goto _test_eof;
@@ -833,14 +936,14 @@ case 3:
833
936
  goto st0;
834
937
  goto tr4;
835
938
  tr4:
836
- #line 292 "parser.rl"
939
+ #line 306 "parser.rl"
837
940
  { p--; {p++; cs = 4; goto _out;} }
838
941
  goto st4;
839
942
  st4:
840
943
  if ( ++p == pe )
841
944
  goto _test_eof4;
842
945
  case 4:
843
- #line 844 "parser.c"
946
+ #line 947 "parser.c"
844
947
  goto st0;
845
948
  st5:
846
949
  if ( ++p == pe )
@@ -859,7 +962,7 @@ case 5:
859
962
  _out: {}
860
963
  }
861
964
 
862
- #line 304 "parser.rl"
965
+ #line 318 "parser.rl"
863
966
 
864
967
  if (cs >= JSON_integer_first_final) {
865
968
  long len = p - json->memo;
@@ -874,7 +977,7 @@ case 5:
874
977
  }
875
978
 
876
979
 
877
- #line 878 "parser.c"
980
+ #line 981 "parser.c"
878
981
  enum {JSON_float_start = 1};
879
982
  enum {JSON_float_first_final = 8};
880
983
  enum {JSON_float_error = 0};
@@ -882,7 +985,7 @@ enum {JSON_float_error = 0};
882
985
  enum {JSON_float_en_main = 1};
883
986
 
884
987
 
885
- #line 329 "parser.rl"
988
+ #line 343 "parser.rl"
886
989
 
887
990
 
888
991
  static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -890,15 +993,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
890
993
  int cs = EVIL;
891
994
 
892
995
 
893
- #line 894 "parser.c"
996
+ #line 997 "parser.c"
894
997
  {
895
998
  cs = JSON_float_start;
896
999
  }
897
1000
 
898
- #line 336 "parser.rl"
1001
+ #line 350 "parser.rl"
899
1002
  json->memo = p;
900
1003
 
901
- #line 902 "parser.c"
1004
+ #line 1005 "parser.c"
902
1005
  {
903
1006
  if ( p == pe )
904
1007
  goto _test_eof;
@@ -956,14 +1059,14 @@ case 8:
956
1059
  goto st0;
957
1060
  goto tr9;
958
1061
  tr9:
959
- #line 323 "parser.rl"
1062
+ #line 337 "parser.rl"
960
1063
  { p--; {p++; cs = 9; goto _out;} }
961
1064
  goto st9;
962
1065
  st9:
963
1066
  if ( ++p == pe )
964
1067
  goto _test_eof9;
965
1068
  case 9:
966
- #line 967 "parser.c"
1069
+ #line 1070 "parser.c"
967
1070
  goto st0;
968
1071
  st5:
969
1072
  if ( ++p == pe )
@@ -1024,7 +1127,7 @@ case 7:
1024
1127
  _out: {}
1025
1128
  }
1026
1129
 
1027
- #line 338 "parser.rl"
1130
+ #line 352 "parser.rl"
1028
1131
 
1029
1132
  if (cs >= JSON_float_first_final) {
1030
1133
  long len = p - json->memo;
@@ -1040,7 +1143,7 @@ case 7:
1040
1143
 
1041
1144
 
1042
1145
 
1043
- #line 1044 "parser.c"
1146
+ #line 1147 "parser.c"
1044
1147
  enum {JSON_array_start = 1};
1045
1148
  enum {JSON_array_first_final = 17};
1046
1149
  enum {JSON_array_error = 0};
@@ -1048,7 +1151,7 @@ enum {JSON_array_error = 0};
1048
1151
  enum {JSON_array_en_main = 1};
1049
1152
 
1050
1153
 
1051
- #line 381 "parser.rl"
1154
+ #line 395 "parser.rl"
1052
1155
 
1053
1156
 
1054
1157
  static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1062,14 +1165,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
1062
1165
  *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
1063
1166
 
1064
1167
 
1065
- #line 1066 "parser.c"
1168
+ #line 1169 "parser.c"
1066
1169
  {
1067
1170
  cs = JSON_array_start;
1068
1171
  }
1069
1172
 
1070
- #line 394 "parser.rl"
1173
+ #line 408 "parser.rl"
1071
1174
 
1072
- #line 1073 "parser.c"
1175
+ #line 1176 "parser.c"
1073
1176
  {
1074
1177
  if ( p == pe )
1075
1178
  goto _test_eof;
@@ -1108,7 +1211,7 @@ case 2:
1108
1211
  goto st2;
1109
1212
  goto st0;
1110
1213
  tr2:
1111
- #line 358 "parser.rl"
1214
+ #line 372 "parser.rl"
1112
1215
  {
1113
1216
  VALUE v = Qnil;
1114
1217
  char *np = JSON_parse_value(json, p, pe, &v);
@@ -1128,7 +1231,7 @@ st3:
1128
1231
  if ( ++p == pe )
1129
1232
  goto _test_eof3;
1130
1233
  case 3:
1131
- #line 1132 "parser.c"
1234
+ #line 1235 "parser.c"
1132
1235
  switch( (*p) ) {
1133
1236
  case 13: goto st3;
1134
1237
  case 32: goto st3;
@@ -1228,14 +1331,14 @@ case 12:
1228
1331
  goto st3;
1229
1332
  goto st12;
1230
1333
  tr4:
1231
- #line 373 "parser.rl"
1334
+ #line 387 "parser.rl"
1232
1335
  { p--; {p++; cs = 17; goto _out;} }
1233
1336
  goto st17;
1234
1337
  st17:
1235
1338
  if ( ++p == pe )
1236
1339
  goto _test_eof17;
1237
1340
  case 17:
1238
- #line 1239 "parser.c"
1341
+ #line 1342 "parser.c"
1239
1342
  goto st0;
1240
1343
  st13:
1241
1344
  if ( ++p == pe )
@@ -1291,12 +1394,12 @@ case 16:
1291
1394
  _out: {}
1292
1395
  }
1293
1396
 
1294
- #line 395 "parser.rl"
1397
+ #line 409 "parser.rl"
1295
1398
 
1296
1399
  if(cs >= JSON_array_first_final) {
1297
1400
  return p + 1;
1298
1401
  } else {
1299
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1402
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1300
1403
  return NULL;
1301
1404
  }
1302
1405
  }
@@ -1372,7 +1475,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1372
1475
  }
1373
1476
 
1374
1477
 
1375
- #line 1376 "parser.c"
1478
+ #line 1479 "parser.c"
1376
1479
  enum {JSON_string_start = 1};
1377
1480
  enum {JSON_string_first_final = 8};
1378
1481
  enum {JSON_string_error = 0};
@@ -1380,7 +1483,7 @@ enum {JSON_string_error = 0};
1380
1483
  enum {JSON_string_en_main = 1};
1381
1484
 
1382
1485
 
1383
- #line 494 "parser.rl"
1486
+ #line 508 "parser.rl"
1384
1487
 
1385
1488
 
1386
1489
  static int
@@ -1402,15 +1505,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
1402
1505
 
1403
1506
  *result = rb_str_buf_new(0);
1404
1507
 
1405
- #line 1406 "parser.c"
1508
+ #line 1509 "parser.c"
1406
1509
  {
1407
1510
  cs = JSON_string_start;
1408
1511
  }
1409
1512
 
1410
- #line 515 "parser.rl"
1513
+ #line 529 "parser.rl"
1411
1514
  json->memo = p;
1412
1515
 
1413
- #line 1414 "parser.c"
1516
+ #line 1517 "parser.c"
1414
1517
  {
1415
1518
  if ( p == pe )
1416
1519
  goto _test_eof;
@@ -1435,7 +1538,7 @@ case 2:
1435
1538
  goto st0;
1436
1539
  goto st2;
1437
1540
  tr2:
1438
- #line 480 "parser.rl"
1541
+ #line 494 "parser.rl"
1439
1542
  {
1440
1543
  *result = json_string_unescape(*result, json->memo + 1, p);
1441
1544
  if (NIL_P(*result)) {
@@ -1446,14 +1549,14 @@ tr2:
1446
1549
  {p = (( p + 1))-1;}
1447
1550
  }
1448
1551
  }
1449
- #line 491 "parser.rl"
1552
+ #line 505 "parser.rl"
1450
1553
  { p--; {p++; cs = 8; goto _out;} }
1451
1554
  goto st8;
1452
1555
  st8:
1453
1556
  if ( ++p == pe )
1454
1557
  goto _test_eof8;
1455
1558
  case 8:
1456
- #line 1457 "parser.c"
1559
+ #line 1560 "parser.c"
1457
1560
  goto st0;
1458
1561
  st3:
1459
1562
  if ( ++p == pe )
@@ -1529,7 +1632,7 @@ case 7:
1529
1632
  _out: {}
1530
1633
  }
1531
1634
 
1532
- #line 517 "parser.rl"
1635
+ #line 531 "parser.rl"
1533
1636
 
1534
1637
  if (json->create_additions && RTEST(match_string = json->match_string)) {
1535
1638
  VALUE klass;
@@ -1544,6 +1647,8 @@ case 7:
1544
1647
 
1545
1648
  if (json->symbolize_names && json->parsing_name) {
1546
1649
  *result = rb_str_intern(*result);
1650
+ } else {
1651
+ rb_str_resize(*result, RSTRING_LEN(*result));
1547
1652
  }
1548
1653
  if (cs >= JSON_string_first_final) {
1549
1654
  return p + 1;
@@ -1566,41 +1671,13 @@ case 7:
1566
1671
 
1567
1672
  static VALUE convert_encoding(VALUE source)
1568
1673
  {
1569
- char *ptr = RSTRING_PTR(source);
1570
- long len = RSTRING_LEN(source);
1571
- if (len < 2) {
1572
- rb_raise(eParserError, "A JSON text must at least contain two octets!");
1573
- }
1574
1674
  #ifdef HAVE_RUBY_ENCODING_H
1575
- {
1576
- VALUE encoding = rb_funcall(source, i_encoding, 0);
1577
- if (encoding == CEncoding_ASCII_8BIT) {
1578
- if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
1579
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
1580
- } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
1581
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
1582
- } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
1583
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
1584
- } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
1585
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
1586
- } else {
1587
- source = rb_str_dup(source);
1588
- FORCE_UTF8(source);
1589
- }
1590
- } else {
1591
- source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
1592
- }
1593
- }
1594
- #else
1595
- if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
1596
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32be"), source);
1597
- } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
1598
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16be"), source);
1599
- } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
1600
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32le"), source);
1601
- } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
1602
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16le"), source);
1603
- }
1675
+ rb_encoding *enc = rb_enc_get(source);
1676
+ if (enc == rb_ascii8bit_encoding()) {
1677
+ FORCE_UTF8(source);
1678
+ } else {
1679
+ source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
1680
+ }
1604
1681
  #endif
1605
1682
  return source;
1606
1683
  }
@@ -1623,8 +1700,9 @@ static VALUE convert_encoding(VALUE source)
1623
1700
  * defiance of RFC 4627 to be parsed by the Parser. This option defaults to
1624
1701
  * false.
1625
1702
  * * *symbolize_names*: If set to true, returns symbols for the names
1626
- * (keys) in a JSON object. Otherwise strings are returned, which is also
1627
- * the default.
1703
+ * (keys) in a JSON object. Otherwise strings are returned, which is
1704
+ * also the default. It's not possible to use this option in
1705
+ * conjunction with the *create_additions* option.
1628
1706
  * * *create_additions*: If set to false, the Parser doesn't create
1629
1707
  * additions even if a matching class and create_id was found. This option
1630
1708
  * defaults to false.
@@ -1639,12 +1717,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1639
1717
  if (json->Vsource) {
1640
1718
  rb_raise(rb_eTypeError, "already initialized instance");
1641
1719
  }
1720
+ #ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1721
+ rb_scan_args(argc, argv, "1:", &source, &opts);
1722
+ #else
1642
1723
  rb_scan_args(argc, argv, "11", &source, &opts);
1724
+ #endif
1643
1725
  if (!NIL_P(opts)) {
1726
+ #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1644
1727
  opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
1645
1728
  if (NIL_P(opts)) {
1646
1729
  rb_raise(rb_eArgError, "opts needs to be like a hash");
1647
1730
  } else {
1731
+ #endif
1648
1732
  VALUE tmp = ID2SYM(i_max_nesting);
1649
1733
  if (option_given_p(opts, tmp)) {
1650
1734
  VALUE max_nesting = rb_hash_aref(opts, tmp);
@@ -1669,19 +1753,17 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1669
1753
  } else {
1670
1754
  json->symbolize_names = 0;
1671
1755
  }
1672
- tmp = ID2SYM(i_quirks_mode);
1673
- if (option_given_p(opts, tmp)) {
1674
- VALUE quirks_mode = rb_hash_aref(opts, tmp);
1675
- json->quirks_mode = RTEST(quirks_mode) ? 1 : 0;
1676
- } else {
1677
- json->quirks_mode = 0;
1678
- }
1679
1756
  tmp = ID2SYM(i_create_additions);
1680
1757
  if (option_given_p(opts, tmp)) {
1681
1758
  json->create_additions = RTEST(rb_hash_aref(opts, tmp));
1682
1759
  } else {
1683
1760
  json->create_additions = 0;
1684
1761
  }
1762
+ if (json->symbolize_names && json->create_additions) {
1763
+ rb_raise(rb_eArgError,
1764
+ "options :symbolize_names and :create_additions cannot be "
1765
+ " used in conjunction");
1766
+ }
1685
1767
  tmp = ID2SYM(i_create_id);
1686
1768
  if (option_given_p(opts, tmp)) {
1687
1769
  json->create_id = rb_hash_aref(opts, tmp);
@@ -1707,7 +1789,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1707
1789
  } else {
1708
1790
  json->match_string = Qnil;
1709
1791
  }
1792
+ #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1710
1793
  }
1794
+ #endif
1711
1795
  } else {
1712
1796
  json->max_nesting = 100;
1713
1797
  json->allow_nan = 0;
@@ -1716,10 +1800,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1716
1800
  json->object_class = Qnil;
1717
1801
  json->array_class = Qnil;
1718
1802
  }
1719
- source = rb_convert_type(source, T_STRING, "String", "to_str");
1720
- if (!json->quirks_mode) {
1721
- source = convert_encoding(StringValue(source));
1722
- }
1803
+ source = convert_encoding(StringValue(source));
1723
1804
  json->current_nesting = 0;
1724
1805
  StringValue(source);
1725
1806
  json->len = RSTRING_LEN(source);
@@ -1729,7 +1810,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1729
1810
  }
1730
1811
 
1731
1812
 
1732
- #line 1733 "parser.c"
1813
+ #line 1814 "parser.c"
1733
1814
  enum {JSON_start = 1};
1734
1815
  enum {JSON_first_final = 10};
1735
1816
  enum {JSON_error = 0};
@@ -1737,201 +1818,33 @@ enum {JSON_error = 0};
1737
1818
  enum {JSON_en_main = 1};
1738
1819
 
1739
1820
 
1740
- #line 740 "parser.rl"
1741
-
1742
-
1743
- static VALUE cParser_parse_strict(VALUE self)
1744
- {
1745
- char *p, *pe;
1746
- int cs = EVIL;
1747
- VALUE result = Qnil;
1748
- GET_PARSER;
1749
-
1750
-
1751
- #line 1752 "parser.c"
1752
- {
1753
- cs = JSON_start;
1754
- }
1755
-
1756
- #line 750 "parser.rl"
1757
- p = json->source;
1758
- pe = p + json->len;
1759
-
1760
- #line 1761 "parser.c"
1761
- {
1762
- if ( p == pe )
1763
- goto _test_eof;
1764
- switch ( cs )
1765
- {
1766
- st1:
1767
- if ( ++p == pe )
1768
- goto _test_eof1;
1769
- case 1:
1770
- switch( (*p) ) {
1771
- case 13: goto st1;
1772
- case 32: goto st1;
1773
- case 47: goto st2;
1774
- case 91: goto tr3;
1775
- case 123: goto tr4;
1776
- }
1777
- if ( 9 <= (*p) && (*p) <= 10 )
1778
- goto st1;
1779
- goto st0;
1780
- st0:
1781
- cs = 0;
1782
- goto _out;
1783
- st2:
1784
- if ( ++p == pe )
1785
- goto _test_eof2;
1786
- case 2:
1787
- switch( (*p) ) {
1788
- case 42: goto st3;
1789
- case 47: goto st5;
1790
- }
1791
- goto st0;
1792
- st3:
1793
- if ( ++p == pe )
1794
- goto _test_eof3;
1795
- case 3:
1796
- if ( (*p) == 42 )
1797
- goto st4;
1798
- goto st3;
1799
- st4:
1800
- if ( ++p == pe )
1801
- goto _test_eof4;
1802
- case 4:
1803
- switch( (*p) ) {
1804
- case 42: goto st4;
1805
- case 47: goto st1;
1806
- }
1807
- goto st3;
1808
- st5:
1809
- if ( ++p == pe )
1810
- goto _test_eof5;
1811
- case 5:
1812
- if ( (*p) == 10 )
1813
- goto st1;
1814
- goto st5;
1815
- tr3:
1816
- #line 729 "parser.rl"
1817
- {
1818
- char *np;
1819
- json->current_nesting = 1;
1820
- np = JSON_parse_array(json, p, pe, &result);
1821
- if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1822
- }
1823
- goto st10;
1824
- tr4:
1825
1821
  #line 722 "parser.rl"
1826
- {
1827
- char *np;
1828
- json->current_nesting = 1;
1829
- np = JSON_parse_object(json, p, pe, &result);
1830
- if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1831
- }
1832
- goto st10;
1833
- st10:
1834
- if ( ++p == pe )
1835
- goto _test_eof10;
1836
- case 10:
1837
- #line 1838 "parser.c"
1838
- switch( (*p) ) {
1839
- case 13: goto st10;
1840
- case 32: goto st10;
1841
- case 47: goto st6;
1842
- }
1843
- if ( 9 <= (*p) && (*p) <= 10 )
1844
- goto st10;
1845
- goto st0;
1846
- st6:
1847
- if ( ++p == pe )
1848
- goto _test_eof6;
1849
- case 6:
1850
- switch( (*p) ) {
1851
- case 42: goto st7;
1852
- case 47: goto st9;
1853
- }
1854
- goto st0;
1855
- st7:
1856
- if ( ++p == pe )
1857
- goto _test_eof7;
1858
- case 7:
1859
- if ( (*p) == 42 )
1860
- goto st8;
1861
- goto st7;
1862
- st8:
1863
- if ( ++p == pe )
1864
- goto _test_eof8;
1865
- case 8:
1866
- switch( (*p) ) {
1867
- case 42: goto st8;
1868
- case 47: goto st10;
1869
- }
1870
- goto st7;
1871
- st9:
1872
- if ( ++p == pe )
1873
- goto _test_eof9;
1874
- case 9:
1875
- if ( (*p) == 10 )
1876
- goto st10;
1877
- goto st9;
1878
- }
1879
- _test_eof1: cs = 1; goto _test_eof;
1880
- _test_eof2: cs = 2; goto _test_eof;
1881
- _test_eof3: cs = 3; goto _test_eof;
1882
- _test_eof4: cs = 4; goto _test_eof;
1883
- _test_eof5: cs = 5; goto _test_eof;
1884
- _test_eof10: cs = 10; goto _test_eof;
1885
- _test_eof6: cs = 6; goto _test_eof;
1886
- _test_eof7: cs = 7; goto _test_eof;
1887
- _test_eof8: cs = 8; goto _test_eof;
1888
- _test_eof9: cs = 9; goto _test_eof;
1889
-
1890
- _test_eof: {}
1891
- _out: {}
1892
- }
1893
-
1894
- #line 753 "parser.rl"
1895
1822
 
1896
- if (cs >= JSON_first_final && p == pe) {
1897
- return result;
1898
- } else {
1899
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1900
- return Qnil;
1901
- }
1902
- }
1903
-
1904
-
1905
-
1906
- #line 1907 "parser.c"
1907
- enum {JSON_quirks_mode_start = 1};
1908
- enum {JSON_quirks_mode_first_final = 10};
1909
- enum {JSON_quirks_mode_error = 0};
1910
1823
 
1911
- enum {JSON_quirks_mode_en_main = 1};
1912
-
1913
-
1914
- #line 778 "parser.rl"
1915
-
1916
-
1917
- static VALUE cParser_parse_quirks_mode(VALUE self)
1824
+ /*
1825
+ * call-seq: parse()
1826
+ *
1827
+ * Parses the current JSON text _source_ and returns the complete data
1828
+ * structure as a result.
1829
+ */
1830
+ static VALUE cParser_parse(VALUE self)
1918
1831
  {
1919
- char *p, *pe;
1920
- int cs = EVIL;
1921
- VALUE result = Qnil;
1922
- GET_PARSER;
1832
+ char *p, *pe;
1833
+ int cs = EVIL;
1834
+ VALUE result = Qnil;
1835
+ GET_PARSER;
1923
1836
 
1924
1837
 
1925
- #line 1926 "parser.c"
1838
+ #line 1839 "parser.c"
1926
1839
  {
1927
- cs = JSON_quirks_mode_start;
1840
+ cs = JSON_start;
1928
1841
  }
1929
1842
 
1930
- #line 788 "parser.rl"
1931
- p = json->source;
1932
- pe = p + json->len;
1843
+ #line 738 "parser.rl"
1844
+ p = json->source;
1845
+ pe = p + json->len;
1933
1846
 
1934
- #line 1935 "parser.c"
1847
+ #line 1848 "parser.c"
1935
1848
  {
1936
1849
  if ( p == pe )
1937
1850
  goto _test_eof;
@@ -1965,7 +1878,7 @@ st0:
1965
1878
  cs = 0;
1966
1879
  goto _out;
1967
1880
  tr2:
1968
- #line 770 "parser.rl"
1881
+ #line 714 "parser.rl"
1969
1882
  {
1970
1883
  char *np = JSON_parse_value(json, p, pe, &result);
1971
1884
  if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1975,7 +1888,7 @@ st10:
1975
1888
  if ( ++p == pe )
1976
1889
  goto _test_eof10;
1977
1890
  case 10:
1978
- #line 1979 "parser.c"
1891
+ #line 1892 "parser.c"
1979
1892
  switch( (*p) ) {
1980
1893
  case 13: goto st10;
1981
1894
  case 32: goto st10;
@@ -2064,30 +1977,13 @@ case 9:
2064
1977
  _out: {}
2065
1978
  }
2066
1979
 
2067
- #line 791 "parser.rl"
1980
+ #line 741 "parser.rl"
2068
1981
 
2069
- if (cs >= JSON_quirks_mode_first_final && p == pe) {
2070
- return result;
2071
- } else {
2072
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
2073
- return Qnil;
2074
- }
2075
- }
2076
-
2077
- /*
2078
- * call-seq: parse()
2079
- *
2080
- * Parses the current JSON text _source_ and returns the complete data
2081
- * structure as a result.
2082
- */
2083
- static VALUE cParser_parse(VALUE self)
2084
- {
2085
- GET_PARSER;
2086
-
2087
- if (json->quirks_mode) {
2088
- return cParser_parse_quirks_mode(self);
1982
+ if (cs >= JSON_first_final && p == pe) {
1983
+ return result;
2089
1984
  } else {
2090
- return cParser_parse_strict(self);
1985
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1986
+ return Qnil;
2091
1987
  }
2092
1988
  }
2093
1989
 
@@ -2145,18 +2041,6 @@ static VALUE cParser_source(VALUE self)
2145
2041
  return rb_str_dup(json->Vsource);
2146
2042
  }
2147
2043
 
2148
- /*
2149
- * call-seq: quirks_mode?()
2150
- *
2151
- * Returns a true, if this parser is in quirks_mode, false otherwise.
2152
- */
2153
- static VALUE cParser_quirks_mode_p(VALUE self)
2154
- {
2155
- GET_PARSER;
2156
- return json->quirks_mode ? Qtrue : Qfalse;
2157
- }
2158
-
2159
-
2160
2044
  void Init_parser(void)
2161
2045
  {
2162
2046
  rb_require("json/common");
@@ -2169,7 +2053,6 @@ void Init_parser(void)
2169
2053
  rb_define_method(cParser, "initialize", cParser_initialize, -1);
2170
2054
  rb_define_method(cParser, "parse", cParser_parse, 0);
2171
2055
  rb_define_method(cParser, "source", cParser_source, 0);
2172
- rb_define_method(cParser, "quirks_mode?", cParser_quirks_mode_p, 0);
2173
2056
 
2174
2057
  CNaN = rb_const_get(mJSON, rb_intern("NaN"));
2175
2058
  CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
@@ -2183,7 +2066,6 @@ void Init_parser(void)
2183
2066
  i_max_nesting = rb_intern("max_nesting");
2184
2067
  i_allow_nan = rb_intern("allow_nan");
2185
2068
  i_symbolize_names = rb_intern("symbolize_names");
2186
- i_quirks_mode = rb_intern("quirks_mode");
2187
2069
  i_object_class = rb_intern("object_class");
2188
2070
  i_array_class = rb_intern("array_class");
2189
2071
  i_match = rb_intern("match");
@@ -2193,18 +2075,6 @@ void Init_parser(void)
2193
2075
  i_aset = rb_intern("[]=");
2194
2076
  i_aref = rb_intern("[]");
2195
2077
  i_leftshift = rb_intern("<<");
2196
- #ifdef HAVE_RUBY_ENCODING_H
2197
- CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
2198
- CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
2199
- CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
2200
- CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
2201
- CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
2202
- CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
2203
- i_encoding = rb_intern("encoding");
2204
- i_encode = rb_intern("encode");
2205
- #else
2206
- i_iconv = rb_intern("iconv");
2207
- #endif
2208
2078
  }
2209
2079
 
2210
2080
  /*