json 1.8.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +3 -10
  4. data/{CHANGES → CHANGES.md} +183 -90
  5. data/Gemfile +11 -5
  6. data/{README-json-jruby.markdown → README-json-jruby.md} +0 -0
  7. data/{README.rdoc → README.md} +147 -113
  8. data/Rakefile +32 -36
  9. data/VERSION +1 -1
  10. data/ext/json/ext/fbuffer/fbuffer.h +0 -3
  11. data/ext/json/ext/generator/generator.c +46 -61
  12. data/ext/json/ext/generator/generator.h +7 -2
  13. data/ext/json/ext/parser/extconf.rb +3 -0
  14. data/ext/json/ext/parser/parser.c +353 -460
  15. data/ext/json/ext/parser/parser.h +4 -5
  16. data/ext/json/ext/parser/parser.rl +111 -181
  17. data/ext/json/extconf.rb +0 -1
  18. data/java/src/json/ext/ByteListTranscoder.java +1 -2
  19. data/java/src/json/ext/Generator.java +11 -12
  20. data/java/src/json/ext/GeneratorMethods.java +1 -2
  21. data/java/src/json/ext/GeneratorService.java +1 -2
  22. data/java/src/json/ext/GeneratorState.java +3 -56
  23. data/java/src/json/ext/OptionsReader.java +2 -3
  24. data/java/src/json/ext/Parser.java +135 -418
  25. data/java/src/json/ext/Parser.rl +48 -124
  26. data/java/src/json/ext/ParserService.java +1 -2
  27. data/java/src/json/ext/RuntimeInfo.java +1 -6
  28. data/java/src/json/ext/StringDecoder.java +1 -2
  29. data/java/src/json/ext/StringEncoder.java +5 -0
  30. data/java/src/json/ext/Utils.java +1 -2
  31. data/json-java.gemspec +15 -0
  32. data/json.gemspec +0 -0
  33. data/json_pure.gemspec +24 -26
  34. data/lib/json/add/bigdecimal.rb +1 -0
  35. data/lib/json/add/complex.rb +2 -1
  36. data/lib/json/add/core.rb +1 -0
  37. data/lib/json/add/date.rb +1 -1
  38. data/lib/json/add/date_time.rb +1 -1
  39. data/lib/json/add/exception.rb +1 -1
  40. data/lib/json/add/ostruct.rb +2 -2
  41. data/lib/json/add/range.rb +1 -1
  42. data/lib/json/add/rational.rb +1 -0
  43. data/lib/json/add/regexp.rb +1 -1
  44. data/lib/json/add/struct.rb +1 -1
  45. data/lib/json/add/symbol.rb +1 -1
  46. data/lib/json/add/time.rb +1 -1
  47. data/lib/json/common.rb +24 -52
  48. data/lib/json/ext.rb +0 -6
  49. data/lib/json/generic_object.rb +5 -4
  50. data/lib/json/pure/generator.rb +61 -125
  51. data/lib/json/pure/parser.rb +33 -81
  52. data/lib/json/pure.rb +2 -8
  53. data/lib/json/version.rb +2 -1
  54. data/lib/json.rb +1 -0
  55. data/references/rfc7159.txt +899 -0
  56. data/tests/fixtures/obsolete_fail1.json +1 -0
  57. data/tests/{test_json_addition.rb → json_addition_test.rb} +22 -25
  58. data/tests/json_common_interface_test.rb +126 -0
  59. data/tests/json_encoding_test.rb +107 -0
  60. data/tests/json_ext_parser_test.rb +15 -0
  61. data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +5 -8
  62. data/tests/{test_json_generate.rb → json_generator_test.rb} +79 -39
  63. data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
  64. data/tests/json_parser_test.rb +471 -0
  65. data/tests/json_string_matching_test.rb +38 -0
  66. data/tests/{setup_variant.rb → test_helper.rb} +10 -0
  67. data/tools/diff.sh +18 -0
  68. data/tools/fuzz.rb +1 -9
  69. metadata +28 -43
  70. data/COPYING +0 -58
  71. data/COPYING-json-jruby +0 -57
  72. data/GPL +0 -340
  73. data/TODO +0 -1
  74. data/tests/fixtures/fail1.json +0 -1
  75. data/tests/test_json.rb +0 -553
  76. data/tests/test_json_encoding.rb +0 -65
  77. data/tests/test_json_string_matching.rb +0 -39
  78. data/tests/test_json_unicode.rb +0 -72
@@ -3,8 +3,7 @@
3
3
  /*
4
4
  * This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
5
5
  *
6
- * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
7
- * for details.
6
+ * Distributed under the Ruby license: https://www.ruby-lang.org/en/about/license.txt
8
7
  */
9
8
  package json.ext;
10
9
 
@@ -53,10 +52,10 @@ public class Parser extends RubyObject {
53
52
  private int maxNesting;
54
53
  private boolean allowNaN;
55
54
  private boolean symbolizeNames;
56
- private boolean quirksMode;
57
55
  private RubyClass objectClass;
58
56
  private RubyClass arrayClass;
59
- private RubyHash match_string;
57
+ private RubyClass decimalClass;
58
+ private RubyHash matchString;
60
59
 
61
60
  private static final int DEFAULT_MAX_NESTING = 100;
62
61
 
@@ -124,10 +123,6 @@ public class Parser extends RubyObject {
124
123
  * <dd>If set to <code>true</code>, returns symbols for the names (keys) in
125
124
  * a JSON object. Otherwise strings are returned, which is also the default.
126
125
  *
127
- * <dt><code>:quirks_mode?</code>
128
- * <dd>If set to <code>true</code>, if the parse is in quirks_mode, false
129
- * otherwise.
130
- *
131
126
  * <dt><code>:create_additions</code>
132
127
  * <dd>If set to <code>false</code>, the Parser doesn't create additions
133
128
  * even if a matching class and <code>create_id</code> was found. This option
@@ -139,9 +134,10 @@ public class Parser extends RubyObject {
139
134
  * <dt><code>:array_class</code>
140
135
  * <dd>Defaults to Array.
141
136
  *
142
- * <dt><code>:quirks_mode</code>
143
- * <dd>Enables quirks_mode for parser, that is for example parsing single
144
- * JSON values instead of documents is possible.
137
+ * <dt><code>:decimal_class</code>
138
+ * <dd>Specifies which class to use instead of the default (Float) when
139
+ * parsing decimal numbers. This class must accept a single string argument
140
+ * in its constructor.
145
141
  * </dl>
146
142
  */
147
143
  @JRubyMethod(name = "new", required = 1, optional = 1, meta = true)
@@ -164,15 +160,21 @@ public class Parser extends RubyObject {
164
160
  this.maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING);
165
161
  this.allowNaN = opts.getBool("allow_nan", false);
166
162
  this.symbolizeNames = opts.getBool("symbolize_names", false);
167
- this.quirksMode = opts.getBool("quirks_mode", false);
168
163
  this.createId = opts.getString("create_id", getCreateId(context));
169
164
  this.createAdditions = opts.getBool("create_additions", false);
170
165
  this.objectClass = opts.getClass("object_class", runtime.getHash());
171
166
  this.arrayClass = opts.getClass("array_class", runtime.getArray());
172
- this.match_string = opts.getHash("match_string");
173
-
167
+ this.decimalClass = opts.getClass("decimal_class", null);
168
+ this.matchString = opts.getHash("match_string");
169
+
170
+ if(symbolizeNames && createAdditions) {
171
+ throw runtime.newArgumentError(
172
+ "options :symbolize_names and :create_additions cannot be " +
173
+ " used in conjunction"
174
+ );
175
+ }
174
176
  this.vSource = args[0].convertToString();
175
- if (!quirksMode) this.vSource = convertEncoding(context, vSource);
177
+ this.vSource = convertEncoding(context, vSource);
176
178
 
177
179
  return this;
178
180
  }
@@ -183,33 +185,16 @@ public class Parser extends RubyObject {
183
185
  * Returns the source string if no conversion is needed.
184
186
  */
185
187
  private RubyString convertEncoding(ThreadContext context, RubyString source) {
186
- ByteList bl = source.getByteList();
187
- int len = bl.length();
188
- if (len < 2) {
189
- throw Utils.newException(context, Utils.M_PARSER_ERROR,
190
- "A JSON text must at least contain two octets!");
191
- }
192
-
193
- if (info.encodingsSupported()) {
194
- RubyEncoding encoding = (RubyEncoding)source.encoding(context);
195
- if (encoding != info.ascii8bit.get()) {
196
- return (RubyString)source.encode(context, info.utf8.get());
197
- }
198
-
199
- String sniffedEncoding = sniffByteList(bl);
200
- if (sniffedEncoding == null) return source; // assume UTF-8
201
- return reinterpretEncoding(context, source, sniffedEncoding);
202
- }
203
-
204
- String sniffedEncoding = sniffByteList(bl);
205
- if (sniffedEncoding == null) return source; // assume UTF-8
206
- Ruby runtime = context.getRuntime();
207
- return (RubyString)info.jsonModule.get().
208
- callMethod(context, "iconv",
209
- new IRubyObject[] {
210
- runtime.newString("utf-8"),
211
- runtime.newString(sniffedEncoding),
212
- source});
188
+ RubyEncoding encoding = (RubyEncoding)source.encoding(context);
189
+ if (encoding == info.ascii8bit.get()) {
190
+ if (source.isFrozen()) {
191
+ source = (RubyString) source.dup();
192
+ }
193
+ source.force_encoding(context, info.utf8.get());
194
+ } else {
195
+ source = (RubyString) source.encode(context, info.utf8.get());
196
+ }
197
+ return source;
213
198
  }
214
199
 
215
200
  /**
@@ -262,17 +247,6 @@ public class Parser extends RubyObject {
262
247
  return checkAndGetSource().dup();
263
248
  }
264
249
 
265
- /**
266
- * <code>Parser#quirks_mode?()</code>
267
- *
268
- * <p>If set to <code>true</code>, if the parse is in quirks_mode, false
269
- * otherwise.
270
- */
271
- @JRubyMethod(name = "quirks_mode?")
272
- public IRubyObject quirks_mode_p(ThreadContext context) {
273
- return context.getRuntime().newBoolean(quirksMode);
274
- }
275
-
276
250
  public RubyString checkAndGetSource() {
277
251
  if (vSource != null) {
278
252
  return vSource;
@@ -339,11 +313,11 @@ public class Parser extends RubyObject {
339
313
  }
340
314
 
341
315
 
342
- // line 365 "Parser.rl"
316
+ // line 339 "Parser.rl"
343
317
 
344
318
 
345
319
 
346
- // line 347 "Parser.java"
320
+ // line 321 "Parser.java"
347
321
  private static byte[] init__JSON_value_actions_0()
348
322
  {
349
323
  return new byte [] {
@@ -457,7 +431,7 @@ static final int JSON_value_error = 0;
457
431
  static final int JSON_value_en_main = 1;
458
432
 
459
433
 
460
- // line 471 "Parser.rl"
434
+ // line 445 "Parser.rl"
461
435
 
462
436
 
463
437
  void parseValue(ParserResult res, int p, int pe) {
@@ -465,14 +439,14 @@ static final int JSON_value_en_main = 1;
465
439
  IRubyObject result = null;
466
440
 
467
441
 
468
- // line 469 "Parser.java"
442
+ // line 443 "Parser.java"
469
443
  {
470
444
  cs = JSON_value_start;
471
445
  }
472
446
 
473
- // line 478 "Parser.rl"
447
+ // line 452 "Parser.rl"
474
448
 
475
- // line 476 "Parser.java"
449
+ // line 450 "Parser.java"
476
450
  {
477
451
  int _klen;
478
452
  int _trans = 0;
@@ -498,13 +472,13 @@ case 1:
498
472
  while ( _nacts-- > 0 ) {
499
473
  switch ( _JSON_value_actions[_acts++] ) {
500
474
  case 9:
501
- // line 456 "Parser.rl"
475
+ // line 430 "Parser.rl"
502
476
  {
503
477
  p--;
504
478
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
505
479
  }
506
480
  break;
507
- // line 508 "Parser.java"
481
+ // line 482 "Parser.java"
508
482
  }
509
483
  }
510
484
 
@@ -567,25 +541,25 @@ case 1:
567
541
  switch ( _JSON_value_actions[_acts++] )
568
542
  {
569
543
  case 0:
570
- // line 373 "Parser.rl"
544
+ // line 347 "Parser.rl"
571
545
  {
572
546
  result = getRuntime().getNil();
573
547
  }
574
548
  break;
575
549
  case 1:
576
- // line 376 "Parser.rl"
550
+ // line 350 "Parser.rl"
577
551
  {
578
552
  result = getRuntime().getFalse();
579
553
  }
580
554
  break;
581
555
  case 2:
582
- // line 379 "Parser.rl"
556
+ // line 353 "Parser.rl"
583
557
  {
584
558
  result = getRuntime().getTrue();
585
559
  }
586
560
  break;
587
561
  case 3:
588
- // line 382 "Parser.rl"
562
+ // line 356 "Parser.rl"
589
563
  {
590
564
  if (parser.allowNaN) {
591
565
  result = getConstant(CONST_NAN);
@@ -595,7 +569,7 @@ case 1:
595
569
  }
596
570
  break;
597
571
  case 4:
598
- // line 389 "Parser.rl"
572
+ // line 363 "Parser.rl"
599
573
  {
600
574
  if (parser.allowNaN) {
601
575
  result = getConstant(CONST_INFINITY);
@@ -605,9 +579,9 @@ case 1:
605
579
  }
606
580
  break;
607
581
  case 5:
608
- // line 396 "Parser.rl"
582
+ // line 370 "Parser.rl"
609
583
  {
610
- if (pe > p + 9 - (parser.quirksMode ? 1 : 0) &&
584
+ if (pe > p + 8 &&
611
585
  absSubSequence(p, p + 9).equals(JSON_MINUS_INFINITY)) {
612
586
 
613
587
  if (parser.allowNaN) {
@@ -634,7 +608,7 @@ case 1:
634
608
  }
635
609
  break;
636
610
  case 6:
637
- // line 422 "Parser.rl"
611
+ // line 396 "Parser.rl"
638
612
  {
639
613
  parseString(res, p, pe);
640
614
  if (res.result == null) {
@@ -647,7 +621,7 @@ case 1:
647
621
  }
648
622
  break;
649
623
  case 7:
650
- // line 432 "Parser.rl"
624
+ // line 406 "Parser.rl"
651
625
  {
652
626
  currentNesting++;
653
627
  parseArray(res, p, pe);
@@ -662,7 +636,7 @@ case 1:
662
636
  }
663
637
  break;
664
638
  case 8:
665
- // line 444 "Parser.rl"
639
+ // line 418 "Parser.rl"
666
640
  {
667
641
  currentNesting++;
668
642
  parseObject(res, p, pe);
@@ -676,7 +650,7 @@ case 1:
676
650
  }
677
651
  }
678
652
  break;
679
- // line 680 "Parser.java"
653
+ // line 654 "Parser.java"
680
654
  }
681
655
  }
682
656
  }
@@ -696,7 +670,7 @@ case 5:
696
670
  break; }
697
671
  }
698
672
 
699
- // line 479 "Parser.rl"
673
+ // line 453 "Parser.rl"
700
674
 
701
675
  if (cs >= JSON_value_first_final && result != null) {
702
676
  res.update(result, p);
@@ -706,7 +680,7 @@ case 5:
706
680
  }
707
681
 
708
682
 
709
- // line 710 "Parser.java"
683
+ // line 684 "Parser.java"
710
684
  private static byte[] init__JSON_integer_actions_0()
711
685
  {
712
686
  return new byte [] {
@@ -805,7 +779,7 @@ static final int JSON_integer_error = 0;
805
779
  static final int JSON_integer_en_main = 1;
806
780
 
807
781
 
808
- // line 498 "Parser.rl"
782
+ // line 472 "Parser.rl"
809
783
 
810
784
 
811
785
  void parseInteger(ParserResult res, int p, int pe) {
@@ -823,15 +797,15 @@ static final int JSON_integer_en_main = 1;
823
797
  int cs = EVIL;
824
798
 
825
799
 
826
- // line 827 "Parser.java"
800
+ // line 801 "Parser.java"
827
801
  {
828
802
  cs = JSON_integer_start;
829
803
  }
830
804
 
831
- // line 515 "Parser.rl"
805
+ // line 489 "Parser.rl"
832
806
  int memo = p;
833
807
 
834
- // line 835 "Parser.java"
808
+ // line 809 "Parser.java"
835
809
  {
836
810
  int _klen;
837
811
  int _trans = 0;
@@ -912,13 +886,13 @@ case 1:
912
886
  switch ( _JSON_integer_actions[_acts++] )
913
887
  {
914
888
  case 0:
915
- // line 492 "Parser.rl"
889
+ // line 466 "Parser.rl"
916
890
  {
917
891
  p--;
918
892
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
919
893
  }
920
894
  break;
921
- // line 922 "Parser.java"
895
+ // line 896 "Parser.java"
922
896
  }
923
897
  }
924
898
  }
@@ -938,7 +912,7 @@ case 5:
938
912
  break; }
939
913
  }
940
914
 
941
- // line 517 "Parser.rl"
915
+ // line 491 "Parser.rl"
942
916
 
943
917
  if (cs < JSON_integer_first_final) {
944
918
  return -1;
@@ -946,13 +920,13 @@ case 5:
946
920
 
947
921
  return p;
948
922
  }
949
-
923
+
950
924
  RubyInteger createInteger(int p, int new_p) {
951
925
  Ruby runtime = getRuntime();
952
926
  ByteList num = absSubSequence(p, new_p);
953
927
  return bytesToInum(runtime, num);
954
928
  }
955
-
929
+
956
930
  RubyInteger bytesToInum(Ruby runtime, ByteList num) {
957
931
  return runtime.is1_9() ?
958
932
  ConvertBytes.byteListToInum19(runtime, num, 10, true) :
@@ -960,7 +934,7 @@ case 5:
960
934
  }
961
935
 
962
936
 
963
- // line 964 "Parser.java"
937
+ // line 938 "Parser.java"
964
938
  private static byte[] init__JSON_float_actions_0()
965
939
  {
966
940
  return new byte [] {
@@ -1062,7 +1036,7 @@ static final int JSON_float_error = 0;
1062
1036
  static final int JSON_float_en_main = 1;
1063
1037
 
1064
1038
 
1065
- // line 552 "Parser.rl"
1039
+ // line 526 "Parser.rl"
1066
1040
 
1067
1041
 
1068
1042
  void parseFloat(ParserResult res, int p, int pe) {
@@ -1071,7 +1045,9 @@ static final int JSON_float_en_main = 1;
1071
1045
  res.update(null, p);
1072
1046
  return;
1073
1047
  }
1074
- RubyFloat number = createFloat(p, new_p);
1048
+ IRubyObject number = parser.decimalClass == null ?
1049
+ createFloat(p, new_p) : createCustomDecimal(p, new_p);
1050
+
1075
1051
  res.update(number, new_p + 1);
1076
1052
  return;
1077
1053
  }
@@ -1080,15 +1056,15 @@ static final int JSON_float_en_main = 1;
1080
1056
  int cs = EVIL;
1081
1057
 
1082
1058
 
1083
- // line 1084 "Parser.java"
1059
+ // line 1060 "Parser.java"
1084
1060
  {
1085
1061
  cs = JSON_float_start;
1086
1062
  }
1087
1063
 
1088
- // line 569 "Parser.rl"
1064
+ // line 545 "Parser.rl"
1089
1065
  int memo = p;
1090
1066
 
1091
- // line 1092 "Parser.java"
1067
+ // line 1068 "Parser.java"
1092
1068
  {
1093
1069
  int _klen;
1094
1070
  int _trans = 0;
@@ -1169,13 +1145,13 @@ case 1:
1169
1145
  switch ( _JSON_float_actions[_acts++] )
1170
1146
  {
1171
1147
  case 0:
1172
- // line 543 "Parser.rl"
1148
+ // line 517 "Parser.rl"
1173
1149
  {
1174
1150
  p--;
1175
1151
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
1176
1152
  }
1177
1153
  break;
1178
- // line 1179 "Parser.java"
1154
+ // line 1155 "Parser.java"
1179
1155
  }
1180
1156
  }
1181
1157
  }
@@ -1195,23 +1171,30 @@ case 5:
1195
1171
  break; }
1196
1172
  }
1197
1173
 
1198
- // line 571 "Parser.rl"
1174
+ // line 547 "Parser.rl"
1199
1175
 
1200
1176
  if (cs < JSON_float_first_final) {
1201
1177
  return -1;
1202
1178
  }
1203
-
1179
+
1204
1180
  return p;
1205
1181
  }
1206
-
1182
+
1207
1183
  RubyFloat createFloat(int p, int new_p) {
1208
1184
  Ruby runtime = getRuntime();
1209
1185
  ByteList num = absSubSequence(p, new_p);
1210
1186
  return RubyFloat.newFloat(runtime, dc.parse(num, true, runtime.is1_9()));
1211
1187
  }
1212
1188
 
1189
+ IRubyObject createCustomDecimal(int p, int new_p) {
1190
+ Ruby runtime = getRuntime();
1191
+ ByteList num = absSubSequence(p, new_p);
1192
+ IRubyObject numString = runtime.newString(num.toString());
1193
+ return parser.decimalClass.callMethod(context, "new", numString);
1194
+ }
1195
+
1213
1196
 
1214
- // line 1215 "Parser.java"
1197
+ // line 1198 "Parser.java"
1215
1198
  private static byte[] init__JSON_string_actions_0()
1216
1199
  {
1217
1200
  return new byte [] {
@@ -1313,7 +1296,7 @@ static final int JSON_string_error = 0;
1313
1296
  static final int JSON_string_en_main = 1;
1314
1297
 
1315
1298
 
1316
- // line 616 "Parser.rl"
1299
+ // line 599 "Parser.rl"
1317
1300
 
1318
1301
 
1319
1302
  void parseString(ParserResult res, int p, int pe) {
@@ -1321,15 +1304,15 @@ static final int JSON_string_en_main = 1;
1321
1304
  IRubyObject result = null;
1322
1305
 
1323
1306
 
1324
- // line 1325 "Parser.java"
1307
+ // line 1308 "Parser.java"
1325
1308
  {
1326
1309
  cs = JSON_string_start;
1327
1310
  }
1328
1311
 
1329
- // line 623 "Parser.rl"
1312
+ // line 606 "Parser.rl"
1330
1313
  int memo = p;
1331
1314
 
1332
- // line 1333 "Parser.java"
1315
+ // line 1316 "Parser.java"
1333
1316
  {
1334
1317
  int _klen;
1335
1318
  int _trans = 0;
@@ -1410,7 +1393,7 @@ case 1:
1410
1393
  switch ( _JSON_string_actions[_acts++] )
1411
1394
  {
1412
1395
  case 0:
1413
- // line 591 "Parser.rl"
1396
+ // line 574 "Parser.rl"
1414
1397
  {
1415
1398
  int offset = byteList.begin();
1416
1399
  ByteList decoded = decoder.decode(byteList, memo + 1 - offset,
@@ -1425,13 +1408,13 @@ case 1:
1425
1408
  }
1426
1409
  break;
1427
1410
  case 1:
1428
- // line 604 "Parser.rl"
1411
+ // line 587 "Parser.rl"
1429
1412
  {
1430
1413
  p--;
1431
1414
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
1432
1415
  }
1433
1416
  break;
1434
- // line 1435 "Parser.java"
1417
+ // line 1418 "Parser.java"
1435
1418
  }
1436
1419
  }
1437
1420
  }
@@ -1451,14 +1434,14 @@ case 5:
1451
1434
  break; }
1452
1435
  }
1453
1436
 
1454
- // line 625 "Parser.rl"
1437
+ // line 608 "Parser.rl"
1455
1438
 
1456
1439
  if (parser.createAdditions) {
1457
- RubyHash match_string = parser.match_string;
1458
- if (match_string != null) {
1440
+ RubyHash matchString = parser.matchString;
1441
+ if (matchString != null) {
1459
1442
  final IRubyObject[] memoArray = { result, null };
1460
1443
  try {
1461
- match_string.visitAll(new RubyHash.Visitor() {
1444
+ matchString.visitAll(new RubyHash.Visitor() {
1462
1445
  @Override
1463
1446
  public void visit(IRubyObject pattern, IRubyObject klass) {
1464
1447
  if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) {
@@ -1478,8 +1461,8 @@ case 5:
1478
1461
  }
1479
1462
  }
1480
1463
 
1481
- if (cs >= JSON_string_first_final && result != null) {
1482
- if (info.encodingsSupported() && result instanceof RubyString) {
1464
+ if (cs >= JSON_string_first_final && result != null) {
1465
+ if (result instanceof RubyString) {
1483
1466
  ((RubyString)result).force_encoding(context, info.utf8.get());
1484
1467
  }
1485
1468
  res.update(result, p + 1);
@@ -1489,7 +1472,7 @@ case 5:
1489
1472
  }
1490
1473
 
1491
1474
 
1492
- // line 1493 "Parser.java"
1475
+ // line 1476 "Parser.java"
1493
1476
  private static byte[] init__JSON_array_actions_0()
1494
1477
  {
1495
1478
  return new byte [] {
@@ -1602,7 +1585,7 @@ static final int JSON_array_error = 0;
1602
1585
  static final int JSON_array_en_main = 1;
1603
1586
 
1604
1587
 
1605
- // line 698 "Parser.rl"
1588
+ // line 681 "Parser.rl"
1606
1589
 
1607
1590
 
1608
1591
  void parseArray(ParserResult res, int p, int pe) {
@@ -1622,14 +1605,14 @@ static final int JSON_array_en_main = 1;
1622
1605
  }
1623
1606
 
1624
1607
 
1625
- // line 1626 "Parser.java"
1608
+ // line 1609 "Parser.java"
1626
1609
  {
1627
1610
  cs = JSON_array_start;
1628
1611
  }
1629
1612
 
1630
- // line 717 "Parser.rl"
1613
+ // line 700 "Parser.rl"
1631
1614
 
1632
- // line 1633 "Parser.java"
1615
+ // line 1616 "Parser.java"
1633
1616
  {
1634
1617
  int _klen;
1635
1618
  int _trans = 0;
@@ -1710,7 +1693,7 @@ case 1:
1710
1693
  switch ( _JSON_array_actions[_acts++] )
1711
1694
  {
1712
1695
  case 0:
1713
- // line 667 "Parser.rl"
1696
+ // line 650 "Parser.rl"
1714
1697
  {
1715
1698
  parseValue(res, p, pe);
1716
1699
  if (res.result == null) {
@@ -1727,13 +1710,13 @@ case 1:
1727
1710
  }
1728
1711
  break;
1729
1712
  case 1:
1730
- // line 682 "Parser.rl"
1713
+ // line 665 "Parser.rl"
1731
1714
  {
1732
1715
  p--;
1733
1716
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
1734
1717
  }
1735
1718
  break;
1736
- // line 1737 "Parser.java"
1719
+ // line 1720 "Parser.java"
1737
1720
  }
1738
1721
  }
1739
1722
  }
@@ -1753,7 +1736,7 @@ case 5:
1753
1736
  break; }
1754
1737
  }
1755
1738
 
1756
- // line 718 "Parser.rl"
1739
+ // line 701 "Parser.rl"
1757
1740
 
1758
1741
  if (cs >= JSON_array_first_final) {
1759
1742
  res.update(result, p + 1);
@@ -1763,7 +1746,7 @@ case 5:
1763
1746
  }
1764
1747
 
1765
1748
 
1766
- // line 1767 "Parser.java"
1749
+ // line 1750 "Parser.java"
1767
1750
  private static byte[] init__JSON_object_actions_0()
1768
1751
  {
1769
1752
  return new byte [] {
@@ -1886,7 +1869,7 @@ static final int JSON_object_error = 0;
1886
1869
  static final int JSON_object_en_main = 1;
1887
1870
 
1888
1871
 
1889
- // line 777 "Parser.rl"
1872
+ // line 760 "Parser.rl"
1890
1873
 
1891
1874
 
1892
1875
  void parseObject(ParserResult res, int p, int pe) {
@@ -1911,14 +1894,14 @@ static final int JSON_object_en_main = 1;
1911
1894
  }
1912
1895
 
1913
1896
 
1914
- // line 1915 "Parser.java"
1897
+ // line 1898 "Parser.java"
1915
1898
  {
1916
1899
  cs = JSON_object_start;
1917
1900
  }
1918
1901
 
1919
- // line 801 "Parser.rl"
1902
+ // line 784 "Parser.rl"
1920
1903
 
1921
- // line 1922 "Parser.java"
1904
+ // line 1905 "Parser.java"
1922
1905
  {
1923
1906
  int _klen;
1924
1907
  int _trans = 0;
@@ -1999,7 +1982,7 @@ case 1:
1999
1982
  switch ( _JSON_object_actions[_acts++] )
2000
1983
  {
2001
1984
  case 0:
2002
- // line 732 "Parser.rl"
1985
+ // line 715 "Parser.rl"
2003
1986
  {
2004
1987
  parseValue(res, p, pe);
2005
1988
  if (res.result == null) {
@@ -2016,7 +1999,7 @@ case 1:
2016
1999
  }
2017
2000
  break;
2018
2001
  case 1:
2019
- // line 747 "Parser.rl"
2002
+ // line 730 "Parser.rl"
2020
2003
  {
2021
2004
  parseString(res, p, pe);
2022
2005
  if (res.result == null) {
@@ -2036,13 +2019,13 @@ case 1:
2036
2019
  }
2037
2020
  break;
2038
2021
  case 2:
2039
- // line 765 "Parser.rl"
2022
+ // line 748 "Parser.rl"
2040
2023
  {
2041
2024
  p--;
2042
2025
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
2043
2026
  }
2044
2027
  break;
2045
- // line 2046 "Parser.java"
2028
+ // line 2029 "Parser.java"
2046
2029
  }
2047
2030
  }
2048
2031
  }
@@ -2062,7 +2045,7 @@ case 5:
2062
2045
  break; }
2063
2046
  }
2064
2047
 
2065
- // line 802 "Parser.rl"
2048
+ // line 785 "Parser.rl"
2066
2049
 
2067
2050
  if (cs < JSON_object_first_final) {
2068
2051
  res.update(null, p + 1);
@@ -2095,11 +2078,11 @@ case 5:
2095
2078
  }
2096
2079
 
2097
2080
 
2098
- // line 2099 "Parser.java"
2081
+ // line 2082 "Parser.java"
2099
2082
  private static byte[] init__JSON_actions_0()
2100
2083
  {
2101
2084
  return new byte [] {
2102
- 0, 1, 0, 1, 1
2085
+ 0, 1, 0
2103
2086
  };
2104
2087
  }
2105
2088
 
@@ -2109,7 +2092,7 @@ private static final byte _JSON_actions[] = init__JSON_actions_0();
2109
2092
  private static byte[] init__JSON_key_offsets_0()
2110
2093
  {
2111
2094
  return new byte [] {
2112
- 0, 0, 7, 9, 10, 12, 13, 15, 16, 18, 19
2095
+ 0, 0, 16, 18, 19, 21, 22, 24, 25, 27, 28
2113
2096
  };
2114
2097
  }
2115
2098
 
@@ -2119,9 +2102,9 @@ private static final byte _JSON_key_offsets[] = init__JSON_key_offsets_0();
2119
2102
  private static char[] init__JSON_trans_keys_0()
2120
2103
  {
2121
2104
  return new char [] {
2122
- 13, 32, 47, 91, 123, 9, 10, 42, 47, 42, 42, 47,
2123
- 10, 42, 47, 42, 42, 47, 10, 13, 32, 47, 9, 10,
2124
- 0
2105
+ 13, 32, 34, 45, 47, 73, 78, 91, 102, 110, 116, 123,
2106
+ 9, 10, 48, 57, 42, 47, 42, 42, 47, 10, 42, 47,
2107
+ 42, 42, 47, 10, 13, 32, 47, 9, 10, 0
2125
2108
  };
2126
2109
  }
2127
2110
 
@@ -2131,7 +2114,7 @@ private static final char _JSON_trans_keys[] = init__JSON_trans_keys_0();
2131
2114
  private static byte[] init__JSON_single_lengths_0()
2132
2115
  {
2133
2116
  return new byte [] {
2134
- 0, 5, 2, 1, 2, 1, 2, 1, 2, 1, 3
2117
+ 0, 12, 2, 1, 2, 1, 2, 1, 2, 1, 3
2135
2118
  };
2136
2119
  }
2137
2120
 
@@ -2141,7 +2124,7 @@ private static final byte _JSON_single_lengths[] = init__JSON_single_lengths_0()
2141
2124
  private static byte[] init__JSON_range_lengths_0()
2142
2125
  {
2143
2126
  return new byte [] {
2144
- 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
2127
+ 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1
2145
2128
  };
2146
2129
  }
2147
2130
 
@@ -2151,7 +2134,7 @@ private static final byte _JSON_range_lengths[] = init__JSON_range_lengths_0();
2151
2134
  private static byte[] init__JSON_index_offsets_0()
2152
2135
  {
2153
2136
  return new byte [] {
2154
- 0, 0, 7, 10, 12, 15, 17, 20, 22, 25, 27
2137
+ 0, 0, 15, 18, 20, 23, 25, 28, 30, 33, 35
2155
2138
  };
2156
2139
  }
2157
2140
 
@@ -2161,9 +2144,10 @@ private static final byte _JSON_index_offsets[] = init__JSON_index_offsets_0();
2161
2144
  private static byte[] init__JSON_indicies_0()
2162
2145
  {
2163
2146
  return new byte [] {
2164
- 0, 0, 2, 3, 4, 0, 1, 5, 6, 1, 7, 5,
2165
- 7, 0, 5, 0, 6, 8, 9, 1, 10, 8, 10, 11,
2166
- 8, 11, 9, 11, 11, 12, 11, 1, 0
2147
+ 0, 0, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2,
2148
+ 0, 2, 1, 4, 5, 1, 6, 4, 6, 7, 4, 7,
2149
+ 5, 8, 9, 1, 10, 8, 10, 0, 8, 0, 9, 7,
2150
+ 7, 11, 7, 1, 0
2167
2151
  };
2168
2152
  }
2169
2153
 
@@ -2173,8 +2157,7 @@ private static final byte _JSON_indicies[] = init__JSON_indicies_0();
2173
2157
  private static byte[] init__JSON_trans_targs_0()
2174
2158
  {
2175
2159
  return new byte [] {
2176
- 1, 0, 2, 10, 10, 3, 5, 4, 7, 9, 8, 10,
2177
- 6
2160
+ 1, 0, 10, 6, 3, 5, 4, 10, 7, 9, 8, 2
2178
2161
  };
2179
2162
  }
2180
2163
 
@@ -2184,8 +2167,7 @@ private static final byte _JSON_trans_targs[] = init__JSON_trans_targs_0();
2184
2167
  private static byte[] init__JSON_trans_actions_0()
2185
2168
  {
2186
2169
  return new byte [] {
2187
- 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0,
2188
- 0
2170
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
2189
2171
  };
2190
2172
  }
2191
2173
 
@@ -2199,26 +2181,26 @@ static final int JSON_error = 0;
2199
2181
  static final int JSON_en_main = 1;
2200
2182
 
2201
2183
 
2202
- // line 867 "Parser.rl"
2184
+ // line 836 "Parser.rl"
2203
2185
 
2204
2186
 
2205
- public IRubyObject parseStrict() {
2187
+ public IRubyObject parseImplemetation() {
2206
2188
  int cs = EVIL;
2207
2189
  int p, pe;
2208
2190
  IRubyObject result = null;
2209
2191
  ParserResult res = new ParserResult();
2210
2192
 
2211
2193
 
2212
- // line 2213 "Parser.java"
2194
+ // line 2195 "Parser.java"
2213
2195
  {
2214
2196
  cs = JSON_start;
2215
2197
  }
2216
2198
 
2217
- // line 876 "Parser.rl"
2199
+ // line 845 "Parser.rl"
2218
2200
  p = byteList.begin();
2219
2201
  pe = p + byteList.length();
2220
2202
 
2221
- // line 2222 "Parser.java"
2203
+ // line 2204 "Parser.java"
2222
2204
  {
2223
2205
  int _klen;
2224
2206
  int _trans = 0;
@@ -2299,267 +2281,7 @@ case 1:
2299
2281
  switch ( _JSON_actions[_acts++] )
2300
2282
  {
2301
2283
  case 0:
2302
- // line 839 "Parser.rl"
2303
- {
2304
- currentNesting = 1;
2305
- parseObject(res, p, pe);
2306
- if (res.result == null) {
2307
- p--;
2308
- { p += 1; _goto_targ = 5; if (true) continue _goto;}
2309
- } else {
2310
- result = res.result;
2311
- {p = (( res.p))-1;}
2312
- }
2313
- }
2314
- break;
2315
- case 1:
2316
- // line 851 "Parser.rl"
2317
- {
2318
- currentNesting = 1;
2319
- parseArray(res, p, pe);
2320
- if (res.result == null) {
2321
- p--;
2322
- { p += 1; _goto_targ = 5; if (true) continue _goto;}
2323
- } else {
2324
- result = res.result;
2325
- {p = (( res.p))-1;}
2326
- }
2327
- }
2328
- break;
2329
- // line 2330 "Parser.java"
2330
- }
2331
- }
2332
- }
2333
-
2334
- case 2:
2335
- if ( cs == 0 ) {
2336
- _goto_targ = 5;
2337
- continue _goto;
2338
- }
2339
- if ( ++p != pe ) {
2340
- _goto_targ = 1;
2341
- continue _goto;
2342
- }
2343
- case 4:
2344
- case 5:
2345
- }
2346
- break; }
2347
- }
2348
-
2349
- // line 879 "Parser.rl"
2350
-
2351
- if (cs >= JSON_first_final && p == pe) {
2352
- return result;
2353
- } else {
2354
- throw unexpectedToken(p, pe);
2355
- }
2356
- }
2357
-
2358
-
2359
- // line 2360 "Parser.java"
2360
- private static byte[] init__JSON_quirks_mode_actions_0()
2361
- {
2362
- return new byte [] {
2363
- 0, 1, 0
2364
- };
2365
- }
2366
-
2367
- private static final byte _JSON_quirks_mode_actions[] = init__JSON_quirks_mode_actions_0();
2368
-
2369
-
2370
- private static byte[] init__JSON_quirks_mode_key_offsets_0()
2371
- {
2372
- return new byte [] {
2373
- 0, 0, 16, 18, 19, 21, 22, 24, 25, 27, 28
2374
- };
2375
- }
2376
-
2377
- private static final byte _JSON_quirks_mode_key_offsets[] = init__JSON_quirks_mode_key_offsets_0();
2378
-
2379
-
2380
- private static char[] init__JSON_quirks_mode_trans_keys_0()
2381
- {
2382
- return new char [] {
2383
- 13, 32, 34, 45, 47, 73, 78, 91, 102, 110, 116, 123,
2384
- 9, 10, 48, 57, 42, 47, 42, 42, 47, 10, 42, 47,
2385
- 42, 42, 47, 10, 13, 32, 47, 9, 10, 0
2386
- };
2387
- }
2388
-
2389
- private static final char _JSON_quirks_mode_trans_keys[] = init__JSON_quirks_mode_trans_keys_0();
2390
-
2391
-
2392
- private static byte[] init__JSON_quirks_mode_single_lengths_0()
2393
- {
2394
- return new byte [] {
2395
- 0, 12, 2, 1, 2, 1, 2, 1, 2, 1, 3
2396
- };
2397
- }
2398
-
2399
- private static final byte _JSON_quirks_mode_single_lengths[] = init__JSON_quirks_mode_single_lengths_0();
2400
-
2401
-
2402
- private static byte[] init__JSON_quirks_mode_range_lengths_0()
2403
- {
2404
- return new byte [] {
2405
- 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1
2406
- };
2407
- }
2408
-
2409
- private static final byte _JSON_quirks_mode_range_lengths[] = init__JSON_quirks_mode_range_lengths_0();
2410
-
2411
-
2412
- private static byte[] init__JSON_quirks_mode_index_offsets_0()
2413
- {
2414
- return new byte [] {
2415
- 0, 0, 15, 18, 20, 23, 25, 28, 30, 33, 35
2416
- };
2417
- }
2418
-
2419
- private static final byte _JSON_quirks_mode_index_offsets[] = init__JSON_quirks_mode_index_offsets_0();
2420
-
2421
-
2422
- private static byte[] init__JSON_quirks_mode_indicies_0()
2423
- {
2424
- return new byte [] {
2425
- 0, 0, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2,
2426
- 0, 2, 1, 4, 5, 1, 6, 4, 6, 7, 4, 7,
2427
- 5, 8, 9, 1, 10, 8, 10, 0, 8, 0, 9, 7,
2428
- 7, 11, 7, 1, 0
2429
- };
2430
- }
2431
-
2432
- private static final byte _JSON_quirks_mode_indicies[] = init__JSON_quirks_mode_indicies_0();
2433
-
2434
-
2435
- private static byte[] init__JSON_quirks_mode_trans_targs_0()
2436
- {
2437
- return new byte [] {
2438
- 1, 0, 10, 6, 3, 5, 4, 10, 7, 9, 8, 2
2439
- };
2440
- }
2441
-
2442
- private static final byte _JSON_quirks_mode_trans_targs[] = init__JSON_quirks_mode_trans_targs_0();
2443
-
2444
-
2445
- private static byte[] init__JSON_quirks_mode_trans_actions_0()
2446
- {
2447
- return new byte [] {
2448
- 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
2449
- };
2450
- }
2451
-
2452
- private static final byte _JSON_quirks_mode_trans_actions[] = init__JSON_quirks_mode_trans_actions_0();
2453
-
2454
-
2455
- static final int JSON_quirks_mode_start = 1;
2456
- static final int JSON_quirks_mode_first_final = 10;
2457
- static final int JSON_quirks_mode_error = 0;
2458
-
2459
- static final int JSON_quirks_mode_en_main = 1;
2460
-
2461
-
2462
- // line 907 "Parser.rl"
2463
-
2464
-
2465
- public IRubyObject parseQuirksMode() {
2466
- int cs = EVIL;
2467
- int p, pe;
2468
- IRubyObject result = null;
2469
- ParserResult res = new ParserResult();
2470
-
2471
-
2472
- // line 2473 "Parser.java"
2473
- {
2474
- cs = JSON_quirks_mode_start;
2475
- }
2476
-
2477
- // line 916 "Parser.rl"
2478
- p = byteList.begin();
2479
- pe = p + byteList.length();
2480
-
2481
- // line 2482 "Parser.java"
2482
- {
2483
- int _klen;
2484
- int _trans = 0;
2485
- int _acts;
2486
- int _nacts;
2487
- int _keys;
2488
- int _goto_targ = 0;
2489
-
2490
- _goto: while (true) {
2491
- switch ( _goto_targ ) {
2492
- case 0:
2493
- if ( p == pe ) {
2494
- _goto_targ = 4;
2495
- continue _goto;
2496
- }
2497
- if ( cs == 0 ) {
2498
- _goto_targ = 5;
2499
- continue _goto;
2500
- }
2501
- case 1:
2502
- _match: do {
2503
- _keys = _JSON_quirks_mode_key_offsets[cs];
2504
- _trans = _JSON_quirks_mode_index_offsets[cs];
2505
- _klen = _JSON_quirks_mode_single_lengths[cs];
2506
- if ( _klen > 0 ) {
2507
- int _lower = _keys;
2508
- int _mid;
2509
- int _upper = _keys + _klen - 1;
2510
- while (true) {
2511
- if ( _upper < _lower )
2512
- break;
2513
-
2514
- _mid = _lower + ((_upper-_lower) >> 1);
2515
- if ( data[p] < _JSON_quirks_mode_trans_keys[_mid] )
2516
- _upper = _mid - 1;
2517
- else if ( data[p] > _JSON_quirks_mode_trans_keys[_mid] )
2518
- _lower = _mid + 1;
2519
- else {
2520
- _trans += (_mid - _keys);
2521
- break _match;
2522
- }
2523
- }
2524
- _keys += _klen;
2525
- _trans += _klen;
2526
- }
2527
-
2528
- _klen = _JSON_quirks_mode_range_lengths[cs];
2529
- if ( _klen > 0 ) {
2530
- int _lower = _keys;
2531
- int _mid;
2532
- int _upper = _keys + (_klen<<1) - 2;
2533
- while (true) {
2534
- if ( _upper < _lower )
2535
- break;
2536
-
2537
- _mid = _lower + (((_upper-_lower) >> 1) & ~1);
2538
- if ( data[p] < _JSON_quirks_mode_trans_keys[_mid] )
2539
- _upper = _mid - 2;
2540
- else if ( data[p] > _JSON_quirks_mode_trans_keys[_mid+1] )
2541
- _lower = _mid + 2;
2542
- else {
2543
- _trans += ((_mid - _keys)>>1);
2544
- break _match;
2545
- }
2546
- }
2547
- _trans += _klen;
2548
- }
2549
- } while (false);
2550
-
2551
- _trans = _JSON_quirks_mode_indicies[_trans];
2552
- cs = _JSON_quirks_mode_trans_targs[_trans];
2553
-
2554
- if ( _JSON_quirks_mode_trans_actions[_trans] != 0 ) {
2555
- _acts = _JSON_quirks_mode_trans_actions[_trans];
2556
- _nacts = (int) _JSON_quirks_mode_actions[_acts++];
2557
- while ( _nacts-- > 0 )
2558
- {
2559
- switch ( _JSON_quirks_mode_actions[_acts++] )
2560
- {
2561
- case 0:
2562
- // line 893 "Parser.rl"
2284
+ // line 822 "Parser.rl"
2563
2285
  {
2564
2286
  parseValue(res, p, pe);
2565
2287
  if (res.result == null) {
@@ -2571,7 +2293,7 @@ case 1:
2571
2293
  }
2572
2294
  }
2573
2295
  break;
2574
- // line 2575 "Parser.java"
2296
+ // line 2297 "Parser.java"
2575
2297
  }
2576
2298
  }
2577
2299
  }
@@ -2591,9 +2313,9 @@ case 5:
2591
2313
  break; }
2592
2314
  }
2593
2315
 
2594
- // line 919 "Parser.rl"
2316
+ // line 848 "Parser.rl"
2595
2317
 
2596
- if (cs >= JSON_quirks_mode_first_final && p == pe) {
2318
+ if (cs >= JSON_first_final && p == pe) {
2597
2319
  return result;
2598
2320
  } else {
2599
2321
  throw unexpectedToken(p, pe);
@@ -2601,12 +2323,7 @@ case 5:
2601
2323
  }
2602
2324
 
2603
2325
  public IRubyObject parse() {
2604
- if (parser.quirksMode) {
2605
- return parseQuirksMode();
2606
- } else {
2607
- return parseStrict();
2608
- }
2609
-
2326
+ return parseImplemetation();
2610
2327
  }
2611
2328
 
2612
2329
  /**