json_pure 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +14 -0
  3. data/VERSION +1 -1
  4. data/json_pure.gemspec +47 -19
  5. data/lib/json/version.rb +1 -1
  6. data/tests/fixtures/fail29.json +1 -0
  7. data/tests/fixtures/fail30.json +1 -0
  8. data/tests/fixtures/fail31.json +1 -0
  9. data/tests/fixtures/fail32.json +1 -0
  10. metadata +16 -48
  11. data/.gitignore +0 -18
  12. data/.travis.yml +0 -23
  13. data/README-json-jruby.md +0 -33
  14. data/Rakefile +0 -334
  15. data/diagrams/.keep +0 -0
  16. data/ext/json/ext/fbuffer/fbuffer.h +0 -187
  17. data/ext/json/ext/generator/depend +0 -1
  18. data/ext/json/ext/generator/extconf.rb +0 -4
  19. data/ext/json/ext/generator/generator.c +0 -1612
  20. data/ext/json/ext/generator/generator.h +0 -174
  21. data/ext/json/ext/parser/depend +0 -1
  22. data/ext/json/ext/parser/extconf.rb +0 -31
  23. data/ext/json/ext/parser/parser.c +0 -2164
  24. data/ext/json/ext/parser/parser.h +0 -92
  25. data/ext/json/ext/parser/parser.rl +0 -924
  26. data/ext/json/extconf.rb +0 -3
  27. data/install.rb +0 -23
  28. data/java/src/json/ext/ByteListTranscoder.java +0 -166
  29. data/java/src/json/ext/Generator.java +0 -447
  30. data/java/src/json/ext/GeneratorMethods.java +0 -231
  31. data/java/src/json/ext/GeneratorService.java +0 -42
  32. data/java/src/json/ext/GeneratorState.java +0 -520
  33. data/java/src/json/ext/OptionsReader.java +0 -113
  34. data/java/src/json/ext/Parser.java +0 -2374
  35. data/java/src/json/ext/Parser.rl +0 -905
  36. data/java/src/json/ext/ParserService.java +0 -34
  37. data/java/src/json/ext/RuntimeInfo.java +0 -116
  38. data/java/src/json/ext/StringDecoder.java +0 -166
  39. data/java/src/json/ext/StringEncoder.java +0 -117
  40. data/java/src/json/ext/Utils.java +0 -88
  41. data/json-java.gemspec +0 -38
  42. data/json.gemspec +0 -140
  43. data/references/rfc7159.txt +0 -899
  44. data/tools/diff.sh +0 -18
  45. data/tools/fuzz.rb +0 -131
  46. data/tools/server.rb +0 -62
@@ -1,174 +0,0 @@
1
- #ifndef _GENERATOR_H_
2
- #define _GENERATOR_H_
3
-
4
- #include <math.h>
5
- #include <ctype.h>
6
-
7
- #include "ruby.h"
8
-
9
- #ifdef HAVE_RUBY_RE_H
10
- #include "ruby/re.h"
11
- #else
12
- #include "re.h"
13
- #endif
14
-
15
- #ifndef rb_intern_str
16
- #define rb_intern_str(string) SYM2ID(rb_str_intern(string))
17
- #endif
18
-
19
- #ifndef rb_obj_instance_variables
20
- #define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
21
- #endif
22
-
23
- #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
24
-
25
- /* unicode definitions */
26
-
27
- #define UNI_STRICT_CONVERSION 1
28
-
29
- typedef unsigned long UTF32; /* at least 32 bits */
30
- typedef unsigned short UTF16; /* at least 16 bits */
31
- typedef unsigned char UTF8; /* typically 8 bits */
32
-
33
- #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
34
- #define UNI_MAX_BMP (UTF32)0x0000FFFF
35
- #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
36
- #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
37
- #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
38
-
39
- #define UNI_SUR_HIGH_START (UTF32)0xD800
40
- #define UNI_SUR_HIGH_END (UTF32)0xDBFF
41
- #define UNI_SUR_LOW_START (UTF32)0xDC00
42
- #define UNI_SUR_LOW_END (UTF32)0xDFFF
43
-
44
- static const int halfShift = 10; /* used for shifting by 10 bits */
45
-
46
- static const UTF32 halfBase = 0x0010000UL;
47
- static const UTF32 halfMask = 0x3FFUL;
48
-
49
- static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
50
- static void unicode_escape(char *buf, UTF16 character);
51
- static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
52
- static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escape_slash);
53
- static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slash);
54
- static char *fstrndup(const char *ptr, unsigned long len);
55
-
56
- /* ruby api and some helpers */
57
-
58
- typedef struct JSON_Generator_StateStruct {
59
- char *indent;
60
- long indent_len;
61
- char *space;
62
- long space_len;
63
- char *space_before;
64
- long space_before_len;
65
- char *object_nl;
66
- long object_nl_len;
67
- char *array_nl;
68
- long array_nl_len;
69
- FBuffer *array_delim;
70
- FBuffer *object_delim;
71
- FBuffer *object_delim2;
72
- long max_nesting;
73
- char allow_nan;
74
- char ascii_only;
75
- char escape_slash;
76
- long depth;
77
- long buffer_initial_length;
78
- } JSON_Generator_State;
79
-
80
- #define GET_STATE_TO(self, state) \
81
- TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
82
-
83
- #define GET_STATE(self) \
84
- JSON_Generator_State *state; \
85
- GET_STATE_TO(self, state)
86
-
87
- #define GENERATE_JSON(type) \
88
- FBuffer *buffer; \
89
- VALUE Vstate; \
90
- JSON_Generator_State *state; \
91
- \
92
- rb_scan_args(argc, argv, "01", &Vstate); \
93
- Vstate = cState_from_state_s(cState, Vstate); \
94
- TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
95
- buffer = cState_prepare_buffer(Vstate); \
96
- generate_json_##type(buffer, Vstate, state, self); \
97
- return fbuffer_to_s(buffer)
98
-
99
- static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
100
- static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
101
- #ifdef RUBY_INTEGER_UNIFICATION
102
- static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
103
- #else
104
- static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
105
- static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
106
- #endif
107
- static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
108
- static VALUE mString_included_s(VALUE self, VALUE modul);
109
- static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
110
- static VALUE mString_to_json_raw_object(VALUE self);
111
- static VALUE mString_to_json_raw(int argc, VALUE *argv, VALUE self);
112
- static VALUE mString_Extend_json_create(VALUE self, VALUE o);
113
- static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self);
114
- static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
115
- static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
116
- static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
117
- static void State_free(void *state);
118
- static VALUE cState_s_allocate(VALUE klass);
119
- static VALUE cState_configure(VALUE self, VALUE opts);
120
- static VALUE cState_to_h(VALUE self);
121
- static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
122
- static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
123
- static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
124
- static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
125
- static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
126
- static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
127
- static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
128
- #ifdef RUBY_INTEGER_UNIFICATION
129
- static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
130
- #endif
131
- static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
132
- static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
133
- static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
134
- static VALUE cState_partial_generate(VALUE self, VALUE obj);
135
- static VALUE cState_generate(VALUE self, VALUE obj);
136
- static VALUE cState_initialize(int argc, VALUE *argv, VALUE self);
137
- static VALUE cState_from_state_s(VALUE self, VALUE opts);
138
- static VALUE cState_indent(VALUE self);
139
- static VALUE cState_indent_set(VALUE self, VALUE indent);
140
- static VALUE cState_space(VALUE self);
141
- static VALUE cState_space_set(VALUE self, VALUE space);
142
- static VALUE cState_space_before(VALUE self);
143
- static VALUE cState_space_before_set(VALUE self, VALUE space_before);
144
- static VALUE cState_object_nl(VALUE self);
145
- static VALUE cState_object_nl_set(VALUE self, VALUE object_nl);
146
- static VALUE cState_array_nl(VALUE self);
147
- static VALUE cState_array_nl_set(VALUE self, VALUE array_nl);
148
- static VALUE cState_max_nesting(VALUE self);
149
- static VALUE cState_max_nesting_set(VALUE self, VALUE depth);
150
- static VALUE cState_allow_nan_p(VALUE self);
151
- static VALUE cState_ascii_only_p(VALUE self);
152
- static VALUE cState_depth(VALUE self);
153
- static VALUE cState_depth_set(VALUE self, VALUE depth);
154
- static VALUE cState_escape_slash(VALUE self);
155
- static VALUE cState_escape_slash_set(VALUE self, VALUE depth);
156
- static FBuffer *cState_prepare_buffer(VALUE self);
157
- #ifndef ZALLOC
158
- #define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
159
- static inline void *ruby_zalloc(size_t n)
160
- {
161
- void *p = ruby_xmalloc(n);
162
- memset(p, 0, n);
163
- return p;
164
- }
165
- #endif
166
- #ifdef TypedData_Make_Struct
167
- static const rb_data_type_t JSON_Generator_State_type;
168
- #define NEW_TYPEDDATA_WRAPPER 1
169
- #else
170
- #define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
171
- #define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
172
- #endif
173
-
174
- #endif
@@ -1 +0,0 @@
1
- parser.o: parser.c parser.h $(srcdir)/../fbuffer/fbuffer.h
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'mkmf'
3
-
4
- have_func("rb_enc_raise", "ruby.h")
5
-
6
- # checking if String#-@ (str_uminus) dedupes... '
7
- begin
8
- a = -(%w(t e s t).join)
9
- b = -(%w(t e s t).join)
10
- if a.equal?(b)
11
- $CFLAGS << ' -DSTR_UMINUS_DEDUPE=1 '
12
- else
13
- $CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
14
- end
15
- rescue NoMethodError
16
- $CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
17
- end
18
-
19
- # checking if String#-@ (str_uminus) directly interns frozen strings... '
20
- begin
21
- s = rand.to_s.freeze
22
- if (-s).equal?(s) && (-s.dup).equal?(s)
23
- $CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=1 '
24
- else
25
- $CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
26
- end
27
- rescue NoMethodError
28
- $CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
29
- end
30
-
31
- create_makefile 'json/ext/parser'
@@ -1,2164 +0,0 @@
1
- /* This file is automatically generated from parser.rl by using ragel */
2
- #line 1 "parser.rl"
3
- #include "../fbuffer/fbuffer.h"
4
- #include "parser.h"
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
-
28
- /* unicode */
29
-
30
- static const signed char digit_values[256] = {
31
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
32
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
34
- -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
35
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36
- 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
37
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
38
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
39
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
40
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
41
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44
- -1, -1, -1, -1, -1, -1, -1
45
- };
46
-
47
- static UTF32 unescape_unicode(const unsigned char *p)
48
- {
49
- signed char b;
50
- UTF32 result = 0;
51
- b = digit_values[p[0]];
52
- if (b < 0) return UNI_REPLACEMENT_CHAR;
53
- result = (result << 4) | (unsigned char)b;
54
- b = digit_values[p[1]];
55
- if (b < 0) return UNI_REPLACEMENT_CHAR;
56
- result = (result << 4) | (unsigned char)b;
57
- b = digit_values[p[2]];
58
- if (b < 0) return UNI_REPLACEMENT_CHAR;
59
- result = (result << 4) | (unsigned char)b;
60
- b = digit_values[p[3]];
61
- if (b < 0) return UNI_REPLACEMENT_CHAR;
62
- result = (result << 4) | (unsigned char)b;
63
- return result;
64
- }
65
-
66
- static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
67
- {
68
- int len = 1;
69
- if (ch <= 0x7F) {
70
- buf[0] = (char) ch;
71
- } else if (ch <= 0x07FF) {
72
- buf[0] = (char) ((ch >> 6) | 0xC0);
73
- buf[1] = (char) ((ch & 0x3F) | 0x80);
74
- len++;
75
- } else if (ch <= 0xFFFF) {
76
- buf[0] = (char) ((ch >> 12) | 0xE0);
77
- buf[1] = (char) (((ch >> 6) & 0x3F) | 0x80);
78
- buf[2] = (char) ((ch & 0x3F) | 0x80);
79
- len += 2;
80
- } else if (ch <= 0x1fffff) {
81
- buf[0] =(char) ((ch >> 18) | 0xF0);
82
- buf[1] =(char) (((ch >> 12) & 0x3F) | 0x80);
83
- buf[2] =(char) (((ch >> 6) & 0x3F) | 0x80);
84
- buf[3] =(char) ((ch & 0x3F) | 0x80);
85
- len += 3;
86
- } else {
87
- buf[0] = '?';
88
- }
89
- return len;
90
- }
91
-
92
- static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
93
- static VALUE CNaN, CInfinity, CMinusInfinity;
94
- static VALUE cBigDecimal = Qundef;
95
-
96
- static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
97
- i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
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, i_freeze, i_uminus;
101
-
102
-
103
- #line 126 "parser.rl"
104
-
105
-
106
-
107
- #line 108 "parser.c"
108
- enum {JSON_object_start = 1};
109
- enum {JSON_object_first_final = 27};
110
- enum {JSON_object_error = 0};
111
-
112
- enum {JSON_object_en_main = 1};
113
-
114
-
115
- #line 168 "parser.rl"
116
-
117
-
118
- static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
119
- {
120
- int cs = EVIL;
121
- VALUE last_name = Qnil;
122
- VALUE object_class = json->object_class;
123
-
124
- if (json->max_nesting && current_nesting > json->max_nesting) {
125
- rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
126
- }
127
-
128
- *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
129
-
130
-
131
- #line 132 "parser.c"
132
- {
133
- cs = JSON_object_start;
134
- }
135
-
136
- #line 183 "parser.rl"
137
-
138
- #line 139 "parser.c"
139
- {
140
- if ( p == pe )
141
- goto _test_eof;
142
- switch ( cs )
143
- {
144
- case 1:
145
- if ( (*p) == 123 )
146
- goto st2;
147
- goto st0;
148
- st0:
149
- cs = 0;
150
- goto _out;
151
- st2:
152
- if ( ++p == pe )
153
- goto _test_eof2;
154
- case 2:
155
- switch( (*p) ) {
156
- case 13: goto st2;
157
- case 32: goto st2;
158
- case 34: goto tr2;
159
- case 47: goto st23;
160
- case 125: goto tr4;
161
- }
162
- if ( 9 <= (*p) && (*p) <= 10 )
163
- goto st2;
164
- goto st0;
165
- tr2:
166
- #line 150 "parser.rl"
167
- {
168
- char *np;
169
- json->parsing_name = 1;
170
- np = JSON_parse_string(json, p, pe, &last_name);
171
- json->parsing_name = 0;
172
- if (np == NULL) { p--; {p++; cs = 3; goto _out;} } else {p = (( np))-1;}
173
- }
174
- goto st3;
175
- st3:
176
- if ( ++p == pe )
177
- goto _test_eof3;
178
- case 3:
179
- #line 180 "parser.c"
180
- switch( (*p) ) {
181
- case 13: goto st3;
182
- case 32: goto st3;
183
- case 47: goto st4;
184
- case 58: goto st8;
185
- }
186
- if ( 9 <= (*p) && (*p) <= 10 )
187
- goto st3;
188
- goto st0;
189
- st4:
190
- if ( ++p == pe )
191
- goto _test_eof4;
192
- case 4:
193
- switch( (*p) ) {
194
- case 42: goto st5;
195
- case 47: goto st7;
196
- }
197
- goto st0;
198
- st5:
199
- if ( ++p == pe )
200
- goto _test_eof5;
201
- case 5:
202
- if ( (*p) == 42 )
203
- goto st6;
204
- goto st5;
205
- st6:
206
- if ( ++p == pe )
207
- goto _test_eof6;
208
- case 6:
209
- switch( (*p) ) {
210
- case 42: goto st6;
211
- case 47: goto st3;
212
- }
213
- goto st5;
214
- st7:
215
- if ( ++p == pe )
216
- goto _test_eof7;
217
- case 7:
218
- if ( (*p) == 10 )
219
- goto st3;
220
- goto st7;
221
- st8:
222
- if ( ++p == pe )
223
- goto _test_eof8;
224
- case 8:
225
- switch( (*p) ) {
226
- case 13: goto st8;
227
- case 32: goto st8;
228
- case 34: goto tr11;
229
- case 45: goto tr11;
230
- case 47: goto st19;
231
- case 73: goto tr11;
232
- case 78: goto tr11;
233
- case 91: goto tr11;
234
- case 102: goto tr11;
235
- case 110: goto tr11;
236
- case 116: goto tr11;
237
- case 123: goto tr11;
238
- }
239
- if ( (*p) > 10 ) {
240
- if ( 48 <= (*p) && (*p) <= 57 )
241
- goto tr11;
242
- } else if ( (*p) >= 9 )
243
- goto st8;
244
- goto st0;
245
- tr11:
246
- #line 134 "parser.rl"
247
- {
248
- VALUE v = Qnil;
249
- char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
250
- if (np == NULL) {
251
- p--; {p++; cs = 9; goto _out;}
252
- } else {
253
- if (NIL_P(json->object_class)) {
254
- OBJ_FREEZE(last_name);
255
- rb_hash_aset(*result, last_name, v);
256
- } else {
257
- rb_funcall(*result, i_aset, 2, last_name, v);
258
- }
259
- {p = (( np))-1;}
260
- }
261
- }
262
- goto st9;
263
- st9:
264
- if ( ++p == pe )
265
- goto _test_eof9;
266
- case 9:
267
- #line 268 "parser.c"
268
- switch( (*p) ) {
269
- case 13: goto st9;
270
- case 32: goto st9;
271
- case 44: goto st10;
272
- case 47: goto st15;
273
- case 125: goto tr4;
274
- }
275
- if ( 9 <= (*p) && (*p) <= 10 )
276
- goto st9;
277
- goto st0;
278
- st10:
279
- if ( ++p == pe )
280
- goto _test_eof10;
281
- case 10:
282
- switch( (*p) ) {
283
- case 13: goto st10;
284
- case 32: goto st10;
285
- case 34: goto tr2;
286
- case 47: goto st11;
287
- }
288
- if ( 9 <= (*p) && (*p) <= 10 )
289
- goto st10;
290
- goto st0;
291
- st11:
292
- if ( ++p == pe )
293
- goto _test_eof11;
294
- case 11:
295
- switch( (*p) ) {
296
- case 42: goto st12;
297
- case 47: goto st14;
298
- }
299
- goto st0;
300
- st12:
301
- if ( ++p == pe )
302
- goto _test_eof12;
303
- case 12:
304
- if ( (*p) == 42 )
305
- goto st13;
306
- goto st12;
307
- st13:
308
- if ( ++p == pe )
309
- goto _test_eof13;
310
- case 13:
311
- switch( (*p) ) {
312
- case 42: goto st13;
313
- case 47: goto st10;
314
- }
315
- goto st12;
316
- st14:
317
- if ( ++p == pe )
318
- goto _test_eof14;
319
- case 14:
320
- if ( (*p) == 10 )
321
- goto st10;
322
- goto st14;
323
- st15:
324
- if ( ++p == pe )
325
- goto _test_eof15;
326
- case 15:
327
- switch( (*p) ) {
328
- case 42: goto st16;
329
- case 47: goto st18;
330
- }
331
- goto st0;
332
- st16:
333
- if ( ++p == pe )
334
- goto _test_eof16;
335
- case 16:
336
- if ( (*p) == 42 )
337
- goto st17;
338
- goto st16;
339
- st17:
340
- if ( ++p == pe )
341
- goto _test_eof17;
342
- case 17:
343
- switch( (*p) ) {
344
- case 42: goto st17;
345
- case 47: goto st9;
346
- }
347
- goto st16;
348
- st18:
349
- if ( ++p == pe )
350
- goto _test_eof18;
351
- case 18:
352
- if ( (*p) == 10 )
353
- goto st9;
354
- goto st18;
355
- tr4:
356
- #line 158 "parser.rl"
357
- { p--; {p++; cs = 27; goto _out;} }
358
- goto st27;
359
- st27:
360
- if ( ++p == pe )
361
- goto _test_eof27;
362
- case 27:
363
- #line 364 "parser.c"
364
- goto st0;
365
- st19:
366
- if ( ++p == pe )
367
- goto _test_eof19;
368
- case 19:
369
- switch( (*p) ) {
370
- case 42: goto st20;
371
- case 47: goto st22;
372
- }
373
- goto st0;
374
- st20:
375
- if ( ++p == pe )
376
- goto _test_eof20;
377
- case 20:
378
- if ( (*p) == 42 )
379
- goto st21;
380
- goto st20;
381
- st21:
382
- if ( ++p == pe )
383
- goto _test_eof21;
384
- case 21:
385
- switch( (*p) ) {
386
- case 42: goto st21;
387
- case 47: goto st8;
388
- }
389
- goto st20;
390
- st22:
391
- if ( ++p == pe )
392
- goto _test_eof22;
393
- case 22:
394
- if ( (*p) == 10 )
395
- goto st8;
396
- goto st22;
397
- st23:
398
- if ( ++p == pe )
399
- goto _test_eof23;
400
- case 23:
401
- switch( (*p) ) {
402
- case 42: goto st24;
403
- case 47: goto st26;
404
- }
405
- goto st0;
406
- st24:
407
- if ( ++p == pe )
408
- goto _test_eof24;
409
- case 24:
410
- if ( (*p) == 42 )
411
- goto st25;
412
- goto st24;
413
- st25:
414
- if ( ++p == pe )
415
- goto _test_eof25;
416
- case 25:
417
- switch( (*p) ) {
418
- case 42: goto st25;
419
- case 47: goto st2;
420
- }
421
- goto st24;
422
- st26:
423
- if ( ++p == pe )
424
- goto _test_eof26;
425
- case 26:
426
- if ( (*p) == 10 )
427
- goto st2;
428
- goto st26;
429
- }
430
- _test_eof2: cs = 2; goto _test_eof;
431
- _test_eof3: cs = 3; goto _test_eof;
432
- _test_eof4: cs = 4; goto _test_eof;
433
- _test_eof5: cs = 5; goto _test_eof;
434
- _test_eof6: cs = 6; goto _test_eof;
435
- _test_eof7: cs = 7; goto _test_eof;
436
- _test_eof8: cs = 8; goto _test_eof;
437
- _test_eof9: cs = 9; goto _test_eof;
438
- _test_eof10: cs = 10; goto _test_eof;
439
- _test_eof11: cs = 11; goto _test_eof;
440
- _test_eof12: cs = 12; goto _test_eof;
441
- _test_eof13: cs = 13; goto _test_eof;
442
- _test_eof14: cs = 14; goto _test_eof;
443
- _test_eof15: cs = 15; goto _test_eof;
444
- _test_eof16: cs = 16; goto _test_eof;
445
- _test_eof17: cs = 17; goto _test_eof;
446
- _test_eof18: cs = 18; goto _test_eof;
447
- _test_eof27: cs = 27; goto _test_eof;
448
- _test_eof19: cs = 19; goto _test_eof;
449
- _test_eof20: cs = 20; goto _test_eof;
450
- _test_eof21: cs = 21; goto _test_eof;
451
- _test_eof22: cs = 22; goto _test_eof;
452
- _test_eof23: cs = 23; goto _test_eof;
453
- _test_eof24: cs = 24; goto _test_eof;
454
- _test_eof25: cs = 25; goto _test_eof;
455
- _test_eof26: cs = 26; goto _test_eof;
456
-
457
- _test_eof: {}
458
- _out: {}
459
- }
460
-
461
- #line 184 "parser.rl"
462
-
463
- if (cs >= JSON_object_first_final) {
464
- if (json->create_additions) {
465
- VALUE klassname;
466
- if (NIL_P(json->object_class)) {
467
- klassname = rb_hash_aref(*result, json->create_id);
468
- } else {
469
- klassname = rb_funcall(*result, i_aref, 1, json->create_id);
470
- }
471
- if (!NIL_P(klassname)) {
472
- VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
473
- if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
474
- *result = rb_funcall(klass, i_json_create, 1, *result);
475
- }
476
- }
477
- }
478
- return p + 1;
479
- } else {
480
- return NULL;
481
- }
482
- }
483
-
484
-
485
-
486
- #line 487 "parser.c"
487
- enum {JSON_value_start = 1};
488
- enum {JSON_value_first_final = 29};
489
- enum {JSON_value_error = 0};
490
-
491
- enum {JSON_value_en_main = 1};
492
-
493
-
494
- #line 284 "parser.rl"
495
-
496
-
497
- static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
498
- {
499
- int cs = EVIL;
500
-
501
-
502
- #line 503 "parser.c"
503
- {
504
- cs = JSON_value_start;
505
- }
506
-
507
- #line 291 "parser.rl"
508
-
509
- #line 510 "parser.c"
510
- {
511
- if ( p == pe )
512
- goto _test_eof;
513
- switch ( cs )
514
- {
515
- st1:
516
- if ( ++p == pe )
517
- goto _test_eof1;
518
- case 1:
519
- switch( (*p) ) {
520
- case 13: goto st1;
521
- case 32: goto st1;
522
- case 34: goto tr2;
523
- case 45: goto tr3;
524
- case 47: goto st6;
525
- case 73: goto st10;
526
- case 78: goto st17;
527
- case 91: goto tr7;
528
- case 102: goto st19;
529
- case 110: goto st23;
530
- case 116: goto st26;
531
- case 123: goto tr11;
532
- }
533
- if ( (*p) > 10 ) {
534
- if ( 48 <= (*p) && (*p) <= 57 )
535
- goto tr3;
536
- } else if ( (*p) >= 9 )
537
- goto st1;
538
- goto st0;
539
- st0:
540
- cs = 0;
541
- goto _out;
542
- tr2:
543
- #line 236 "parser.rl"
544
- {
545
- char *np = JSON_parse_string(json, p, pe, result);
546
- if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
547
- }
548
- goto st29;
549
- tr3:
550
- #line 241 "parser.rl"
551
- {
552
- char *np;
553
- if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
554
- if (json->allow_nan) {
555
- *result = CMinusInfinity;
556
- {p = (( p + 10))-1;}
557
- p--; {p++; cs = 29; goto _out;}
558
- } else {
559
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
560
- }
561
- }
562
- np = JSON_parse_float(json, p, pe, result);
563
- if (np != NULL) {p = (( np))-1;}
564
- np = JSON_parse_integer(json, p, pe, result);
565
- if (np != NULL) {p = (( np))-1;}
566
- p--; {p++; cs = 29; goto _out;}
567
- }
568
- goto st29;
569
- tr7:
570
- #line 259 "parser.rl"
571
- {
572
- char *np;
573
- np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
574
- if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
575
- }
576
- goto st29;
577
- tr11:
578
- #line 265 "parser.rl"
579
- {
580
- char *np;
581
- np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
582
- if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
583
- }
584
- goto st29;
585
- tr25:
586
- #line 229 "parser.rl"
587
- {
588
- if (json->allow_nan) {
589
- *result = CInfinity;
590
- } else {
591
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
592
- }
593
- }
594
- goto st29;
595
- tr27:
596
- #line 222 "parser.rl"
597
- {
598
- if (json->allow_nan) {
599
- *result = CNaN;
600
- } else {
601
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
602
- }
603
- }
604
- goto st29;
605
- tr31:
606
- #line 216 "parser.rl"
607
- {
608
- *result = Qfalse;
609
- }
610
- goto st29;
611
- tr34:
612
- #line 213 "parser.rl"
613
- {
614
- *result = Qnil;
615
- }
616
- goto st29;
617
- tr37:
618
- #line 219 "parser.rl"
619
- {
620
- *result = Qtrue;
621
- }
622
- goto st29;
623
- st29:
624
- if ( ++p == pe )
625
- goto _test_eof29;
626
- case 29:
627
- #line 271 "parser.rl"
628
- { p--; {p++; cs = 29; goto _out;} }
629
- #line 630 "parser.c"
630
- switch( (*p) ) {
631
- case 13: goto st29;
632
- case 32: goto st29;
633
- case 47: goto st2;
634
- }
635
- if ( 9 <= (*p) && (*p) <= 10 )
636
- goto st29;
637
- goto st0;
638
- st2:
639
- if ( ++p == pe )
640
- goto _test_eof2;
641
- case 2:
642
- switch( (*p) ) {
643
- case 42: goto st3;
644
- case 47: goto st5;
645
- }
646
- goto st0;
647
- st3:
648
- if ( ++p == pe )
649
- goto _test_eof3;
650
- case 3:
651
- if ( (*p) == 42 )
652
- goto st4;
653
- goto st3;
654
- st4:
655
- if ( ++p == pe )
656
- goto _test_eof4;
657
- case 4:
658
- switch( (*p) ) {
659
- case 42: goto st4;
660
- case 47: goto st29;
661
- }
662
- goto st3;
663
- st5:
664
- if ( ++p == pe )
665
- goto _test_eof5;
666
- case 5:
667
- if ( (*p) == 10 )
668
- goto st29;
669
- goto st5;
670
- st6:
671
- if ( ++p == pe )
672
- goto _test_eof6;
673
- case 6:
674
- switch( (*p) ) {
675
- case 42: goto st7;
676
- case 47: goto st9;
677
- }
678
- goto st0;
679
- st7:
680
- if ( ++p == pe )
681
- goto _test_eof7;
682
- case 7:
683
- if ( (*p) == 42 )
684
- goto st8;
685
- goto st7;
686
- st8:
687
- if ( ++p == pe )
688
- goto _test_eof8;
689
- case 8:
690
- switch( (*p) ) {
691
- case 42: goto st8;
692
- case 47: goto st1;
693
- }
694
- goto st7;
695
- st9:
696
- if ( ++p == pe )
697
- goto _test_eof9;
698
- case 9:
699
- if ( (*p) == 10 )
700
- goto st1;
701
- goto st9;
702
- st10:
703
- if ( ++p == pe )
704
- goto _test_eof10;
705
- case 10:
706
- if ( (*p) == 110 )
707
- goto st11;
708
- goto st0;
709
- st11:
710
- if ( ++p == pe )
711
- goto _test_eof11;
712
- case 11:
713
- if ( (*p) == 102 )
714
- goto st12;
715
- goto st0;
716
- st12:
717
- if ( ++p == pe )
718
- goto _test_eof12;
719
- case 12:
720
- if ( (*p) == 105 )
721
- goto st13;
722
- goto st0;
723
- st13:
724
- if ( ++p == pe )
725
- goto _test_eof13;
726
- case 13:
727
- if ( (*p) == 110 )
728
- goto st14;
729
- goto st0;
730
- st14:
731
- if ( ++p == pe )
732
- goto _test_eof14;
733
- case 14:
734
- if ( (*p) == 105 )
735
- goto st15;
736
- goto st0;
737
- st15:
738
- if ( ++p == pe )
739
- goto _test_eof15;
740
- case 15:
741
- if ( (*p) == 116 )
742
- goto st16;
743
- goto st0;
744
- st16:
745
- if ( ++p == pe )
746
- goto _test_eof16;
747
- case 16:
748
- if ( (*p) == 121 )
749
- goto tr25;
750
- goto st0;
751
- st17:
752
- if ( ++p == pe )
753
- goto _test_eof17;
754
- case 17:
755
- if ( (*p) == 97 )
756
- goto st18;
757
- goto st0;
758
- st18:
759
- if ( ++p == pe )
760
- goto _test_eof18;
761
- case 18:
762
- if ( (*p) == 78 )
763
- goto tr27;
764
- goto st0;
765
- st19:
766
- if ( ++p == pe )
767
- goto _test_eof19;
768
- case 19:
769
- if ( (*p) == 97 )
770
- goto st20;
771
- goto st0;
772
- st20:
773
- if ( ++p == pe )
774
- goto _test_eof20;
775
- case 20:
776
- if ( (*p) == 108 )
777
- goto st21;
778
- goto st0;
779
- st21:
780
- if ( ++p == pe )
781
- goto _test_eof21;
782
- case 21:
783
- if ( (*p) == 115 )
784
- goto st22;
785
- goto st0;
786
- st22:
787
- if ( ++p == pe )
788
- goto _test_eof22;
789
- case 22:
790
- if ( (*p) == 101 )
791
- goto tr31;
792
- goto st0;
793
- st23:
794
- if ( ++p == pe )
795
- goto _test_eof23;
796
- case 23:
797
- if ( (*p) == 117 )
798
- goto st24;
799
- goto st0;
800
- st24:
801
- if ( ++p == pe )
802
- goto _test_eof24;
803
- case 24:
804
- if ( (*p) == 108 )
805
- goto st25;
806
- goto st0;
807
- st25:
808
- if ( ++p == pe )
809
- goto _test_eof25;
810
- case 25:
811
- if ( (*p) == 108 )
812
- goto tr34;
813
- goto st0;
814
- st26:
815
- if ( ++p == pe )
816
- goto _test_eof26;
817
- case 26:
818
- if ( (*p) == 114 )
819
- goto st27;
820
- goto st0;
821
- st27:
822
- if ( ++p == pe )
823
- goto _test_eof27;
824
- case 27:
825
- if ( (*p) == 117 )
826
- goto st28;
827
- goto st0;
828
- st28:
829
- if ( ++p == pe )
830
- goto _test_eof28;
831
- case 28:
832
- if ( (*p) == 101 )
833
- goto tr37;
834
- goto st0;
835
- }
836
- _test_eof1: cs = 1; goto _test_eof;
837
- _test_eof29: cs = 29; goto _test_eof;
838
- _test_eof2: cs = 2; goto _test_eof;
839
- _test_eof3: cs = 3; goto _test_eof;
840
- _test_eof4: cs = 4; goto _test_eof;
841
- _test_eof5: cs = 5; goto _test_eof;
842
- _test_eof6: cs = 6; goto _test_eof;
843
- _test_eof7: cs = 7; goto _test_eof;
844
- _test_eof8: cs = 8; goto _test_eof;
845
- _test_eof9: cs = 9; goto _test_eof;
846
- _test_eof10: cs = 10; goto _test_eof;
847
- _test_eof11: cs = 11; goto _test_eof;
848
- _test_eof12: cs = 12; goto _test_eof;
849
- _test_eof13: cs = 13; goto _test_eof;
850
- _test_eof14: cs = 14; goto _test_eof;
851
- _test_eof15: cs = 15; goto _test_eof;
852
- _test_eof16: cs = 16; goto _test_eof;
853
- _test_eof17: cs = 17; goto _test_eof;
854
- _test_eof18: cs = 18; goto _test_eof;
855
- _test_eof19: cs = 19; goto _test_eof;
856
- _test_eof20: cs = 20; goto _test_eof;
857
- _test_eof21: cs = 21; goto _test_eof;
858
- _test_eof22: cs = 22; goto _test_eof;
859
- _test_eof23: cs = 23; goto _test_eof;
860
- _test_eof24: cs = 24; goto _test_eof;
861
- _test_eof25: cs = 25; goto _test_eof;
862
- _test_eof26: cs = 26; goto _test_eof;
863
- _test_eof27: cs = 27; goto _test_eof;
864
- _test_eof28: cs = 28; goto _test_eof;
865
-
866
- _test_eof: {}
867
- _out: {}
868
- }
869
-
870
- #line 292 "parser.rl"
871
-
872
- if (json->freeze) {
873
- OBJ_FREEZE(*result);
874
- }
875
-
876
- if (cs >= JSON_value_first_final) {
877
- return p;
878
- } else {
879
- return NULL;
880
- }
881
- }
882
-
883
-
884
- #line 885 "parser.c"
885
- enum {JSON_integer_start = 1};
886
- enum {JSON_integer_first_final = 3};
887
- enum {JSON_integer_error = 0};
888
-
889
- enum {JSON_integer_en_main = 1};
890
-
891
-
892
- #line 312 "parser.rl"
893
-
894
-
895
- static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
896
- {
897
- int cs = EVIL;
898
-
899
-
900
- #line 901 "parser.c"
901
- {
902
- cs = JSON_integer_start;
903
- }
904
-
905
- #line 319 "parser.rl"
906
- json->memo = p;
907
-
908
- #line 909 "parser.c"
909
- {
910
- if ( p == pe )
911
- goto _test_eof;
912
- switch ( cs )
913
- {
914
- case 1:
915
- switch( (*p) ) {
916
- case 45: goto st2;
917
- case 48: goto st3;
918
- }
919
- if ( 49 <= (*p) && (*p) <= 57 )
920
- goto st5;
921
- goto st0;
922
- st0:
923
- cs = 0;
924
- goto _out;
925
- st2:
926
- if ( ++p == pe )
927
- goto _test_eof2;
928
- case 2:
929
- if ( (*p) == 48 )
930
- goto st3;
931
- if ( 49 <= (*p) && (*p) <= 57 )
932
- goto st5;
933
- goto st0;
934
- st3:
935
- if ( ++p == pe )
936
- goto _test_eof3;
937
- case 3:
938
- if ( 48 <= (*p) && (*p) <= 57 )
939
- goto st0;
940
- goto tr4;
941
- tr4:
942
- #line 309 "parser.rl"
943
- { p--; {p++; cs = 4; goto _out;} }
944
- goto st4;
945
- st4:
946
- if ( ++p == pe )
947
- goto _test_eof4;
948
- case 4:
949
- #line 950 "parser.c"
950
- goto st0;
951
- st5:
952
- if ( ++p == pe )
953
- goto _test_eof5;
954
- case 5:
955
- if ( 48 <= (*p) && (*p) <= 57 )
956
- goto st5;
957
- goto tr4;
958
- }
959
- _test_eof2: cs = 2; goto _test_eof;
960
- _test_eof3: cs = 3; goto _test_eof;
961
- _test_eof4: cs = 4; goto _test_eof;
962
- _test_eof5: cs = 5; goto _test_eof;
963
-
964
- _test_eof: {}
965
- _out: {}
966
- }
967
-
968
- #line 321 "parser.rl"
969
-
970
- if (cs >= JSON_integer_first_final) {
971
- long len = p - json->memo;
972
- fbuffer_clear(json->fbuffer);
973
- fbuffer_append(json->fbuffer, json->memo, len);
974
- fbuffer_append_char(json->fbuffer, '\0');
975
- *result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
976
- return p + 1;
977
- } else {
978
- return NULL;
979
- }
980
- }
981
-
982
-
983
- #line 984 "parser.c"
984
- enum {JSON_float_start = 1};
985
- enum {JSON_float_first_final = 8};
986
- enum {JSON_float_error = 0};
987
-
988
- enum {JSON_float_en_main = 1};
989
-
990
-
991
- #line 346 "parser.rl"
992
-
993
-
994
- static int is_bigdecimal_class(VALUE obj)
995
- {
996
- if (cBigDecimal == Qundef) {
997
- if (rb_const_defined(rb_cObject, i_BigDecimal)) {
998
- cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal);
999
- }
1000
- else {
1001
- return 0;
1002
- }
1003
- }
1004
- return obj == cBigDecimal;
1005
- }
1006
-
1007
- static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
1008
- {
1009
- int cs = EVIL;
1010
-
1011
-
1012
- #line 1013 "parser.c"
1013
- {
1014
- cs = JSON_float_start;
1015
- }
1016
-
1017
- #line 366 "parser.rl"
1018
- json->memo = p;
1019
-
1020
- #line 1021 "parser.c"
1021
- {
1022
- if ( p == pe )
1023
- goto _test_eof;
1024
- switch ( cs )
1025
- {
1026
- case 1:
1027
- switch( (*p) ) {
1028
- case 45: goto st2;
1029
- case 48: goto st3;
1030
- }
1031
- if ( 49 <= (*p) && (*p) <= 57 )
1032
- goto st7;
1033
- goto st0;
1034
- st0:
1035
- cs = 0;
1036
- goto _out;
1037
- st2:
1038
- if ( ++p == pe )
1039
- goto _test_eof2;
1040
- case 2:
1041
- if ( (*p) == 48 )
1042
- goto st3;
1043
- if ( 49 <= (*p) && (*p) <= 57 )
1044
- goto st7;
1045
- goto st0;
1046
- st3:
1047
- if ( ++p == pe )
1048
- goto _test_eof3;
1049
- case 3:
1050
- switch( (*p) ) {
1051
- case 46: goto st4;
1052
- case 69: goto st5;
1053
- case 101: goto st5;
1054
- }
1055
- goto st0;
1056
- st4:
1057
- if ( ++p == pe )
1058
- goto _test_eof4;
1059
- case 4:
1060
- if ( 48 <= (*p) && (*p) <= 57 )
1061
- goto st8;
1062
- goto st0;
1063
- st8:
1064
- if ( ++p == pe )
1065
- goto _test_eof8;
1066
- case 8:
1067
- switch( (*p) ) {
1068
- case 69: goto st5;
1069
- case 101: goto st5;
1070
- }
1071
- if ( (*p) > 46 ) {
1072
- if ( 48 <= (*p) && (*p) <= 57 )
1073
- goto st8;
1074
- } else if ( (*p) >= 45 )
1075
- goto st0;
1076
- goto tr9;
1077
- tr9:
1078
- #line 340 "parser.rl"
1079
- { p--; {p++; cs = 9; goto _out;} }
1080
- goto st9;
1081
- st9:
1082
- if ( ++p == pe )
1083
- goto _test_eof9;
1084
- case 9:
1085
- #line 1086 "parser.c"
1086
- goto st0;
1087
- st5:
1088
- if ( ++p == pe )
1089
- goto _test_eof5;
1090
- case 5:
1091
- switch( (*p) ) {
1092
- case 43: goto st6;
1093
- case 45: goto st6;
1094
- }
1095
- if ( 48 <= (*p) && (*p) <= 57 )
1096
- goto st10;
1097
- goto st0;
1098
- st6:
1099
- if ( ++p == pe )
1100
- goto _test_eof6;
1101
- case 6:
1102
- if ( 48 <= (*p) && (*p) <= 57 )
1103
- goto st10;
1104
- goto st0;
1105
- st10:
1106
- if ( ++p == pe )
1107
- goto _test_eof10;
1108
- case 10:
1109
- switch( (*p) ) {
1110
- case 69: goto st0;
1111
- case 101: goto st0;
1112
- }
1113
- if ( (*p) > 46 ) {
1114
- if ( 48 <= (*p) && (*p) <= 57 )
1115
- goto st10;
1116
- } else if ( (*p) >= 45 )
1117
- goto st0;
1118
- goto tr9;
1119
- st7:
1120
- if ( ++p == pe )
1121
- goto _test_eof7;
1122
- case 7:
1123
- switch( (*p) ) {
1124
- case 46: goto st4;
1125
- case 69: goto st5;
1126
- case 101: goto st5;
1127
- }
1128
- if ( 48 <= (*p) && (*p) <= 57 )
1129
- goto st7;
1130
- goto st0;
1131
- }
1132
- _test_eof2: cs = 2; goto _test_eof;
1133
- _test_eof3: cs = 3; goto _test_eof;
1134
- _test_eof4: cs = 4; goto _test_eof;
1135
- _test_eof8: cs = 8; goto _test_eof;
1136
- _test_eof9: cs = 9; goto _test_eof;
1137
- _test_eof5: cs = 5; goto _test_eof;
1138
- _test_eof6: cs = 6; goto _test_eof;
1139
- _test_eof10: cs = 10; goto _test_eof;
1140
- _test_eof7: cs = 7; goto _test_eof;
1141
-
1142
- _test_eof: {}
1143
- _out: {}
1144
- }
1145
-
1146
- #line 368 "parser.rl"
1147
-
1148
- if (cs >= JSON_float_first_final) {
1149
- long len = p - json->memo;
1150
- fbuffer_clear(json->fbuffer);
1151
- fbuffer_append(json->fbuffer, json->memo, len);
1152
- fbuffer_append_char(json->fbuffer, '\0');
1153
- if (NIL_P(json->decimal_class)) {
1154
- *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
1155
- } else {
1156
- VALUE text;
1157
- text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
1158
- if (is_bigdecimal_class(json->decimal_class)) {
1159
- *result = rb_funcall(Qnil, i_BigDecimal, 1, text);
1160
- } else {
1161
- *result = rb_funcall(json->decimal_class, i_new, 1, text);
1162
- }
1163
- }
1164
- return p + 1;
1165
- } else {
1166
- return NULL;
1167
- }
1168
- }
1169
-
1170
-
1171
-
1172
- #line 1173 "parser.c"
1173
- enum {JSON_array_start = 1};
1174
- enum {JSON_array_first_final = 17};
1175
- enum {JSON_array_error = 0};
1176
-
1177
- enum {JSON_array_en_main = 1};
1178
-
1179
-
1180
- #line 421 "parser.rl"
1181
-
1182
-
1183
- static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
1184
- {
1185
- int cs = EVIL;
1186
- VALUE array_class = json->array_class;
1187
-
1188
- if (json->max_nesting && current_nesting > json->max_nesting) {
1189
- rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
1190
- }
1191
- *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
1192
-
1193
-
1194
- #line 1195 "parser.c"
1195
- {
1196
- cs = JSON_array_start;
1197
- }
1198
-
1199
- #line 434 "parser.rl"
1200
-
1201
- #line 1202 "parser.c"
1202
- {
1203
- if ( p == pe )
1204
- goto _test_eof;
1205
- switch ( cs )
1206
- {
1207
- case 1:
1208
- if ( (*p) == 91 )
1209
- goto st2;
1210
- goto st0;
1211
- st0:
1212
- cs = 0;
1213
- goto _out;
1214
- st2:
1215
- if ( ++p == pe )
1216
- goto _test_eof2;
1217
- case 2:
1218
- switch( (*p) ) {
1219
- case 13: goto st2;
1220
- case 32: goto st2;
1221
- case 34: goto tr2;
1222
- case 45: goto tr2;
1223
- case 47: goto st13;
1224
- case 73: goto tr2;
1225
- case 78: goto tr2;
1226
- case 91: goto tr2;
1227
- case 93: goto tr4;
1228
- case 102: goto tr2;
1229
- case 110: goto tr2;
1230
- case 116: goto tr2;
1231
- case 123: goto tr2;
1232
- }
1233
- if ( (*p) > 10 ) {
1234
- if ( 48 <= (*p) && (*p) <= 57 )
1235
- goto tr2;
1236
- } else if ( (*p) >= 9 )
1237
- goto st2;
1238
- goto st0;
1239
- tr2:
1240
- #line 398 "parser.rl"
1241
- {
1242
- VALUE v = Qnil;
1243
- char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
1244
- if (np == NULL) {
1245
- p--; {p++; cs = 3; goto _out;}
1246
- } else {
1247
- if (NIL_P(json->array_class)) {
1248
- rb_ary_push(*result, v);
1249
- } else {
1250
- rb_funcall(*result, i_leftshift, 1, v);
1251
- }
1252
- {p = (( np))-1;}
1253
- }
1254
- }
1255
- goto st3;
1256
- st3:
1257
- if ( ++p == pe )
1258
- goto _test_eof3;
1259
- case 3:
1260
- #line 1261 "parser.c"
1261
- switch( (*p) ) {
1262
- case 13: goto st3;
1263
- case 32: goto st3;
1264
- case 44: goto st4;
1265
- case 47: goto st9;
1266
- case 93: goto tr4;
1267
- }
1268
- if ( 9 <= (*p) && (*p) <= 10 )
1269
- goto st3;
1270
- goto st0;
1271
- st4:
1272
- if ( ++p == pe )
1273
- goto _test_eof4;
1274
- case 4:
1275
- switch( (*p) ) {
1276
- case 13: goto st4;
1277
- case 32: goto st4;
1278
- case 34: goto tr2;
1279
- case 45: goto tr2;
1280
- case 47: goto st5;
1281
- case 73: goto tr2;
1282
- case 78: goto tr2;
1283
- case 91: goto tr2;
1284
- case 102: goto tr2;
1285
- case 110: goto tr2;
1286
- case 116: goto tr2;
1287
- case 123: goto tr2;
1288
- }
1289
- if ( (*p) > 10 ) {
1290
- if ( 48 <= (*p) && (*p) <= 57 )
1291
- goto tr2;
1292
- } else if ( (*p) >= 9 )
1293
- goto st4;
1294
- goto st0;
1295
- st5:
1296
- if ( ++p == pe )
1297
- goto _test_eof5;
1298
- case 5:
1299
- switch( (*p) ) {
1300
- case 42: goto st6;
1301
- case 47: goto st8;
1302
- }
1303
- goto st0;
1304
- st6:
1305
- if ( ++p == pe )
1306
- goto _test_eof6;
1307
- case 6:
1308
- if ( (*p) == 42 )
1309
- goto st7;
1310
- goto st6;
1311
- st7:
1312
- if ( ++p == pe )
1313
- goto _test_eof7;
1314
- case 7:
1315
- switch( (*p) ) {
1316
- case 42: goto st7;
1317
- case 47: goto st4;
1318
- }
1319
- goto st6;
1320
- st8:
1321
- if ( ++p == pe )
1322
- goto _test_eof8;
1323
- case 8:
1324
- if ( (*p) == 10 )
1325
- goto st4;
1326
- goto st8;
1327
- st9:
1328
- if ( ++p == pe )
1329
- goto _test_eof9;
1330
- case 9:
1331
- switch( (*p) ) {
1332
- case 42: goto st10;
1333
- case 47: goto st12;
1334
- }
1335
- goto st0;
1336
- st10:
1337
- if ( ++p == pe )
1338
- goto _test_eof10;
1339
- case 10:
1340
- if ( (*p) == 42 )
1341
- goto st11;
1342
- goto st10;
1343
- st11:
1344
- if ( ++p == pe )
1345
- goto _test_eof11;
1346
- case 11:
1347
- switch( (*p) ) {
1348
- case 42: goto st11;
1349
- case 47: goto st3;
1350
- }
1351
- goto st10;
1352
- st12:
1353
- if ( ++p == pe )
1354
- goto _test_eof12;
1355
- case 12:
1356
- if ( (*p) == 10 )
1357
- goto st3;
1358
- goto st12;
1359
- tr4:
1360
- #line 413 "parser.rl"
1361
- { p--; {p++; cs = 17; goto _out;} }
1362
- goto st17;
1363
- st17:
1364
- if ( ++p == pe )
1365
- goto _test_eof17;
1366
- case 17:
1367
- #line 1368 "parser.c"
1368
- goto st0;
1369
- st13:
1370
- if ( ++p == pe )
1371
- goto _test_eof13;
1372
- case 13:
1373
- switch( (*p) ) {
1374
- case 42: goto st14;
1375
- case 47: goto st16;
1376
- }
1377
- goto st0;
1378
- st14:
1379
- if ( ++p == pe )
1380
- goto _test_eof14;
1381
- case 14:
1382
- if ( (*p) == 42 )
1383
- goto st15;
1384
- goto st14;
1385
- st15:
1386
- if ( ++p == pe )
1387
- goto _test_eof15;
1388
- case 15:
1389
- switch( (*p) ) {
1390
- case 42: goto st15;
1391
- case 47: goto st2;
1392
- }
1393
- goto st14;
1394
- st16:
1395
- if ( ++p == pe )
1396
- goto _test_eof16;
1397
- case 16:
1398
- if ( (*p) == 10 )
1399
- goto st2;
1400
- goto st16;
1401
- }
1402
- _test_eof2: cs = 2; goto _test_eof;
1403
- _test_eof3: cs = 3; goto _test_eof;
1404
- _test_eof4: cs = 4; goto _test_eof;
1405
- _test_eof5: cs = 5; goto _test_eof;
1406
- _test_eof6: cs = 6; goto _test_eof;
1407
- _test_eof7: cs = 7; goto _test_eof;
1408
- _test_eof8: cs = 8; goto _test_eof;
1409
- _test_eof9: cs = 9; goto _test_eof;
1410
- _test_eof10: cs = 10; goto _test_eof;
1411
- _test_eof11: cs = 11; goto _test_eof;
1412
- _test_eof12: cs = 12; goto _test_eof;
1413
- _test_eof17: cs = 17; goto _test_eof;
1414
- _test_eof13: cs = 13; goto _test_eof;
1415
- _test_eof14: cs = 14; goto _test_eof;
1416
- _test_eof15: cs = 15; goto _test_eof;
1417
- _test_eof16: cs = 16; goto _test_eof;
1418
-
1419
- _test_eof: {}
1420
- _out: {}
1421
- }
1422
-
1423
- #line 435 "parser.rl"
1424
-
1425
- if(cs >= JSON_array_first_final) {
1426
- return p + 1;
1427
- } else {
1428
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1429
- return NULL;
1430
- }
1431
- }
1432
-
1433
- static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1434
- {
1435
- char *p = string, *pe = string, *unescape;
1436
- int unescape_len;
1437
- char buf[4];
1438
-
1439
- while (pe < stringEnd) {
1440
- if (*pe == '\\') {
1441
- unescape = (char *) "?";
1442
- unescape_len = 1;
1443
- if (pe > p) rb_str_buf_cat(result, p, pe - p);
1444
- switch (*++pe) {
1445
- case 'n':
1446
- unescape = (char *) "\n";
1447
- break;
1448
- case 'r':
1449
- unescape = (char *) "\r";
1450
- break;
1451
- case 't':
1452
- unescape = (char *) "\t";
1453
- break;
1454
- case '"':
1455
- unescape = (char *) "\"";
1456
- break;
1457
- case '\\':
1458
- unescape = (char *) "\\";
1459
- break;
1460
- case 'b':
1461
- unescape = (char *) "\b";
1462
- break;
1463
- case 'f':
1464
- unescape = (char *) "\f";
1465
- break;
1466
- case 'u':
1467
- if (pe > stringEnd - 4) {
1468
- rb_enc_raise(
1469
- EXC_ENCODING eParserError,
1470
- "%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
1471
- );
1472
- } else {
1473
- UTF32 ch = unescape_unicode((unsigned char *) ++pe);
1474
- pe += 3;
1475
- if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
1476
- pe++;
1477
- if (pe > stringEnd - 6) {
1478
- rb_enc_raise(
1479
- EXC_ENCODING eParserError,
1480
- "%u: incomplete surrogate pair at '%s'", __LINE__, p
1481
- );
1482
- }
1483
- if (pe[0] == '\\' && pe[1] == 'u') {
1484
- UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
1485
- ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
1486
- | (sur & 0x3FF));
1487
- pe += 5;
1488
- } else {
1489
- unescape = (char *) "?";
1490
- break;
1491
- }
1492
- }
1493
- unescape_len = convert_UTF32_to_UTF8(buf, ch);
1494
- unescape = buf;
1495
- }
1496
- break;
1497
- default:
1498
- p = pe;
1499
- continue;
1500
- }
1501
- rb_str_buf_cat(result, unescape, unescape_len);
1502
- p = ++pe;
1503
- } else {
1504
- pe++;
1505
- }
1506
- }
1507
- rb_str_buf_cat(result, p, pe - p);
1508
- return result;
1509
- }
1510
-
1511
-
1512
- #line 1513 "parser.c"
1513
- enum {JSON_string_start = 1};
1514
- enum {JSON_string_first_final = 8};
1515
- enum {JSON_string_error = 0};
1516
-
1517
- enum {JSON_string_en_main = 1};
1518
-
1519
-
1520
- #line 542 "parser.rl"
1521
-
1522
-
1523
- static int
1524
- match_i(VALUE regexp, VALUE klass, VALUE memo)
1525
- {
1526
- if (regexp == Qundef) return ST_STOP;
1527
- if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) &&
1528
- RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) {
1529
- rb_ary_push(memo, klass);
1530
- return ST_STOP;
1531
- }
1532
- return ST_CONTINUE;
1533
- }
1534
-
1535
- static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
1536
- {
1537
- int cs = EVIL;
1538
- VALUE match_string;
1539
-
1540
- *result = rb_str_buf_new(0);
1541
-
1542
- #line 1543 "parser.c"
1543
- {
1544
- cs = JSON_string_start;
1545
- }
1546
-
1547
- #line 563 "parser.rl"
1548
- json->memo = p;
1549
-
1550
- #line 1551 "parser.c"
1551
- {
1552
- if ( p == pe )
1553
- goto _test_eof;
1554
- switch ( cs )
1555
- {
1556
- case 1:
1557
- if ( (*p) == 34 )
1558
- goto st2;
1559
- goto st0;
1560
- st0:
1561
- cs = 0;
1562
- goto _out;
1563
- st2:
1564
- if ( ++p == pe )
1565
- goto _test_eof2;
1566
- case 2:
1567
- switch( (*p) ) {
1568
- case 34: goto tr2;
1569
- case 92: goto st3;
1570
- }
1571
- if ( 0 <= (signed char)(*p) && (*p) <= 31 )
1572
- goto st0;
1573
- goto st2;
1574
- tr2:
1575
- #line 528 "parser.rl"
1576
- {
1577
- *result = json_string_unescape(*result, json->memo + 1, p);
1578
- if (NIL_P(*result)) {
1579
- p--;
1580
- {p++; cs = 8; goto _out;}
1581
- } else {
1582
- FORCE_UTF8(*result);
1583
- {p = (( p + 1))-1;}
1584
- }
1585
- }
1586
- #line 539 "parser.rl"
1587
- { p--; {p++; cs = 8; goto _out;} }
1588
- goto st8;
1589
- st8:
1590
- if ( ++p == pe )
1591
- goto _test_eof8;
1592
- case 8:
1593
- #line 1594 "parser.c"
1594
- goto st0;
1595
- st3:
1596
- if ( ++p == pe )
1597
- goto _test_eof3;
1598
- case 3:
1599
- if ( (*p) == 117 )
1600
- goto st4;
1601
- if ( 0 <= (signed char)(*p) && (*p) <= 31 )
1602
- goto st0;
1603
- goto st2;
1604
- st4:
1605
- if ( ++p == pe )
1606
- goto _test_eof4;
1607
- case 4:
1608
- if ( (*p) < 65 ) {
1609
- if ( 48 <= (*p) && (*p) <= 57 )
1610
- goto st5;
1611
- } else if ( (*p) > 70 ) {
1612
- if ( 97 <= (*p) && (*p) <= 102 )
1613
- goto st5;
1614
- } else
1615
- goto st5;
1616
- goto st0;
1617
- st5:
1618
- if ( ++p == pe )
1619
- goto _test_eof5;
1620
- case 5:
1621
- if ( (*p) < 65 ) {
1622
- if ( 48 <= (*p) && (*p) <= 57 )
1623
- goto st6;
1624
- } else if ( (*p) > 70 ) {
1625
- if ( 97 <= (*p) && (*p) <= 102 )
1626
- goto st6;
1627
- } else
1628
- goto st6;
1629
- goto st0;
1630
- st6:
1631
- if ( ++p == pe )
1632
- goto _test_eof6;
1633
- case 6:
1634
- if ( (*p) < 65 ) {
1635
- if ( 48 <= (*p) && (*p) <= 57 )
1636
- goto st7;
1637
- } else if ( (*p) > 70 ) {
1638
- if ( 97 <= (*p) && (*p) <= 102 )
1639
- goto st7;
1640
- } else
1641
- goto st7;
1642
- goto st0;
1643
- st7:
1644
- if ( ++p == pe )
1645
- goto _test_eof7;
1646
- case 7:
1647
- if ( (*p) < 65 ) {
1648
- if ( 48 <= (*p) && (*p) <= 57 )
1649
- goto st2;
1650
- } else if ( (*p) > 70 ) {
1651
- if ( 97 <= (*p) && (*p) <= 102 )
1652
- goto st2;
1653
- } else
1654
- goto st2;
1655
- goto st0;
1656
- }
1657
- _test_eof2: cs = 2; goto _test_eof;
1658
- _test_eof8: cs = 8; goto _test_eof;
1659
- _test_eof3: cs = 3; goto _test_eof;
1660
- _test_eof4: cs = 4; goto _test_eof;
1661
- _test_eof5: cs = 5; goto _test_eof;
1662
- _test_eof6: cs = 6; goto _test_eof;
1663
- _test_eof7: cs = 7; goto _test_eof;
1664
-
1665
- _test_eof: {}
1666
- _out: {}
1667
- }
1668
-
1669
- #line 565 "parser.rl"
1670
-
1671
- if (json->create_additions && RTEST(match_string = json->match_string)) {
1672
- VALUE klass;
1673
- VALUE memo = rb_ary_new2(2);
1674
- rb_ary_push(memo, *result);
1675
- rb_hash_foreach(match_string, match_i, memo);
1676
- klass = rb_ary_entry(memo, 1);
1677
- if (RTEST(klass)) {
1678
- *result = rb_funcall(klass, i_json_create, 1, *result);
1679
- }
1680
- }
1681
-
1682
- if (json->symbolize_names && json->parsing_name) {
1683
- *result = rb_str_intern(*result);
1684
- } else if (RB_TYPE_P(*result, T_STRING)) {
1685
- # if STR_UMINUS_DEDUPE_FROZEN
1686
- if (json->freeze) {
1687
- // Starting from MRI 2.8 it is preferable to freeze the string
1688
- // before deduplication so that it can be interned directly
1689
- // otherwise it would be duplicated first which is wasteful.
1690
- *result = rb_funcall(rb_str_freeze(*result), i_uminus, 0);
1691
- }
1692
- # elif STR_UMINUS_DEDUPE
1693
- if (json->freeze) {
1694
- // MRI 2.5 and older do not deduplicate strings that are already
1695
- // frozen.
1696
- *result = rb_funcall(*result, i_uminus, 0);
1697
- }
1698
- # else
1699
- rb_str_resize(*result, RSTRING_LEN(*result));
1700
- # endif
1701
- }
1702
- if (cs >= JSON_string_first_final) {
1703
- return p + 1;
1704
- } else {
1705
- return NULL;
1706
- }
1707
- }
1708
-
1709
- /*
1710
- * Document-class: JSON::Ext::Parser
1711
- *
1712
- * This is the JSON parser implemented as a C extension. It can be configured
1713
- * to be used by setting
1714
- *
1715
- * JSON.parser = JSON::Ext::Parser
1716
- *
1717
- * with the method parser= in JSON.
1718
- *
1719
- */
1720
-
1721
- static VALUE convert_encoding(VALUE source)
1722
- {
1723
- #ifdef HAVE_RUBY_ENCODING_H
1724
- rb_encoding *enc = rb_enc_get(source);
1725
- if (enc == rb_ascii8bit_encoding()) {
1726
- if (OBJ_FROZEN(source)) {
1727
- source = rb_str_dup(source);
1728
- }
1729
- FORCE_UTF8(source);
1730
- } else {
1731
- source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
1732
- }
1733
- #endif
1734
- return source;
1735
- }
1736
-
1737
- /*
1738
- * call-seq: new(source, opts => {})
1739
- *
1740
- * Creates a new JSON::Ext::Parser instance for the string _source_.
1741
- *
1742
- * Creates a new JSON::Ext::Parser instance for the string _source_.
1743
- *
1744
- * It will be configured by the _opts_ hash. _opts_ can have the following
1745
- * keys:
1746
- *
1747
- * _opts_ can have the following keys:
1748
- * * *max_nesting*: The maximum depth of nesting allowed in the parsed data
1749
- * structures. Disable depth checking with :max_nesting => false|nil|0, it
1750
- * defaults to 100.
1751
- * * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
1752
- * defiance of RFC 4627 to be parsed by the Parser. This option defaults to
1753
- * false.
1754
- * * *symbolize_names*: If set to true, returns symbols for the names
1755
- * (keys) in a JSON object. Otherwise strings are returned, which is
1756
- * also the default. It's not possible to use this option in
1757
- * conjunction with the *create_additions* option.
1758
- * * *create_additions*: If set to false, the Parser doesn't create
1759
- * additions even if a matching class and create_id was found. This option
1760
- * defaults to false.
1761
- * * *object_class*: Defaults to Hash
1762
- * * *array_class*: Defaults to Array
1763
- */
1764
- static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1765
- {
1766
- VALUE source, opts;
1767
- GET_PARSER_INIT;
1768
-
1769
- if (json->Vsource) {
1770
- rb_raise(rb_eTypeError, "already initialized instance");
1771
- }
1772
- #ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1773
- rb_scan_args(argc, argv, "1:", &source, &opts);
1774
- #else
1775
- rb_scan_args(argc, argv, "11", &source, &opts);
1776
- #endif
1777
- if (!NIL_P(opts)) {
1778
- #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1779
- opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
1780
- if (NIL_P(opts)) {
1781
- rb_raise(rb_eArgError, "opts needs to be like a hash");
1782
- } else {
1783
- #endif
1784
- VALUE tmp = ID2SYM(i_max_nesting);
1785
- if (option_given_p(opts, tmp)) {
1786
- VALUE max_nesting = rb_hash_aref(opts, tmp);
1787
- if (RTEST(max_nesting)) {
1788
- Check_Type(max_nesting, T_FIXNUM);
1789
- json->max_nesting = FIX2INT(max_nesting);
1790
- } else {
1791
- json->max_nesting = 0;
1792
- }
1793
- } else {
1794
- json->max_nesting = 100;
1795
- }
1796
- tmp = ID2SYM(i_allow_nan);
1797
- if (option_given_p(opts, tmp)) {
1798
- json->allow_nan = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1799
- } else {
1800
- json->allow_nan = 0;
1801
- }
1802
- tmp = ID2SYM(i_symbolize_names);
1803
- if (option_given_p(opts, tmp)) {
1804
- json->symbolize_names = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1805
- } else {
1806
- json->symbolize_names = 0;
1807
- }
1808
- tmp = ID2SYM(i_freeze);
1809
- if (option_given_p(opts, tmp)) {
1810
- json->freeze = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1811
- } else {
1812
- json->freeze = 0;
1813
- }
1814
- tmp = ID2SYM(i_create_additions);
1815
- if (option_given_p(opts, tmp)) {
1816
- json->create_additions = RTEST(rb_hash_aref(opts, tmp));
1817
- } else {
1818
- json->create_additions = 0;
1819
- }
1820
- if (json->symbolize_names && json->create_additions) {
1821
- rb_raise(rb_eArgError,
1822
- "options :symbolize_names and :create_additions cannot be "
1823
- " used in conjunction");
1824
- }
1825
- tmp = ID2SYM(i_create_id);
1826
- if (option_given_p(opts, tmp)) {
1827
- json->create_id = rb_hash_aref(opts, tmp);
1828
- } else {
1829
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
1830
- }
1831
- tmp = ID2SYM(i_object_class);
1832
- if (option_given_p(opts, tmp)) {
1833
- json->object_class = rb_hash_aref(opts, tmp);
1834
- } else {
1835
- json->object_class = Qnil;
1836
- }
1837
- tmp = ID2SYM(i_array_class);
1838
- if (option_given_p(opts, tmp)) {
1839
- json->array_class = rb_hash_aref(opts, tmp);
1840
- } else {
1841
- json->array_class = Qnil;
1842
- }
1843
- tmp = ID2SYM(i_decimal_class);
1844
- if (option_given_p(opts, tmp)) {
1845
- json->decimal_class = rb_hash_aref(opts, tmp);
1846
- } else {
1847
- json->decimal_class = Qnil;
1848
- }
1849
- tmp = ID2SYM(i_match_string);
1850
- if (option_given_p(opts, tmp)) {
1851
- VALUE match_string = rb_hash_aref(opts, tmp);
1852
- json->match_string = RTEST(match_string) ? match_string : Qnil;
1853
- } else {
1854
- json->match_string = Qnil;
1855
- }
1856
- #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1857
- }
1858
- #endif
1859
- } else {
1860
- json->max_nesting = 100;
1861
- json->allow_nan = 0;
1862
- json->create_additions = 0;
1863
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
1864
- json->object_class = Qnil;
1865
- json->array_class = Qnil;
1866
- json->decimal_class = Qnil;
1867
- }
1868
- source = convert_encoding(StringValue(source));
1869
- StringValue(source);
1870
- json->len = RSTRING_LEN(source);
1871
- json->source = RSTRING_PTR(source);;
1872
- json->Vsource = source;
1873
- return self;
1874
- }
1875
-
1876
-
1877
- #line 1878 "parser.c"
1878
- enum {JSON_start = 1};
1879
- enum {JSON_first_final = 10};
1880
- enum {JSON_error = 0};
1881
-
1882
- enum {JSON_en_main = 1};
1883
-
1884
-
1885
- #line 786 "parser.rl"
1886
-
1887
-
1888
- /*
1889
- * call-seq: parse()
1890
- *
1891
- * Parses the current JSON text _source_ and returns the complete data
1892
- * structure as a result.
1893
- */
1894
- static VALUE cParser_parse(VALUE self)
1895
- {
1896
- char *p, *pe;
1897
- int cs = EVIL;
1898
- VALUE result = Qnil;
1899
- GET_PARSER;
1900
-
1901
-
1902
- #line 1903 "parser.c"
1903
- {
1904
- cs = JSON_start;
1905
- }
1906
-
1907
- #line 802 "parser.rl"
1908
- p = json->source;
1909
- pe = p + json->len;
1910
-
1911
- #line 1912 "parser.c"
1912
- {
1913
- if ( p == pe )
1914
- goto _test_eof;
1915
- switch ( cs )
1916
- {
1917
- st1:
1918
- if ( ++p == pe )
1919
- goto _test_eof1;
1920
- case 1:
1921
- switch( (*p) ) {
1922
- case 13: goto st1;
1923
- case 32: goto st1;
1924
- case 34: goto tr2;
1925
- case 45: goto tr2;
1926
- case 47: goto st6;
1927
- case 73: goto tr2;
1928
- case 78: goto tr2;
1929
- case 91: goto tr2;
1930
- case 102: goto tr2;
1931
- case 110: goto tr2;
1932
- case 116: goto tr2;
1933
- case 123: goto tr2;
1934
- }
1935
- if ( (*p) > 10 ) {
1936
- if ( 48 <= (*p) && (*p) <= 57 )
1937
- goto tr2;
1938
- } else if ( (*p) >= 9 )
1939
- goto st1;
1940
- goto st0;
1941
- st0:
1942
- cs = 0;
1943
- goto _out;
1944
- tr2:
1945
- #line 778 "parser.rl"
1946
- {
1947
- char *np = JSON_parse_value(json, p, pe, &result, 0);
1948
- if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1949
- }
1950
- goto st10;
1951
- st10:
1952
- if ( ++p == pe )
1953
- goto _test_eof10;
1954
- case 10:
1955
- #line 1956 "parser.c"
1956
- switch( (*p) ) {
1957
- case 13: goto st10;
1958
- case 32: goto st10;
1959
- case 47: goto st2;
1960
- }
1961
- if ( 9 <= (*p) && (*p) <= 10 )
1962
- goto st10;
1963
- goto st0;
1964
- st2:
1965
- if ( ++p == pe )
1966
- goto _test_eof2;
1967
- case 2:
1968
- switch( (*p) ) {
1969
- case 42: goto st3;
1970
- case 47: goto st5;
1971
- }
1972
- goto st0;
1973
- st3:
1974
- if ( ++p == pe )
1975
- goto _test_eof3;
1976
- case 3:
1977
- if ( (*p) == 42 )
1978
- goto st4;
1979
- goto st3;
1980
- st4:
1981
- if ( ++p == pe )
1982
- goto _test_eof4;
1983
- case 4:
1984
- switch( (*p) ) {
1985
- case 42: goto st4;
1986
- case 47: goto st10;
1987
- }
1988
- goto st3;
1989
- st5:
1990
- if ( ++p == pe )
1991
- goto _test_eof5;
1992
- case 5:
1993
- if ( (*p) == 10 )
1994
- goto st10;
1995
- goto st5;
1996
- st6:
1997
- if ( ++p == pe )
1998
- goto _test_eof6;
1999
- case 6:
2000
- switch( (*p) ) {
2001
- case 42: goto st7;
2002
- case 47: goto st9;
2003
- }
2004
- goto st0;
2005
- st7:
2006
- if ( ++p == pe )
2007
- goto _test_eof7;
2008
- case 7:
2009
- if ( (*p) == 42 )
2010
- goto st8;
2011
- goto st7;
2012
- st8:
2013
- if ( ++p == pe )
2014
- goto _test_eof8;
2015
- case 8:
2016
- switch( (*p) ) {
2017
- case 42: goto st8;
2018
- case 47: goto st1;
2019
- }
2020
- goto st7;
2021
- st9:
2022
- if ( ++p == pe )
2023
- goto _test_eof9;
2024
- case 9:
2025
- if ( (*p) == 10 )
2026
- goto st1;
2027
- goto st9;
2028
- }
2029
- _test_eof1: cs = 1; goto _test_eof;
2030
- _test_eof10: cs = 10; goto _test_eof;
2031
- _test_eof2: cs = 2; goto _test_eof;
2032
- _test_eof3: cs = 3; goto _test_eof;
2033
- _test_eof4: cs = 4; goto _test_eof;
2034
- _test_eof5: cs = 5; goto _test_eof;
2035
- _test_eof6: cs = 6; goto _test_eof;
2036
- _test_eof7: cs = 7; goto _test_eof;
2037
- _test_eof8: cs = 8; goto _test_eof;
2038
- _test_eof9: cs = 9; goto _test_eof;
2039
-
2040
- _test_eof: {}
2041
- _out: {}
2042
- }
2043
-
2044
- #line 805 "parser.rl"
2045
-
2046
- if (cs >= JSON_first_final && p == pe) {
2047
- return result;
2048
- } else {
2049
- rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
2050
- return Qnil;
2051
- }
2052
- }
2053
-
2054
- static void JSON_mark(void *ptr)
2055
- {
2056
- JSON_Parser *json = ptr;
2057
- rb_gc_mark_maybe(json->Vsource);
2058
- rb_gc_mark_maybe(json->create_id);
2059
- rb_gc_mark_maybe(json->object_class);
2060
- rb_gc_mark_maybe(json->array_class);
2061
- rb_gc_mark_maybe(json->decimal_class);
2062
- rb_gc_mark_maybe(json->match_string);
2063
- }
2064
-
2065
- static void JSON_free(void *ptr)
2066
- {
2067
- JSON_Parser *json = ptr;
2068
- fbuffer_free(json->fbuffer);
2069
- ruby_xfree(json);
2070
- }
2071
-
2072
- static size_t JSON_memsize(const void *ptr)
2073
- {
2074
- const JSON_Parser *json = ptr;
2075
- return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
2076
- }
2077
-
2078
- #ifdef NEW_TYPEDDATA_WRAPPER
2079
- static const rb_data_type_t JSON_Parser_type = {
2080
- "JSON/Parser",
2081
- {JSON_mark, JSON_free, JSON_memsize,},
2082
- #ifdef RUBY_TYPED_FREE_IMMEDIATELY
2083
- 0, 0,
2084
- RUBY_TYPED_FREE_IMMEDIATELY,
2085
- #endif
2086
- };
2087
- #endif
2088
-
2089
- static VALUE cJSON_parser_s_allocate(VALUE klass)
2090
- {
2091
- JSON_Parser *json;
2092
- VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
2093
- json->fbuffer = fbuffer_alloc(0);
2094
- return obj;
2095
- }
2096
-
2097
- /*
2098
- * call-seq: source()
2099
- *
2100
- * Returns a copy of the current _source_ string, that was used to construct
2101
- * this Parser.
2102
- */
2103
- static VALUE cParser_source(VALUE self)
2104
- {
2105
- GET_PARSER;
2106
- return rb_str_dup(json->Vsource);
2107
- }
2108
-
2109
- void Init_parser(void)
2110
- {
2111
- #undef rb_intern
2112
- rb_require("json/common");
2113
- mJSON = rb_define_module("JSON");
2114
- mExt = rb_define_module_under(mJSON, "Ext");
2115
- cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
2116
- eParserError = rb_path2class("JSON::ParserError");
2117
- eNestingError = rb_path2class("JSON::NestingError");
2118
- rb_gc_register_mark_object(eParserError);
2119
- rb_gc_register_mark_object(eNestingError);
2120
- rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
2121
- rb_define_method(cParser, "initialize", cParser_initialize, -1);
2122
- rb_define_method(cParser, "parse", cParser_parse, 0);
2123
- rb_define_method(cParser, "source", cParser_source, 0);
2124
-
2125
- CNaN = rb_const_get(mJSON, rb_intern("NaN"));
2126
- rb_gc_register_mark_object(CNaN);
2127
-
2128
- CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
2129
- rb_gc_register_mark_object(CInfinity);
2130
-
2131
- CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
2132
- rb_gc_register_mark_object(CMinusInfinity);
2133
-
2134
- i_json_creatable_p = rb_intern("json_creatable?");
2135
- i_json_create = rb_intern("json_create");
2136
- i_create_id = rb_intern("create_id");
2137
- i_create_additions = rb_intern("create_additions");
2138
- i_chr = rb_intern("chr");
2139
- i_max_nesting = rb_intern("max_nesting");
2140
- i_allow_nan = rb_intern("allow_nan");
2141
- i_symbolize_names = rb_intern("symbolize_names");
2142
- i_object_class = rb_intern("object_class");
2143
- i_array_class = rb_intern("array_class");
2144
- i_decimal_class = rb_intern("decimal_class");
2145
- i_match = rb_intern("match");
2146
- i_match_string = rb_intern("match_string");
2147
- i_key_p = rb_intern("key?");
2148
- i_deep_const_get = rb_intern("deep_const_get");
2149
- i_aset = rb_intern("[]=");
2150
- i_aref = rb_intern("[]");
2151
- i_leftshift = rb_intern("<<");
2152
- i_new = rb_intern("new");
2153
- i_BigDecimal = rb_intern("BigDecimal");
2154
- i_freeze = rb_intern("freeze");
2155
- i_uminus = rb_intern("-@");
2156
- }
2157
-
2158
- /*
2159
- * Local variables:
2160
- * mode: c
2161
- * c-file-style: ruby
2162
- * indent-tabs-mode: nil
2163
- * End:
2164
- */