json 2.0.4 → 2.3.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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +9 -4
- data/CHANGES.md +6 -0
- data/Gemfile +1 -3
- data/LICENSE +56 -0
- data/README.md +38 -21
- data/Rakefile +12 -7
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +96 -40
- data/ext/json/ext/parser/parser.c +124 -80
- data/ext/json/ext/parser/parser.h +1 -0
- data/ext/json/ext/parser/parser.rl +51 -7
- data/java/src/json/ext/Generator.java +33 -10
- data/java/src/json/ext/Parser.java +95 -80
- data/java/src/json/ext/Parser.rl +25 -10
- data/json-java.gemspec +1 -2
- data/json.gemspec +0 -0
- data/json_pure.gemspec +5 -5
- data/lib/json/add/bigdecimal.rb +2 -2
- data/lib/json/add/complex.rb +2 -2
- data/lib/json/add/ostruct.rb +1 -1
- data/lib/json/add/rational.rb +2 -2
- data/lib/json/add/regexp.rb +2 -2
- data/lib/json/add/set.rb +29 -0
- data/lib/json/common.rb +2 -2
- data/lib/json/pure/generator.rb +2 -1
- data/lib/json/pure/parser.rb +13 -1
- data/lib/json/version.rb +1 -1
- data/tests/json_addition_test.rb +10 -0
- data/tests/json_common_interface_test.rb +4 -4
- data/tests/json_encoding_test.rb +2 -2
- data/tests/json_generator_test.rb +44 -0
- data/tests/json_parser_test.rb +18 -12
- data/tests/test_helper.rb +0 -4
- metadata +5 -7
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
|
@@ -27,7 +27,7 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
|
|
27
27
|
|
|
28
28
|
/* unicode */
|
|
29
29
|
|
|
30
|
-
static const char digit_values[256] = {
|
|
30
|
+
static const signed char digit_values[256] = {
|
|
31
31
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
32
32
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
33
33
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
|
@@ -46,7 +46,7 @@ static const char digit_values[256] = {
|
|
|
46
46
|
|
|
47
47
|
static UTF32 unescape_unicode(const unsigned char *p)
|
|
48
48
|
{
|
|
49
|
-
char b;
|
|
49
|
+
signed char b;
|
|
50
50
|
UTF32 result = 0;
|
|
51
51
|
b = digit_values[p[0]];
|
|
52
52
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
|
@@ -91,18 +91,20 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
|
|
|
91
91
|
|
|
92
92
|
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
|
|
93
93
|
static VALUE CNaN, CInfinity, CMinusInfinity;
|
|
94
|
+
static VALUE cBigDecimal = Qundef;
|
|
94
95
|
|
|
95
96
|
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
|
96
97
|
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
|
|
97
|
-
i_object_class, i_array_class,
|
|
98
|
-
i_match_string, i_aset, i_aref,
|
|
98
|
+
i_object_class, i_array_class, i_decimal_class, i_key_p,
|
|
99
|
+
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
|
|
100
|
+
i_leftshift, i_new, i_BigDecimal;
|
|
99
101
|
|
|
100
102
|
|
|
101
|
-
#line
|
|
103
|
+
#line 126 "parser.rl"
|
|
102
104
|
|
|
103
105
|
|
|
104
106
|
|
|
105
|
-
#line
|
|
107
|
+
#line 108 "parser.c"
|
|
106
108
|
enum {JSON_object_start = 1};
|
|
107
109
|
enum {JSON_object_first_final = 27};
|
|
108
110
|
enum {JSON_object_error = 0};
|
|
@@ -110,7 +112,7 @@ enum {JSON_object_error = 0};
|
|
|
110
112
|
enum {JSON_object_en_main = 1};
|
|
111
113
|
|
|
112
114
|
|
|
113
|
-
#line
|
|
115
|
+
#line 167 "parser.rl"
|
|
114
116
|
|
|
115
117
|
|
|
116
118
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
|
@@ -126,14 +128,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
|
126
128
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
|
127
129
|
|
|
128
130
|
|
|
129
|
-
#line
|
|
131
|
+
#line 132 "parser.c"
|
|
130
132
|
{
|
|
131
133
|
cs = JSON_object_start;
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
#line
|
|
136
|
+
#line 182 "parser.rl"
|
|
135
137
|
|
|
136
|
-
#line
|
|
138
|
+
#line 139 "parser.c"
|
|
137
139
|
{
|
|
138
140
|
if ( p == pe )
|
|
139
141
|
goto _test_eof;
|
|
@@ -161,7 +163,7 @@ case 2:
|
|
|
161
163
|
goto st2;
|
|
162
164
|
goto st0;
|
|
163
165
|
tr2:
|
|
164
|
-
#line
|
|
166
|
+
#line 149 "parser.rl"
|
|
165
167
|
{
|
|
166
168
|
char *np;
|
|
167
169
|
json->parsing_name = 1;
|
|
@@ -174,7 +176,7 @@ st3:
|
|
|
174
176
|
if ( ++p == pe )
|
|
175
177
|
goto _test_eof3;
|
|
176
178
|
case 3:
|
|
177
|
-
#line
|
|
179
|
+
#line 180 "parser.c"
|
|
178
180
|
switch( (*p) ) {
|
|
179
181
|
case 13: goto st3;
|
|
180
182
|
case 32: goto st3;
|
|
@@ -241,7 +243,7 @@ case 8:
|
|
|
241
243
|
goto st8;
|
|
242
244
|
goto st0;
|
|
243
245
|
tr11:
|
|
244
|
-
#line
|
|
246
|
+
#line 134 "parser.rl"
|
|
245
247
|
{
|
|
246
248
|
VALUE v = Qnil;
|
|
247
249
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
|
@@ -261,7 +263,7 @@ st9:
|
|
|
261
263
|
if ( ++p == pe )
|
|
262
264
|
goto _test_eof9;
|
|
263
265
|
case 9:
|
|
264
|
-
#line
|
|
266
|
+
#line 267 "parser.c"
|
|
265
267
|
switch( (*p) ) {
|
|
266
268
|
case 13: goto st9;
|
|
267
269
|
case 32: goto st9;
|
|
@@ -350,14 +352,14 @@ case 18:
|
|
|
350
352
|
goto st9;
|
|
351
353
|
goto st18;
|
|
352
354
|
tr4:
|
|
353
|
-
#line
|
|
355
|
+
#line 157 "parser.rl"
|
|
354
356
|
{ p--; {p++; cs = 27; goto _out;} }
|
|
355
357
|
goto st27;
|
|
356
358
|
st27:
|
|
357
359
|
if ( ++p == pe )
|
|
358
360
|
goto _test_eof27;
|
|
359
361
|
case 27:
|
|
360
|
-
#line
|
|
362
|
+
#line 363 "parser.c"
|
|
361
363
|
goto st0;
|
|
362
364
|
st19:
|
|
363
365
|
if ( ++p == pe )
|
|
@@ -455,7 +457,7 @@ case 26:
|
|
|
455
457
|
_out: {}
|
|
456
458
|
}
|
|
457
459
|
|
|
458
|
-
#line
|
|
460
|
+
#line 183 "parser.rl"
|
|
459
461
|
|
|
460
462
|
if (cs >= JSON_object_first_final) {
|
|
461
463
|
if (json->create_additions) {
|
|
@@ -480,7 +482,7 @@ case 26:
|
|
|
480
482
|
|
|
481
483
|
|
|
482
484
|
|
|
483
|
-
#line
|
|
485
|
+
#line 486 "parser.c"
|
|
484
486
|
enum {JSON_value_start = 1};
|
|
485
487
|
enum {JSON_value_first_final = 29};
|
|
486
488
|
enum {JSON_value_error = 0};
|
|
@@ -488,7 +490,7 @@ enum {JSON_value_error = 0};
|
|
|
488
490
|
enum {JSON_value_en_main = 1};
|
|
489
491
|
|
|
490
492
|
|
|
491
|
-
#line
|
|
493
|
+
#line 283 "parser.rl"
|
|
492
494
|
|
|
493
495
|
|
|
494
496
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
|
@@ -496,14 +498,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
|
496
498
|
int cs = EVIL;
|
|
497
499
|
|
|
498
500
|
|
|
499
|
-
#line
|
|
501
|
+
#line 502 "parser.c"
|
|
500
502
|
{
|
|
501
503
|
cs = JSON_value_start;
|
|
502
504
|
}
|
|
503
505
|
|
|
504
|
-
#line
|
|
506
|
+
#line 290 "parser.rl"
|
|
505
507
|
|
|
506
|
-
#line
|
|
508
|
+
#line 509 "parser.c"
|
|
507
509
|
{
|
|
508
510
|
if ( p == pe )
|
|
509
511
|
goto _test_eof;
|
|
@@ -537,14 +539,14 @@ st0:
|
|
|
537
539
|
cs = 0;
|
|
538
540
|
goto _out;
|
|
539
541
|
tr2:
|
|
540
|
-
#line
|
|
542
|
+
#line 235 "parser.rl"
|
|
541
543
|
{
|
|
542
544
|
char *np = JSON_parse_string(json, p, pe, result);
|
|
543
545
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
|
544
546
|
}
|
|
545
547
|
goto st29;
|
|
546
548
|
tr3:
|
|
547
|
-
#line
|
|
549
|
+
#line 240 "parser.rl"
|
|
548
550
|
{
|
|
549
551
|
char *np;
|
|
550
552
|
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
|
|
@@ -564,7 +566,7 @@ tr3:
|
|
|
564
566
|
}
|
|
565
567
|
goto st29;
|
|
566
568
|
tr7:
|
|
567
|
-
#line
|
|
569
|
+
#line 258 "parser.rl"
|
|
568
570
|
{
|
|
569
571
|
char *np;
|
|
570
572
|
np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
|
|
@@ -572,7 +574,7 @@ tr7:
|
|
|
572
574
|
}
|
|
573
575
|
goto st29;
|
|
574
576
|
tr11:
|
|
575
|
-
#line
|
|
577
|
+
#line 264 "parser.rl"
|
|
576
578
|
{
|
|
577
579
|
char *np;
|
|
578
580
|
np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
|
|
@@ -580,7 +582,7 @@ tr11:
|
|
|
580
582
|
}
|
|
581
583
|
goto st29;
|
|
582
584
|
tr25:
|
|
583
|
-
#line
|
|
585
|
+
#line 228 "parser.rl"
|
|
584
586
|
{
|
|
585
587
|
if (json->allow_nan) {
|
|
586
588
|
*result = CInfinity;
|
|
@@ -590,7 +592,7 @@ tr25:
|
|
|
590
592
|
}
|
|
591
593
|
goto st29;
|
|
592
594
|
tr27:
|
|
593
|
-
#line
|
|
595
|
+
#line 221 "parser.rl"
|
|
594
596
|
{
|
|
595
597
|
if (json->allow_nan) {
|
|
596
598
|
*result = CNaN;
|
|
@@ -600,19 +602,19 @@ tr27:
|
|
|
600
602
|
}
|
|
601
603
|
goto st29;
|
|
602
604
|
tr31:
|
|
603
|
-
#line
|
|
605
|
+
#line 215 "parser.rl"
|
|
604
606
|
{
|
|
605
607
|
*result = Qfalse;
|
|
606
608
|
}
|
|
607
609
|
goto st29;
|
|
608
610
|
tr34:
|
|
609
|
-
#line
|
|
611
|
+
#line 212 "parser.rl"
|
|
610
612
|
{
|
|
611
613
|
*result = Qnil;
|
|
612
614
|
}
|
|
613
615
|
goto st29;
|
|
614
616
|
tr37:
|
|
615
|
-
#line
|
|
617
|
+
#line 218 "parser.rl"
|
|
616
618
|
{
|
|
617
619
|
*result = Qtrue;
|
|
618
620
|
}
|
|
@@ -621,9 +623,9 @@ st29:
|
|
|
621
623
|
if ( ++p == pe )
|
|
622
624
|
goto _test_eof29;
|
|
623
625
|
case 29:
|
|
624
|
-
#line
|
|
626
|
+
#line 270 "parser.rl"
|
|
625
627
|
{ p--; {p++; cs = 29; goto _out;} }
|
|
626
|
-
#line
|
|
628
|
+
#line 629 "parser.c"
|
|
627
629
|
switch( (*p) ) {
|
|
628
630
|
case 13: goto st29;
|
|
629
631
|
case 32: goto st29;
|
|
@@ -864,7 +866,7 @@ case 28:
|
|
|
864
866
|
_out: {}
|
|
865
867
|
}
|
|
866
868
|
|
|
867
|
-
#line
|
|
869
|
+
#line 291 "parser.rl"
|
|
868
870
|
|
|
869
871
|
if (cs >= JSON_value_first_final) {
|
|
870
872
|
return p;
|
|
@@ -874,7 +876,7 @@ case 28:
|
|
|
874
876
|
}
|
|
875
877
|
|
|
876
878
|
|
|
877
|
-
#line
|
|
879
|
+
#line 880 "parser.c"
|
|
878
880
|
enum {JSON_integer_start = 1};
|
|
879
881
|
enum {JSON_integer_first_final = 3};
|
|
880
882
|
enum {JSON_integer_error = 0};
|
|
@@ -882,7 +884,7 @@ enum {JSON_integer_error = 0};
|
|
|
882
884
|
enum {JSON_integer_en_main = 1};
|
|
883
885
|
|
|
884
886
|
|
|
885
|
-
#line
|
|
887
|
+
#line 307 "parser.rl"
|
|
886
888
|
|
|
887
889
|
|
|
888
890
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
|
@@ -890,15 +892,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
|
890
892
|
int cs = EVIL;
|
|
891
893
|
|
|
892
894
|
|
|
893
|
-
#line
|
|
895
|
+
#line 896 "parser.c"
|
|
894
896
|
{
|
|
895
897
|
cs = JSON_integer_start;
|
|
896
898
|
}
|
|
897
899
|
|
|
898
|
-
#line
|
|
900
|
+
#line 314 "parser.rl"
|
|
899
901
|
json->memo = p;
|
|
900
902
|
|
|
901
|
-
#line
|
|
903
|
+
#line 904 "parser.c"
|
|
902
904
|
{
|
|
903
905
|
if ( p == pe )
|
|
904
906
|
goto _test_eof;
|
|
@@ -932,14 +934,14 @@ case 3:
|
|
|
932
934
|
goto st0;
|
|
933
935
|
goto tr4;
|
|
934
936
|
tr4:
|
|
935
|
-
#line
|
|
937
|
+
#line 304 "parser.rl"
|
|
936
938
|
{ p--; {p++; cs = 4; goto _out;} }
|
|
937
939
|
goto st4;
|
|
938
940
|
st4:
|
|
939
941
|
if ( ++p == pe )
|
|
940
942
|
goto _test_eof4;
|
|
941
943
|
case 4:
|
|
942
|
-
#line
|
|
944
|
+
#line 945 "parser.c"
|
|
943
945
|
goto st0;
|
|
944
946
|
st5:
|
|
945
947
|
if ( ++p == pe )
|
|
@@ -958,7 +960,7 @@ case 5:
|
|
|
958
960
|
_out: {}
|
|
959
961
|
}
|
|
960
962
|
|
|
961
|
-
#line
|
|
963
|
+
#line 316 "parser.rl"
|
|
962
964
|
|
|
963
965
|
if (cs >= JSON_integer_first_final) {
|
|
964
966
|
long len = p - json->memo;
|
|
@@ -973,7 +975,7 @@ case 5:
|
|
|
973
975
|
}
|
|
974
976
|
|
|
975
977
|
|
|
976
|
-
#line
|
|
978
|
+
#line 979 "parser.c"
|
|
977
979
|
enum {JSON_float_start = 1};
|
|
978
980
|
enum {JSON_float_first_final = 8};
|
|
979
981
|
enum {JSON_float_error = 0};
|
|
@@ -981,23 +983,36 @@ enum {JSON_float_error = 0};
|
|
|
981
983
|
enum {JSON_float_en_main = 1};
|
|
982
984
|
|
|
983
985
|
|
|
984
|
-
#line
|
|
986
|
+
#line 341 "parser.rl"
|
|
985
987
|
|
|
986
988
|
|
|
989
|
+
static int is_bigdecimal_class(VALUE obj)
|
|
990
|
+
{
|
|
991
|
+
if (cBigDecimal == Qundef) {
|
|
992
|
+
if (rb_const_defined(rb_cObject, i_BigDecimal)) {
|
|
993
|
+
cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal);
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
return 0;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return obj == cBigDecimal;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
987
1002
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
|
988
1003
|
{
|
|
989
1004
|
int cs = EVIL;
|
|
990
1005
|
|
|
991
1006
|
|
|
992
|
-
#line
|
|
1007
|
+
#line 1008 "parser.c"
|
|
993
1008
|
{
|
|
994
1009
|
cs = JSON_float_start;
|
|
995
1010
|
}
|
|
996
1011
|
|
|
997
|
-
#line
|
|
1012
|
+
#line 361 "parser.rl"
|
|
998
1013
|
json->memo = p;
|
|
999
1014
|
|
|
1000
|
-
#line
|
|
1015
|
+
#line 1016 "parser.c"
|
|
1001
1016
|
{
|
|
1002
1017
|
if ( p == pe )
|
|
1003
1018
|
goto _test_eof;
|
|
@@ -1055,14 +1070,14 @@ case 8:
|
|
|
1055
1070
|
goto st0;
|
|
1056
1071
|
goto tr9;
|
|
1057
1072
|
tr9:
|
|
1058
|
-
#line
|
|
1073
|
+
#line 335 "parser.rl"
|
|
1059
1074
|
{ p--; {p++; cs = 9; goto _out;} }
|
|
1060
1075
|
goto st9;
|
|
1061
1076
|
st9:
|
|
1062
1077
|
if ( ++p == pe )
|
|
1063
1078
|
goto _test_eof9;
|
|
1064
1079
|
case 9:
|
|
1065
|
-
#line
|
|
1080
|
+
#line 1081 "parser.c"
|
|
1066
1081
|
goto st0;
|
|
1067
1082
|
st5:
|
|
1068
1083
|
if ( ++p == pe )
|
|
@@ -1123,14 +1138,24 @@ case 7:
|
|
|
1123
1138
|
_out: {}
|
|
1124
1139
|
}
|
|
1125
1140
|
|
|
1126
|
-
#line
|
|
1141
|
+
#line 363 "parser.rl"
|
|
1127
1142
|
|
|
1128
1143
|
if (cs >= JSON_float_first_final) {
|
|
1129
1144
|
long len = p - json->memo;
|
|
1130
1145
|
fbuffer_clear(json->fbuffer);
|
|
1131
1146
|
fbuffer_append(json->fbuffer, json->memo, len);
|
|
1132
1147
|
fbuffer_append_char(json->fbuffer, '\0');
|
|
1133
|
-
|
|
1148
|
+
if (NIL_P(json->decimal_class)) {
|
|
1149
|
+
*result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
|
|
1150
|
+
} else {
|
|
1151
|
+
VALUE text;
|
|
1152
|
+
text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
|
|
1153
|
+
if (is_bigdecimal_class(json->decimal_class)) {
|
|
1154
|
+
*result = rb_funcall(Qnil, i_BigDecimal, 1, text);
|
|
1155
|
+
} else {
|
|
1156
|
+
*result = rb_funcall(json->decimal_class, i_new, 1, text);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1134
1159
|
return p + 1;
|
|
1135
1160
|
} else {
|
|
1136
1161
|
return NULL;
|
|
@@ -1139,7 +1164,7 @@ case 7:
|
|
|
1139
1164
|
|
|
1140
1165
|
|
|
1141
1166
|
|
|
1142
|
-
#line
|
|
1167
|
+
#line 1168 "parser.c"
|
|
1143
1168
|
enum {JSON_array_start = 1};
|
|
1144
1169
|
enum {JSON_array_first_final = 17};
|
|
1145
1170
|
enum {JSON_array_error = 0};
|
|
@@ -1147,7 +1172,7 @@ enum {JSON_array_error = 0};
|
|
|
1147
1172
|
enum {JSON_array_en_main = 1};
|
|
1148
1173
|
|
|
1149
1174
|
|
|
1150
|
-
#line
|
|
1175
|
+
#line 416 "parser.rl"
|
|
1151
1176
|
|
|
1152
1177
|
|
|
1153
1178
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
|
@@ -1161,14 +1186,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
|
1161
1186
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
|
1162
1187
|
|
|
1163
1188
|
|
|
1164
|
-
#line
|
|
1189
|
+
#line 1190 "parser.c"
|
|
1165
1190
|
{
|
|
1166
1191
|
cs = JSON_array_start;
|
|
1167
1192
|
}
|
|
1168
1193
|
|
|
1169
|
-
#line
|
|
1194
|
+
#line 429 "parser.rl"
|
|
1170
1195
|
|
|
1171
|
-
#line
|
|
1196
|
+
#line 1197 "parser.c"
|
|
1172
1197
|
{
|
|
1173
1198
|
if ( p == pe )
|
|
1174
1199
|
goto _test_eof;
|
|
@@ -1207,7 +1232,7 @@ case 2:
|
|
|
1207
1232
|
goto st2;
|
|
1208
1233
|
goto st0;
|
|
1209
1234
|
tr2:
|
|
1210
|
-
#line
|
|
1235
|
+
#line 393 "parser.rl"
|
|
1211
1236
|
{
|
|
1212
1237
|
VALUE v = Qnil;
|
|
1213
1238
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
|
@@ -1227,7 +1252,7 @@ st3:
|
|
|
1227
1252
|
if ( ++p == pe )
|
|
1228
1253
|
goto _test_eof3;
|
|
1229
1254
|
case 3:
|
|
1230
|
-
#line
|
|
1255
|
+
#line 1256 "parser.c"
|
|
1231
1256
|
switch( (*p) ) {
|
|
1232
1257
|
case 13: goto st3;
|
|
1233
1258
|
case 32: goto st3;
|
|
@@ -1327,14 +1352,14 @@ case 12:
|
|
|
1327
1352
|
goto st3;
|
|
1328
1353
|
goto st12;
|
|
1329
1354
|
tr4:
|
|
1330
|
-
#line
|
|
1355
|
+
#line 408 "parser.rl"
|
|
1331
1356
|
{ p--; {p++; cs = 17; goto _out;} }
|
|
1332
1357
|
goto st17;
|
|
1333
1358
|
st17:
|
|
1334
1359
|
if ( ++p == pe )
|
|
1335
1360
|
goto _test_eof17;
|
|
1336
1361
|
case 17:
|
|
1337
|
-
#line
|
|
1362
|
+
#line 1363 "parser.c"
|
|
1338
1363
|
goto st0;
|
|
1339
1364
|
st13:
|
|
1340
1365
|
if ( ++p == pe )
|
|
@@ -1390,7 +1415,7 @@ case 16:
|
|
|
1390
1415
|
_out: {}
|
|
1391
1416
|
}
|
|
1392
1417
|
|
|
1393
|
-
#line
|
|
1418
|
+
#line 430 "parser.rl"
|
|
1394
1419
|
|
|
1395
1420
|
if(cs >= JSON_array_first_final) {
|
|
1396
1421
|
return p + 1;
|
|
@@ -1479,7 +1504,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
|
1479
1504
|
}
|
|
1480
1505
|
|
|
1481
1506
|
|
|
1482
|
-
#line
|
|
1507
|
+
#line 1508 "parser.c"
|
|
1483
1508
|
enum {JSON_string_start = 1};
|
|
1484
1509
|
enum {JSON_string_first_final = 8};
|
|
1485
1510
|
enum {JSON_string_error = 0};
|
|
@@ -1487,7 +1512,7 @@ enum {JSON_string_error = 0};
|
|
|
1487
1512
|
enum {JSON_string_en_main = 1};
|
|
1488
1513
|
|
|
1489
1514
|
|
|
1490
|
-
#line
|
|
1515
|
+
#line 537 "parser.rl"
|
|
1491
1516
|
|
|
1492
1517
|
|
|
1493
1518
|
static int
|
|
@@ -1509,15 +1534,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
|
1509
1534
|
|
|
1510
1535
|
*result = rb_str_buf_new(0);
|
|
1511
1536
|
|
|
1512
|
-
#line
|
|
1537
|
+
#line 1538 "parser.c"
|
|
1513
1538
|
{
|
|
1514
1539
|
cs = JSON_string_start;
|
|
1515
1540
|
}
|
|
1516
1541
|
|
|
1517
|
-
#line
|
|
1542
|
+
#line 558 "parser.rl"
|
|
1518
1543
|
json->memo = p;
|
|
1519
1544
|
|
|
1520
|
-
#line
|
|
1545
|
+
#line 1546 "parser.c"
|
|
1521
1546
|
{
|
|
1522
1547
|
if ( p == pe )
|
|
1523
1548
|
goto _test_eof;
|
|
@@ -1542,7 +1567,7 @@ case 2:
|
|
|
1542
1567
|
goto st0;
|
|
1543
1568
|
goto st2;
|
|
1544
1569
|
tr2:
|
|
1545
|
-
#line
|
|
1570
|
+
#line 523 "parser.rl"
|
|
1546
1571
|
{
|
|
1547
1572
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
|
1548
1573
|
if (NIL_P(*result)) {
|
|
@@ -1553,14 +1578,14 @@ tr2:
|
|
|
1553
1578
|
{p = (( p + 1))-1;}
|
|
1554
1579
|
}
|
|
1555
1580
|
}
|
|
1556
|
-
#line
|
|
1581
|
+
#line 534 "parser.rl"
|
|
1557
1582
|
{ p--; {p++; cs = 8; goto _out;} }
|
|
1558
1583
|
goto st8;
|
|
1559
1584
|
st8:
|
|
1560
1585
|
if ( ++p == pe )
|
|
1561
1586
|
goto _test_eof8;
|
|
1562
1587
|
case 8:
|
|
1563
|
-
#line
|
|
1588
|
+
#line 1589 "parser.c"
|
|
1564
1589
|
goto st0;
|
|
1565
1590
|
st3:
|
|
1566
1591
|
if ( ++p == pe )
|
|
@@ -1636,7 +1661,7 @@ case 7:
|
|
|
1636
1661
|
_out: {}
|
|
1637
1662
|
}
|
|
1638
1663
|
|
|
1639
|
-
#line
|
|
1664
|
+
#line 560 "parser.rl"
|
|
1640
1665
|
|
|
1641
1666
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
|
1642
1667
|
VALUE klass;
|
|
@@ -1651,7 +1676,7 @@ case 7:
|
|
|
1651
1676
|
|
|
1652
1677
|
if (json->symbolize_names && json->parsing_name) {
|
|
1653
1678
|
*result = rb_str_intern(*result);
|
|
1654
|
-
} else {
|
|
1679
|
+
} else if (RB_TYPE_P(*result, T_STRING)) {
|
|
1655
1680
|
rb_str_resize(*result, RSTRING_LEN(*result));
|
|
1656
1681
|
}
|
|
1657
1682
|
if (cs >= JSON_string_first_final) {
|
|
@@ -1789,6 +1814,12 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
1789
1814
|
} else {
|
|
1790
1815
|
json->array_class = Qnil;
|
|
1791
1816
|
}
|
|
1817
|
+
tmp = ID2SYM(i_decimal_class);
|
|
1818
|
+
if (option_given_p(opts, tmp)) {
|
|
1819
|
+
json->decimal_class = rb_hash_aref(opts, tmp);
|
|
1820
|
+
} else {
|
|
1821
|
+
json->decimal_class = Qnil;
|
|
1822
|
+
}
|
|
1792
1823
|
tmp = ID2SYM(i_match_string);
|
|
1793
1824
|
if (option_given_p(opts, tmp)) {
|
|
1794
1825
|
VALUE match_string = rb_hash_aref(opts, tmp);
|
|
@@ -1802,10 +1833,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
1802
1833
|
} else {
|
|
1803
1834
|
json->max_nesting = 100;
|
|
1804
1835
|
json->allow_nan = 0;
|
|
1805
|
-
json->create_additions =
|
|
1836
|
+
json->create_additions = 0;
|
|
1806
1837
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
|
1807
1838
|
json->object_class = Qnil;
|
|
1808
1839
|
json->array_class = Qnil;
|
|
1840
|
+
json->decimal_class = Qnil;
|
|
1809
1841
|
}
|
|
1810
1842
|
source = convert_encoding(StringValue(source));
|
|
1811
1843
|
StringValue(source);
|
|
@@ -1816,7 +1848,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
1816
1848
|
}
|
|
1817
1849
|
|
|
1818
1850
|
|
|
1819
|
-
#line
|
|
1851
|
+
#line 1852 "parser.c"
|
|
1820
1852
|
enum {JSON_start = 1};
|
|
1821
1853
|
enum {JSON_first_final = 10};
|
|
1822
1854
|
enum {JSON_error = 0};
|
|
@@ -1824,7 +1856,7 @@ enum {JSON_error = 0};
|
|
|
1824
1856
|
enum {JSON_en_main = 1};
|
|
1825
1857
|
|
|
1826
1858
|
|
|
1827
|
-
#line
|
|
1859
|
+
#line 760 "parser.rl"
|
|
1828
1860
|
|
|
1829
1861
|
|
|
1830
1862
|
/*
|
|
@@ -1841,16 +1873,16 @@ static VALUE cParser_parse(VALUE self)
|
|
|
1841
1873
|
GET_PARSER;
|
|
1842
1874
|
|
|
1843
1875
|
|
|
1844
|
-
#line
|
|
1876
|
+
#line 1877 "parser.c"
|
|
1845
1877
|
{
|
|
1846
1878
|
cs = JSON_start;
|
|
1847
1879
|
}
|
|
1848
1880
|
|
|
1849
|
-
#line
|
|
1881
|
+
#line 776 "parser.rl"
|
|
1850
1882
|
p = json->source;
|
|
1851
1883
|
pe = p + json->len;
|
|
1852
1884
|
|
|
1853
|
-
#line
|
|
1885
|
+
#line 1886 "parser.c"
|
|
1854
1886
|
{
|
|
1855
1887
|
if ( p == pe )
|
|
1856
1888
|
goto _test_eof;
|
|
@@ -1884,7 +1916,7 @@ st0:
|
|
|
1884
1916
|
cs = 0;
|
|
1885
1917
|
goto _out;
|
|
1886
1918
|
tr2:
|
|
1887
|
-
#line
|
|
1919
|
+
#line 752 "parser.rl"
|
|
1888
1920
|
{
|
|
1889
1921
|
char *np = JSON_parse_value(json, p, pe, &result, 0);
|
|
1890
1922
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
|
@@ -1894,7 +1926,7 @@ st10:
|
|
|
1894
1926
|
if ( ++p == pe )
|
|
1895
1927
|
goto _test_eof10;
|
|
1896
1928
|
case 10:
|
|
1897
|
-
#line
|
|
1929
|
+
#line 1930 "parser.c"
|
|
1898
1930
|
switch( (*p) ) {
|
|
1899
1931
|
case 13: goto st10;
|
|
1900
1932
|
case 32: goto st10;
|
|
@@ -1983,7 +2015,7 @@ case 9:
|
|
|
1983
2015
|
_out: {}
|
|
1984
2016
|
}
|
|
1985
2017
|
|
|
1986
|
-
#line
|
|
2018
|
+
#line 779 "parser.rl"
|
|
1987
2019
|
|
|
1988
2020
|
if (cs >= JSON_first_final && p == pe) {
|
|
1989
2021
|
return result;
|
|
@@ -2000,6 +2032,7 @@ static void JSON_mark(void *ptr)
|
|
|
2000
2032
|
rb_gc_mark_maybe(json->create_id);
|
|
2001
2033
|
rb_gc_mark_maybe(json->object_class);
|
|
2002
2034
|
rb_gc_mark_maybe(json->array_class);
|
|
2035
|
+
rb_gc_mark_maybe(json->decimal_class);
|
|
2003
2036
|
rb_gc_mark_maybe(json->match_string);
|
|
2004
2037
|
}
|
|
2005
2038
|
|
|
@@ -2049,20 +2082,28 @@ static VALUE cParser_source(VALUE self)
|
|
|
2049
2082
|
|
|
2050
2083
|
void Init_parser(void)
|
|
2051
2084
|
{
|
|
2085
|
+
#undef rb_intern
|
|
2052
2086
|
rb_require("json/common");
|
|
2053
2087
|
mJSON = rb_define_module("JSON");
|
|
2054
2088
|
mExt = rb_define_module_under(mJSON, "Ext");
|
|
2055
2089
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
|
2056
2090
|
eParserError = rb_path2class("JSON::ParserError");
|
|
2057
2091
|
eNestingError = rb_path2class("JSON::NestingError");
|
|
2092
|
+
rb_gc_register_mark_object(eParserError);
|
|
2093
|
+
rb_gc_register_mark_object(eNestingError);
|
|
2058
2094
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
|
2059
2095
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
|
2060
2096
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
|
2061
2097
|
rb_define_method(cParser, "source", cParser_source, 0);
|
|
2062
2098
|
|
|
2063
2099
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
|
2100
|
+
rb_gc_register_mark_object(CNaN);
|
|
2101
|
+
|
|
2064
2102
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
|
2103
|
+
rb_gc_register_mark_object(CInfinity);
|
|
2104
|
+
|
|
2065
2105
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
|
2106
|
+
rb_gc_register_mark_object(CMinusInfinity);
|
|
2066
2107
|
|
|
2067
2108
|
i_json_creatable_p = rb_intern("json_creatable?");
|
|
2068
2109
|
i_json_create = rb_intern("json_create");
|
|
@@ -2074,6 +2115,7 @@ void Init_parser(void)
|
|
|
2074
2115
|
i_symbolize_names = rb_intern("symbolize_names");
|
|
2075
2116
|
i_object_class = rb_intern("object_class");
|
|
2076
2117
|
i_array_class = rb_intern("array_class");
|
|
2118
|
+
i_decimal_class = rb_intern("decimal_class");
|
|
2077
2119
|
i_match = rb_intern("match");
|
|
2078
2120
|
i_match_string = rb_intern("match_string");
|
|
2079
2121
|
i_key_p = rb_intern("key?");
|
|
@@ -2081,6 +2123,8 @@ void Init_parser(void)
|
|
|
2081
2123
|
i_aset = rb_intern("[]=");
|
|
2082
2124
|
i_aref = rb_intern("[]");
|
|
2083
2125
|
i_leftshift = rb_intern("<<");
|
|
2126
|
+
i_new = rb_intern("new");
|
|
2127
|
+
i_BigDecimal = rb_intern("BigDecimal");
|
|
2084
2128
|
}
|
|
2085
2129
|
|
|
2086
2130
|
/*
|