json_pure 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +15 -0
- data/CHANGES +10 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/benchmarks/data-p4-3GHz-ruby18/.keep +0 -0
- data/benchmarks/data/.keep +0 -0
- data/benchmarks/generator2_benchmark.rb +1 -1
- data/benchmarks/generator_benchmark.rb +1 -1
- data/benchmarks/parser2_benchmark.rb +1 -1
- data/benchmarks/parser_benchmark.rb +1 -1
- data/diagrams/.keep +0 -0
- data/ext/json/ext/fbuffer/fbuffer.h +156 -0
- data/ext/json/ext/generator/extconf.rb +0 -7
- data/ext/json/ext/generator/generator.c +57 -132
- data/ext/json/ext/generator/generator.h +4 -43
- data/ext/json/ext/parser/extconf.rb +0 -3
- data/ext/json/ext/parser/parser.c +94 -87
- data/ext/json/ext/parser/parser.h +2 -7
- data/ext/json/ext/parser/parser.rl +12 -2
- data/java/src/json/ext/GeneratorState.java +21 -0
- data/json.gemspec +16 -16
- data/json_pure.gemspec +15 -15
- data/lib/json/add/bigdecimal.rb +21 -0
- data/lib/json/add/ostruct.rb +31 -0
- data/lib/json/add/time.rb +2 -2
- data/lib/json/common.rb +39 -5
- data/lib/json/ext.rb +6 -0
- data/lib/json/ext/.keep +0 -0
- data/lib/json/pure.rb +6 -0
- data/lib/json/pure/generator.rb +20 -9
- data/lib/json/pure/parser.rb +7 -2
- data/lib/json/version.rb +1 -1
- data/tests/test_json.rb +16 -1
- data/tests/test_json_addition.rb +15 -1
- data/tests/test_json_generate.rb +66 -30
- metadata +143 -134
@@ -7,19 +7,10 @@
|
|
7
7
|
|
8
8
|
#include "ruby.h"
|
9
9
|
|
10
|
-
#
|
10
|
+
#ifdef HAVE_RUBY_RE_H
|
11
11
|
#include "ruby/re.h"
|
12
|
-
#endif
|
13
|
-
|
14
|
-
#if HAVE_RE_H
|
15
|
-
#include "re.h"
|
16
|
-
#endif
|
17
|
-
|
18
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
19
|
-
#include "ruby/encoding.h"
|
20
|
-
#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
|
21
12
|
#else
|
22
|
-
#
|
13
|
+
#include "re.h"
|
23
14
|
#endif
|
24
15
|
|
25
16
|
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
|
@@ -45,38 +36,6 @@
|
|
45
36
|
#define RSTRING_LEN(string) RSTRING(string)->len
|
46
37
|
#endif
|
47
38
|
|
48
|
-
/* We don't need to guard objects for rbx, so let's do nothing at all. */
|
49
|
-
#ifndef RB_GC_GUARD
|
50
|
-
#define RB_GC_GUARD(object)
|
51
|
-
#endif
|
52
|
-
|
53
|
-
/* fbuffer implementation */
|
54
|
-
|
55
|
-
typedef struct FBufferStruct {
|
56
|
-
unsigned long initial_length;
|
57
|
-
char *ptr;
|
58
|
-
unsigned long len;
|
59
|
-
unsigned long capa;
|
60
|
-
} FBuffer;
|
61
|
-
|
62
|
-
#define FBUFFER_INITIAL_LENGTH 4096
|
63
|
-
|
64
|
-
#define FBUFFER_PTR(fb) (fb->ptr)
|
65
|
-
#define FBUFFER_LEN(fb) (fb->len)
|
66
|
-
#define FBUFFER_CAPA(fb) (fb->capa)
|
67
|
-
#define FBUFFER_PAIR(fb) FBUFFER_PTR(fb), FBUFFER_LEN(fb)
|
68
|
-
|
69
|
-
static char *fstrndup(const char *ptr, unsigned long len);
|
70
|
-
static FBuffer *fbuffer_alloc();
|
71
|
-
static FBuffer *fbuffer_alloc_with_length(unsigned long initial_length);
|
72
|
-
static void fbuffer_free(FBuffer *fb);
|
73
|
-
static void fbuffer_clear(FBuffer *fb);
|
74
|
-
static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len);
|
75
|
-
static void fbuffer_append_long(FBuffer *fb, long number);
|
76
|
-
static void fbuffer_append_char(FBuffer *fb, char newchr);
|
77
|
-
static FBuffer *fbuffer_dup(FBuffer *fb);
|
78
|
-
static VALUE fbuffer_to_s(FBuffer *fb);
|
79
|
-
|
80
39
|
/* unicode defintions */
|
81
40
|
|
82
41
|
#define UNI_STRICT_CONVERSION 1
|
@@ -106,6 +65,7 @@ static void unicode_escape(char *buf, UTF16 character);
|
|
106
65
|
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
|
107
66
|
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
|
108
67
|
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string);
|
68
|
+
static char *fstrndup(const char *ptr, unsigned long len);
|
109
69
|
|
110
70
|
/* ruby api and some helpers */
|
111
71
|
|
@@ -128,6 +88,7 @@ typedef struct JSON_Generator_StateStruct {
|
|
128
88
|
char ascii_only;
|
129
89
|
char quirks_mode;
|
130
90
|
long depth;
|
91
|
+
long buffer_initial_length;
|
131
92
|
} JSON_Generator_State;
|
132
93
|
|
133
94
|
#define GET_STATE(self) \
|
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
#line 1 "parser.rl"
|
3
|
+
#include "../fbuffer/fbuffer.h"
|
3
4
|
#include "parser.h"
|
4
5
|
|
5
6
|
/* unicode */
|
@@ -83,11 +84,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
|
83
84
|
i_match_string, i_aset, i_leftshift;
|
84
85
|
|
85
86
|
|
86
|
-
#line
|
87
|
+
#line 110 "parser.rl"
|
87
88
|
|
88
89
|
|
89
90
|
|
90
|
-
#line
|
91
|
+
#line 92 "parser.c"
|
91
92
|
static const int JSON_object_start = 1;
|
92
93
|
static const int JSON_object_first_final = 27;
|
93
94
|
static const int JSON_object_error = 0;
|
@@ -95,7 +96,7 @@ static const int JSON_object_error = 0;
|
|
95
96
|
static const int JSON_object_en_main = 1;
|
96
97
|
|
97
98
|
|
98
|
-
#line
|
99
|
+
#line 151 "parser.rl"
|
99
100
|
|
100
101
|
|
101
102
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -111,14 +112,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
111
112
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
112
113
|
|
113
114
|
|
114
|
-
#line
|
115
|
+
#line 116 "parser.c"
|
115
116
|
{
|
116
117
|
cs = JSON_object_start;
|
117
118
|
}
|
118
119
|
|
119
|
-
#line
|
120
|
+
#line 166 "parser.rl"
|
120
121
|
|
121
|
-
#line
|
122
|
+
#line 123 "parser.c"
|
122
123
|
{
|
123
124
|
if ( p == pe )
|
124
125
|
goto _test_eof;
|
@@ -146,7 +147,7 @@ case 2:
|
|
146
147
|
goto st2;
|
147
148
|
goto st0;
|
148
149
|
tr2:
|
149
|
-
#line
|
150
|
+
#line 133 "parser.rl"
|
150
151
|
{
|
151
152
|
char *np;
|
152
153
|
json->parsing_name = 1;
|
@@ -159,7 +160,7 @@ st3:
|
|
159
160
|
if ( ++p == pe )
|
160
161
|
goto _test_eof3;
|
161
162
|
case 3:
|
162
|
-
#line
|
163
|
+
#line 164 "parser.c"
|
163
164
|
switch( (*p) ) {
|
164
165
|
case 13: goto st3;
|
165
166
|
case 32: goto st3;
|
@@ -226,7 +227,7 @@ case 8:
|
|
226
227
|
goto st8;
|
227
228
|
goto st0;
|
228
229
|
tr11:
|
229
|
-
#line
|
230
|
+
#line 118 "parser.rl"
|
230
231
|
{
|
231
232
|
VALUE v = Qnil;
|
232
233
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -246,7 +247,7 @@ st9:
|
|
246
247
|
if ( ++p == pe )
|
247
248
|
goto _test_eof9;
|
248
249
|
case 9:
|
249
|
-
#line
|
250
|
+
#line 251 "parser.c"
|
250
251
|
switch( (*p) ) {
|
251
252
|
case 13: goto st9;
|
252
253
|
case 32: goto st9;
|
@@ -335,14 +336,14 @@ case 18:
|
|
335
336
|
goto st9;
|
336
337
|
goto st18;
|
337
338
|
tr4:
|
338
|
-
#line
|
339
|
+
#line 141 "parser.rl"
|
339
340
|
{ p--; {p++; cs = 27; goto _out;} }
|
340
341
|
goto st27;
|
341
342
|
st27:
|
342
343
|
if ( ++p == pe )
|
343
344
|
goto _test_eof27;
|
344
345
|
case 27:
|
345
|
-
#line
|
346
|
+
#line 347 "parser.c"
|
346
347
|
goto st0;
|
347
348
|
st19:
|
348
349
|
if ( ++p == pe )
|
@@ -440,7 +441,7 @@ case 26:
|
|
440
441
|
_out: {}
|
441
442
|
}
|
442
443
|
|
443
|
-
#line
|
444
|
+
#line 167 "parser.rl"
|
444
445
|
|
445
446
|
if (cs >= JSON_object_first_final) {
|
446
447
|
if (json->create_additions) {
|
@@ -460,7 +461,7 @@ case 26:
|
|
460
461
|
|
461
462
|
|
462
463
|
|
463
|
-
#line
|
464
|
+
#line 465 "parser.c"
|
464
465
|
static const int JSON_value_start = 1;
|
465
466
|
static const int JSON_value_first_final = 21;
|
466
467
|
static const int JSON_value_error = 0;
|
@@ -468,7 +469,7 @@ static const int JSON_value_error = 0;
|
|
468
469
|
static const int JSON_value_en_main = 1;
|
469
470
|
|
470
471
|
|
471
|
-
#line
|
472
|
+
#line 266 "parser.rl"
|
472
473
|
|
473
474
|
|
474
475
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -476,14 +477,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
476
477
|
int cs = EVIL;
|
477
478
|
|
478
479
|
|
479
|
-
#line
|
480
|
+
#line 481 "parser.c"
|
480
481
|
{
|
481
482
|
cs = JSON_value_start;
|
482
483
|
}
|
483
484
|
|
484
|
-
#line
|
485
|
+
#line 273 "parser.rl"
|
485
486
|
|
486
|
-
#line
|
487
|
+
#line 488 "parser.c"
|
487
488
|
{
|
488
489
|
if ( p == pe )
|
489
490
|
goto _test_eof;
|
@@ -508,14 +509,14 @@ st0:
|
|
508
509
|
cs = 0;
|
509
510
|
goto _out;
|
510
511
|
tr0:
|
511
|
-
#line
|
512
|
+
#line 214 "parser.rl"
|
512
513
|
{
|
513
514
|
char *np = JSON_parse_string(json, p, pe, result);
|
514
515
|
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
515
516
|
}
|
516
517
|
goto st21;
|
517
518
|
tr2:
|
518
|
-
#line
|
519
|
+
#line 219 "parser.rl"
|
519
520
|
{
|
520
521
|
char *np;
|
521
522
|
if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
|
@@ -535,7 +536,7 @@ tr2:
|
|
535
536
|
}
|
536
537
|
goto st21;
|
537
538
|
tr5:
|
538
|
-
#line
|
539
|
+
#line 237 "parser.rl"
|
539
540
|
{
|
540
541
|
char *np;
|
541
542
|
json->current_nesting++;
|
@@ -545,7 +546,7 @@ tr5:
|
|
545
546
|
}
|
546
547
|
goto st21;
|
547
548
|
tr9:
|
548
|
-
#line
|
549
|
+
#line 245 "parser.rl"
|
549
550
|
{
|
550
551
|
char *np;
|
551
552
|
json->current_nesting++;
|
@@ -555,7 +556,7 @@ tr9:
|
|
555
556
|
}
|
556
557
|
goto st21;
|
557
558
|
tr16:
|
558
|
-
#line
|
559
|
+
#line 207 "parser.rl"
|
559
560
|
{
|
560
561
|
if (json->allow_nan) {
|
561
562
|
*result = CInfinity;
|
@@ -565,7 +566,7 @@ tr16:
|
|
565
566
|
}
|
566
567
|
goto st21;
|
567
568
|
tr18:
|
568
|
-
#line
|
569
|
+
#line 200 "parser.rl"
|
569
570
|
{
|
570
571
|
if (json->allow_nan) {
|
571
572
|
*result = CNaN;
|
@@ -575,19 +576,19 @@ tr18:
|
|
575
576
|
}
|
576
577
|
goto st21;
|
577
578
|
tr22:
|
578
|
-
#line
|
579
|
+
#line 194 "parser.rl"
|
579
580
|
{
|
580
581
|
*result = Qfalse;
|
581
582
|
}
|
582
583
|
goto st21;
|
583
584
|
tr25:
|
584
|
-
#line
|
585
|
+
#line 191 "parser.rl"
|
585
586
|
{
|
586
587
|
*result = Qnil;
|
587
588
|
}
|
588
589
|
goto st21;
|
589
590
|
tr28:
|
590
|
-
#line
|
591
|
+
#line 197 "parser.rl"
|
591
592
|
{
|
592
593
|
*result = Qtrue;
|
593
594
|
}
|
@@ -596,9 +597,9 @@ st21:
|
|
596
597
|
if ( ++p == pe )
|
597
598
|
goto _test_eof21;
|
598
599
|
case 21:
|
599
|
-
#line
|
600
|
+
#line 253 "parser.rl"
|
600
601
|
{ p--; {p++; cs = 21; goto _out;} }
|
601
|
-
#line
|
602
|
+
#line 603 "parser.c"
|
602
603
|
goto st0;
|
603
604
|
st2:
|
604
605
|
if ( ++p == pe )
|
@@ -759,7 +760,7 @@ case 20:
|
|
759
760
|
_out: {}
|
760
761
|
}
|
761
762
|
|
762
|
-
#line
|
763
|
+
#line 274 "parser.rl"
|
763
764
|
|
764
765
|
if (cs >= JSON_value_first_final) {
|
765
766
|
return p;
|
@@ -769,7 +770,7 @@ case 20:
|
|
769
770
|
}
|
770
771
|
|
771
772
|
|
772
|
-
#line
|
773
|
+
#line 774 "parser.c"
|
773
774
|
static const int JSON_integer_start = 1;
|
774
775
|
static const int JSON_integer_first_final = 3;
|
775
776
|
static const int JSON_integer_error = 0;
|
@@ -777,7 +778,7 @@ static const int JSON_integer_error = 0;
|
|
777
778
|
static const int JSON_integer_en_main = 1;
|
778
779
|
|
779
780
|
|
780
|
-
#line
|
781
|
+
#line 290 "parser.rl"
|
781
782
|
|
782
783
|
|
783
784
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -785,15 +786,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
785
786
|
int cs = EVIL;
|
786
787
|
|
787
788
|
|
788
|
-
#line
|
789
|
+
#line 790 "parser.c"
|
789
790
|
{
|
790
791
|
cs = JSON_integer_start;
|
791
792
|
}
|
792
793
|
|
793
|
-
#line
|
794
|
+
#line 297 "parser.rl"
|
794
795
|
json->memo = p;
|
795
796
|
|
796
|
-
#line
|
797
|
+
#line 798 "parser.c"
|
797
798
|
{
|
798
799
|
if ( p == pe )
|
799
800
|
goto _test_eof;
|
@@ -827,14 +828,14 @@ case 3:
|
|
827
828
|
goto st0;
|
828
829
|
goto tr4;
|
829
830
|
tr4:
|
830
|
-
#line
|
831
|
+
#line 287 "parser.rl"
|
831
832
|
{ p--; {p++; cs = 4; goto _out;} }
|
832
833
|
goto st4;
|
833
834
|
st4:
|
834
835
|
if ( ++p == pe )
|
835
836
|
goto _test_eof4;
|
836
837
|
case 4:
|
837
|
-
#line
|
838
|
+
#line 839 "parser.c"
|
838
839
|
goto st0;
|
839
840
|
st5:
|
840
841
|
if ( ++p == pe )
|
@@ -853,11 +854,14 @@ case 5:
|
|
853
854
|
_out: {}
|
854
855
|
}
|
855
856
|
|
856
|
-
#line
|
857
|
+
#line 299 "parser.rl"
|
857
858
|
|
858
859
|
if (cs >= JSON_integer_first_final) {
|
859
860
|
long len = p - json->memo;
|
860
|
-
|
861
|
+
fbuffer_clear(json->fbuffer);
|
862
|
+
fbuffer_append(json->fbuffer, json->memo, len);
|
863
|
+
fbuffer_append_char(json->fbuffer, '\0');
|
864
|
+
*result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
|
861
865
|
return p + 1;
|
862
866
|
} else {
|
863
867
|
return NULL;
|
@@ -865,7 +869,7 @@ case 5:
|
|
865
869
|
}
|
866
870
|
|
867
871
|
|
868
|
-
#line
|
872
|
+
#line 873 "parser.c"
|
869
873
|
static const int JSON_float_start = 1;
|
870
874
|
static const int JSON_float_first_final = 8;
|
871
875
|
static const int JSON_float_error = 0;
|
@@ -873,7 +877,7 @@ static const int JSON_float_error = 0;
|
|
873
877
|
static const int JSON_float_en_main = 1;
|
874
878
|
|
875
879
|
|
876
|
-
#line
|
880
|
+
#line 324 "parser.rl"
|
877
881
|
|
878
882
|
|
879
883
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -881,15 +885,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
881
885
|
int cs = EVIL;
|
882
886
|
|
883
887
|
|
884
|
-
#line
|
888
|
+
#line 889 "parser.c"
|
885
889
|
{
|
886
890
|
cs = JSON_float_start;
|
887
891
|
}
|
888
892
|
|
889
|
-
#line
|
893
|
+
#line 331 "parser.rl"
|
890
894
|
json->memo = p;
|
891
895
|
|
892
|
-
#line
|
896
|
+
#line 897 "parser.c"
|
893
897
|
{
|
894
898
|
if ( p == pe )
|
895
899
|
goto _test_eof;
|
@@ -947,14 +951,14 @@ case 8:
|
|
947
951
|
goto st0;
|
948
952
|
goto tr9;
|
949
953
|
tr9:
|
950
|
-
#line
|
954
|
+
#line 318 "parser.rl"
|
951
955
|
{ p--; {p++; cs = 9; goto _out;} }
|
952
956
|
goto st9;
|
953
957
|
st9:
|
954
958
|
if ( ++p == pe )
|
955
959
|
goto _test_eof9;
|
956
960
|
case 9:
|
957
|
-
#line
|
961
|
+
#line 962 "parser.c"
|
958
962
|
goto st0;
|
959
963
|
st5:
|
960
964
|
if ( ++p == pe )
|
@@ -1015,11 +1019,14 @@ case 7:
|
|
1015
1019
|
_out: {}
|
1016
1020
|
}
|
1017
1021
|
|
1018
|
-
#line
|
1022
|
+
#line 333 "parser.rl"
|
1019
1023
|
|
1020
1024
|
if (cs >= JSON_float_first_final) {
|
1021
1025
|
long len = p - json->memo;
|
1022
|
-
|
1026
|
+
fbuffer_clear(json->fbuffer);
|
1027
|
+
fbuffer_append(json->fbuffer, json->memo, len);
|
1028
|
+
fbuffer_append_char(json->fbuffer, '\0');
|
1029
|
+
*result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
|
1023
1030
|
return p + 1;
|
1024
1031
|
} else {
|
1025
1032
|
return NULL;
|
@@ -1028,7 +1035,7 @@ case 7:
|
|
1028
1035
|
|
1029
1036
|
|
1030
1037
|
|
1031
|
-
#line
|
1038
|
+
#line 1039 "parser.c"
|
1032
1039
|
static const int JSON_array_start = 1;
|
1033
1040
|
static const int JSON_array_first_final = 17;
|
1034
1041
|
static const int JSON_array_error = 0;
|
@@ -1036,7 +1043,7 @@ static const int JSON_array_error = 0;
|
|
1036
1043
|
static const int JSON_array_en_main = 1;
|
1037
1044
|
|
1038
1045
|
|
1039
|
-
#line
|
1046
|
+
#line 376 "parser.rl"
|
1040
1047
|
|
1041
1048
|
|
1042
1049
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -1050,14 +1057,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
1050
1057
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
1051
1058
|
|
1052
1059
|
|
1053
|
-
#line
|
1060
|
+
#line 1061 "parser.c"
|
1054
1061
|
{
|
1055
1062
|
cs = JSON_array_start;
|
1056
1063
|
}
|
1057
1064
|
|
1058
|
-
#line
|
1065
|
+
#line 389 "parser.rl"
|
1059
1066
|
|
1060
|
-
#line
|
1067
|
+
#line 1068 "parser.c"
|
1061
1068
|
{
|
1062
1069
|
if ( p == pe )
|
1063
1070
|
goto _test_eof;
|
@@ -1096,7 +1103,7 @@ case 2:
|
|
1096
1103
|
goto st2;
|
1097
1104
|
goto st0;
|
1098
1105
|
tr2:
|
1099
|
-
#line
|
1106
|
+
#line 353 "parser.rl"
|
1100
1107
|
{
|
1101
1108
|
VALUE v = Qnil;
|
1102
1109
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -1116,7 +1123,7 @@ st3:
|
|
1116
1123
|
if ( ++p == pe )
|
1117
1124
|
goto _test_eof3;
|
1118
1125
|
case 3:
|
1119
|
-
#line
|
1126
|
+
#line 1127 "parser.c"
|
1120
1127
|
switch( (*p) ) {
|
1121
1128
|
case 13: goto st3;
|
1122
1129
|
case 32: goto st3;
|
@@ -1216,14 +1223,14 @@ case 12:
|
|
1216
1223
|
goto st3;
|
1217
1224
|
goto st12;
|
1218
1225
|
tr4:
|
1219
|
-
#line
|
1226
|
+
#line 368 "parser.rl"
|
1220
1227
|
{ p--; {p++; cs = 17; goto _out;} }
|
1221
1228
|
goto st17;
|
1222
1229
|
st17:
|
1223
1230
|
if ( ++p == pe )
|
1224
1231
|
goto _test_eof17;
|
1225
1232
|
case 17:
|
1226
|
-
#line
|
1233
|
+
#line 1234 "parser.c"
|
1227
1234
|
goto st0;
|
1228
1235
|
st13:
|
1229
1236
|
if ( ++p == pe )
|
@@ -1279,7 +1286,7 @@ case 16:
|
|
1279
1286
|
_out: {}
|
1280
1287
|
}
|
1281
1288
|
|
1282
|
-
#line
|
1289
|
+
#line 390 "parser.rl"
|
1283
1290
|
|
1284
1291
|
if(cs >= JSON_array_first_final) {
|
1285
1292
|
return p + 1;
|
@@ -1360,7 +1367,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
1360
1367
|
}
|
1361
1368
|
|
1362
1369
|
|
1363
|
-
#line
|
1370
|
+
#line 1371 "parser.c"
|
1364
1371
|
static const int JSON_string_start = 1;
|
1365
1372
|
static const int JSON_string_first_final = 8;
|
1366
1373
|
static const int JSON_string_error = 0;
|
@@ -1368,7 +1375,7 @@ static const int JSON_string_error = 0;
|
|
1368
1375
|
static const int JSON_string_en_main = 1;
|
1369
1376
|
|
1370
1377
|
|
1371
|
-
#line
|
1378
|
+
#line 489 "parser.rl"
|
1372
1379
|
|
1373
1380
|
|
1374
1381
|
static int
|
@@ -1390,15 +1397,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
1390
1397
|
|
1391
1398
|
*result = rb_str_buf_new(0);
|
1392
1399
|
|
1393
|
-
#line
|
1400
|
+
#line 1401 "parser.c"
|
1394
1401
|
{
|
1395
1402
|
cs = JSON_string_start;
|
1396
1403
|
}
|
1397
1404
|
|
1398
|
-
#line
|
1405
|
+
#line 510 "parser.rl"
|
1399
1406
|
json->memo = p;
|
1400
1407
|
|
1401
|
-
#line
|
1408
|
+
#line 1409 "parser.c"
|
1402
1409
|
{
|
1403
1410
|
if ( p == pe )
|
1404
1411
|
goto _test_eof;
|
@@ -1423,7 +1430,7 @@ case 2:
|
|
1423
1430
|
goto st0;
|
1424
1431
|
goto st2;
|
1425
1432
|
tr2:
|
1426
|
-
#line
|
1433
|
+
#line 475 "parser.rl"
|
1427
1434
|
{
|
1428
1435
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
1429
1436
|
if (NIL_P(*result)) {
|
@@ -1434,14 +1441,14 @@ tr2:
|
|
1434
1441
|
{p = (( p + 1))-1;}
|
1435
1442
|
}
|
1436
1443
|
}
|
1437
|
-
#line
|
1444
|
+
#line 486 "parser.rl"
|
1438
1445
|
{ p--; {p++; cs = 8; goto _out;} }
|
1439
1446
|
goto st8;
|
1440
1447
|
st8:
|
1441
1448
|
if ( ++p == pe )
|
1442
1449
|
goto _test_eof8;
|
1443
1450
|
case 8:
|
1444
|
-
#line
|
1451
|
+
#line 1452 "parser.c"
|
1445
1452
|
goto st0;
|
1446
1453
|
st3:
|
1447
1454
|
if ( ++p == pe )
|
@@ -1517,7 +1524,7 @@ case 7:
|
|
1517
1524
|
_out: {}
|
1518
1525
|
}
|
1519
1526
|
|
1520
|
-
#line
|
1527
|
+
#line 512 "parser.rl"
|
1521
1528
|
|
1522
1529
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
1523
1530
|
VALUE klass;
|
@@ -1618,9 +1625,6 @@ static VALUE convert_encoding(VALUE source)
|
|
1618
1625
|
* defaults to true.
|
1619
1626
|
* * *object_class*: Defaults to Hash
|
1620
1627
|
* * *array_class*: Defaults to Array
|
1621
|
-
* * *quirks_mode*: Enables quirks_mode for parser, that is for example
|
1622
|
-
* parsing single JSON values instead of documents is possible.
|
1623
|
-
*
|
1624
1628
|
*/
|
1625
1629
|
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
1626
1630
|
{
|
@@ -1707,6 +1711,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1707
1711
|
json->object_class = Qnil;
|
1708
1712
|
json->array_class = Qnil;
|
1709
1713
|
}
|
1714
|
+
source = rb_convert_type(source, T_STRING, "String", "to_str");
|
1710
1715
|
if (!json->quirks_mode) {
|
1711
1716
|
source = convert_encoding(StringValue(source));
|
1712
1717
|
}
|
@@ -1718,7 +1723,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1718
1723
|
}
|
1719
1724
|
|
1720
1725
|
|
1721
|
-
#line
|
1726
|
+
#line 1727 "parser.c"
|
1722
1727
|
static const int JSON_start = 1;
|
1723
1728
|
static const int JSON_first_final = 10;
|
1724
1729
|
static const int JSON_error = 0;
|
@@ -1726,7 +1731,7 @@ static const int JSON_error = 0;
|
|
1726
1731
|
static const int JSON_en_main = 1;
|
1727
1732
|
|
1728
1733
|
|
1729
|
-
#line
|
1734
|
+
#line 734 "parser.rl"
|
1730
1735
|
|
1731
1736
|
|
1732
1737
|
static VALUE cParser_parse_strict(VALUE self)
|
@@ -1737,16 +1742,16 @@ static VALUE cParser_parse_strict(VALUE self)
|
|
1737
1742
|
GET_PARSER;
|
1738
1743
|
|
1739
1744
|
|
1740
|
-
#line
|
1745
|
+
#line 1746 "parser.c"
|
1741
1746
|
{
|
1742
1747
|
cs = JSON_start;
|
1743
1748
|
}
|
1744
1749
|
|
1745
|
-
#line
|
1750
|
+
#line 744 "parser.rl"
|
1746
1751
|
p = json->source;
|
1747
1752
|
pe = p + json->len;
|
1748
1753
|
|
1749
|
-
#line
|
1754
|
+
#line 1755 "parser.c"
|
1750
1755
|
{
|
1751
1756
|
if ( p == pe )
|
1752
1757
|
goto _test_eof;
|
@@ -1802,7 +1807,7 @@ case 5:
|
|
1802
1807
|
goto st1;
|
1803
1808
|
goto st5;
|
1804
1809
|
tr3:
|
1805
|
-
#line
|
1810
|
+
#line 723 "parser.rl"
|
1806
1811
|
{
|
1807
1812
|
char *np;
|
1808
1813
|
json->current_nesting = 1;
|
@@ -1811,7 +1816,7 @@ tr3:
|
|
1811
1816
|
}
|
1812
1817
|
goto st10;
|
1813
1818
|
tr4:
|
1814
|
-
#line
|
1819
|
+
#line 716 "parser.rl"
|
1815
1820
|
{
|
1816
1821
|
char *np;
|
1817
1822
|
json->current_nesting = 1;
|
@@ -1823,7 +1828,7 @@ st10:
|
|
1823
1828
|
if ( ++p == pe )
|
1824
1829
|
goto _test_eof10;
|
1825
1830
|
case 10:
|
1826
|
-
#line
|
1831
|
+
#line 1832 "parser.c"
|
1827
1832
|
switch( (*p) ) {
|
1828
1833
|
case 13: goto st10;
|
1829
1834
|
case 32: goto st10;
|
@@ -1880,7 +1885,7 @@ case 9:
|
|
1880
1885
|
_out: {}
|
1881
1886
|
}
|
1882
1887
|
|
1883
|
-
#line
|
1888
|
+
#line 747 "parser.rl"
|
1884
1889
|
|
1885
1890
|
if (cs >= JSON_first_final && p == pe) {
|
1886
1891
|
return result;
|
@@ -1892,7 +1897,7 @@ case 9:
|
|
1892
1897
|
|
1893
1898
|
|
1894
1899
|
|
1895
|
-
#line
|
1900
|
+
#line 1901 "parser.c"
|
1896
1901
|
static const int JSON_quirks_mode_start = 1;
|
1897
1902
|
static const int JSON_quirks_mode_first_final = 10;
|
1898
1903
|
static const int JSON_quirks_mode_error = 0;
|
@@ -1900,7 +1905,7 @@ static const int JSON_quirks_mode_error = 0;
|
|
1900
1905
|
static const int JSON_quirks_mode_en_main = 1;
|
1901
1906
|
|
1902
1907
|
|
1903
|
-
#line
|
1908
|
+
#line 772 "parser.rl"
|
1904
1909
|
|
1905
1910
|
|
1906
1911
|
static VALUE cParser_parse_quirks_mode(VALUE self)
|
@@ -1911,16 +1916,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
|
|
1911
1916
|
GET_PARSER;
|
1912
1917
|
|
1913
1918
|
|
1914
|
-
#line
|
1919
|
+
#line 1920 "parser.c"
|
1915
1920
|
{
|
1916
1921
|
cs = JSON_quirks_mode_start;
|
1917
1922
|
}
|
1918
1923
|
|
1919
|
-
#line
|
1924
|
+
#line 782 "parser.rl"
|
1920
1925
|
p = json->source;
|
1921
1926
|
pe = p + json->len;
|
1922
1927
|
|
1923
|
-
#line
|
1928
|
+
#line 1929 "parser.c"
|
1924
1929
|
{
|
1925
1930
|
if ( p == pe )
|
1926
1931
|
goto _test_eof;
|
@@ -1954,7 +1959,7 @@ st0:
|
|
1954
1959
|
cs = 0;
|
1955
1960
|
goto _out;
|
1956
1961
|
tr2:
|
1957
|
-
#line
|
1962
|
+
#line 764 "parser.rl"
|
1958
1963
|
{
|
1959
1964
|
char *np = JSON_parse_value(json, p, pe, &result);
|
1960
1965
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
@@ -1964,7 +1969,7 @@ st10:
|
|
1964
1969
|
if ( ++p == pe )
|
1965
1970
|
goto _test_eof10;
|
1966
1971
|
case 10:
|
1967
|
-
#line
|
1972
|
+
#line 1973 "parser.c"
|
1968
1973
|
switch( (*p) ) {
|
1969
1974
|
case 13: goto st10;
|
1970
1975
|
case 32: goto st10;
|
@@ -2053,7 +2058,7 @@ case 9:
|
|
2053
2058
|
_out: {}
|
2054
2059
|
}
|
2055
2060
|
|
2056
|
-
#line
|
2061
|
+
#line 785 "parser.rl"
|
2057
2062
|
|
2058
2063
|
if (cs >= JSON_quirks_mode_first_final && p == pe) {
|
2059
2064
|
return result;
|
@@ -2085,6 +2090,7 @@ static JSON_Parser *JSON_allocate()
|
|
2085
2090
|
{
|
2086
2091
|
JSON_Parser *json = ALLOC(JSON_Parser);
|
2087
2092
|
MEMZERO(json, JSON_Parser, 1);
|
2093
|
+
json->fbuffer = fbuffer_alloc(0);
|
2088
2094
|
return json;
|
2089
2095
|
}
|
2090
2096
|
|
@@ -2099,6 +2105,7 @@ static void JSON_mark(JSON_Parser *json)
|
|
2099
2105
|
|
2100
2106
|
static void JSON_free(JSON_Parser *json)
|
2101
2107
|
{
|
2108
|
+
fbuffer_free(json->fbuffer);
|
2102
2109
|
ruby_xfree(json);
|
2103
2110
|
}
|
2104
2111
|
|