3 #include "../fbuffer/fbuffer.h" 6 #if defined HAVE_RUBY_ENCODING_H 7 # define EXC_ENCODING rb_utf8_encoding(), 8 # ifndef HAVE_RB_ENC_RAISE 21 # define rb_enc_raise enc_raise 25 # define rb_enc_raise rb_raise 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
53 result = (result << 4) | (
unsigned char)b;
56 result = (result << 4) | (
unsigned char)b;
59 result = (result << 4) | (
unsigned char)b;
62 result = (result << 4) | (
unsigned char)b;
71 }
else if (ch <= 0x07FF) {
72 buf[0] = (char) ((ch >> 6) | 0xC0);
73 buf[1] = (char) ((ch & 0x3F) | 0x80);
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);
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);
101 #line 124 "parser.rl" 113 #line 165 "parser.rl" 134 #line 180 "parser.rl" 160 if ( 9 <= (*p) && (*p) <= 10 )
164 #line 147 "parser.rl" 170 if (np ==
NULL) { p--; {p++; cs = 3;
goto _out;} }
else {p = (( np))-1;}
184 if ( 9 <= (*p) && (*p) <= 10 )
238 if ( 48 <= (*p) && (*p) <= 57 )
240 }
else if ( (*p) >= 9 )
244 #line 132 "parser.rl" 249 p--; {p++; cs = 9;
goto _out;}
272 if ( 9 <= (*p) && (*p) <= 10 )
285 if ( 9 <= (*p) && (*p) <= 10 )
353 #line 155 "parser.rl" 354 { p--; {p++; cs = 27;
goto _out;} }
427 _test_eof2: cs = 2;
goto _test_eof;
428 _test_eof3: cs = 3;
goto _test_eof;
429 _test_eof4: cs = 4;
goto _test_eof;
430 _test_eof5: cs = 5;
goto _test_eof;
431 _test_eof6: cs = 6;
goto _test_eof;
432 _test_eof7: cs = 7;
goto _test_eof;
433 _test_eof8: cs = 8;
goto _test_eof;
434 _test_eof9: cs = 9;
goto _test_eof;
435 _test_eof10: cs = 10;
goto _test_eof;
436 _test_eof11: cs = 11;
goto _test_eof;
437 _test_eof12: cs = 12;
goto _test_eof;
438 _test_eof13: cs = 13;
goto _test_eof;
439 _test_eof14: cs = 14;
goto _test_eof;
440 _test_eof15: cs = 15;
goto _test_eof;
441 _test_eof16: cs = 16;
goto _test_eof;
442 _test_eof17: cs = 17;
goto _test_eof;
443 _test_eof18: cs = 18;
goto _test_eof;
444 _test_eof27: cs = 27;
goto _test_eof;
445 _test_eof19: cs = 19;
goto _test_eof;
446 _test_eof20: cs = 20;
goto _test_eof;
447 _test_eof21: cs = 21;
goto _test_eof;
448 _test_eof22: cs = 22;
goto _test_eof;
449 _test_eof23: cs = 23;
goto _test_eof;
450 _test_eof24: cs = 24;
goto _test_eof;
451 _test_eof25: cs = 25;
goto _test_eof;
452 _test_eof26: cs = 26;
goto _test_eof;
458 #line 181 "parser.rl" 468 if (!
NIL_P(klassname)) {
491 #line 281 "parser.rl" 504 #line 288 "parser.rl" 531 if ( 48 <= (*p) && (*p) <= 57 )
533 }
else if ( (*p) >= 9 )
540 #line 233 "parser.rl" 543 if (np ==
NULL) { p--; {p++; cs = 29;
goto _out;} }
else {p = (( np))-1;}
547 #line 238 "parser.rl" 554 p--; {p++; cs = 29;
goto _out;}
560 if (np !=
NULL) {p = (( np))-1;}
562 if (np !=
NULL) {p = (( np))-1;}
563 p--; {p++; cs = 29;
goto _out;}
567 #line 256 "parser.rl" 571 if (np ==
NULL) { p--; {p++; cs = 29;
goto _out;} }
else {p = (( np))-1;}
575 #line 262 "parser.rl" 579 if (np ==
NULL) { p--; {p++; cs = 29;
goto _out;} }
else {p = (( np))-1;}
583 #line 226 "parser.rl" 593 #line 219 "parser.rl" 603 #line 213 "parser.rl" 609 #line 210 "parser.rl" 615 #line 216 "parser.rl" 624 #line 268 "parser.rl" 625 { p--; {p++; cs = 29;
goto _out;} }
632 if ( 9 <= (*p) && (*p) <= 10 )
833 _test_eof1: cs = 1;
goto _test_eof;
834 _test_eof29: cs = 29;
goto _test_eof;
835 _test_eof2: cs = 2;
goto _test_eof;
836 _test_eof3: cs = 3;
goto _test_eof;
837 _test_eof4: cs = 4;
goto _test_eof;
838 _test_eof5: cs = 5;
goto _test_eof;
839 _test_eof6: cs = 6;
goto _test_eof;
840 _test_eof7: cs = 7;
goto _test_eof;
841 _test_eof8: cs = 8;
goto _test_eof;
842 _test_eof9: cs = 9;
goto _test_eof;
843 _test_eof10: cs = 10;
goto _test_eof;
844 _test_eof11: cs = 11;
goto _test_eof;
845 _test_eof12: cs = 12;
goto _test_eof;
846 _test_eof13: cs = 13;
goto _test_eof;
847 _test_eof14: cs = 14;
goto _test_eof;
848 _test_eof15: cs = 15;
goto _test_eof;
849 _test_eof16: cs = 16;
goto _test_eof;
850 _test_eof17: cs = 17;
goto _test_eof;
851 _test_eof18: cs = 18;
goto _test_eof;
852 _test_eof19: cs = 19;
goto _test_eof;
853 _test_eof20: cs = 20;
goto _test_eof;
854 _test_eof21: cs = 21;
goto _test_eof;
855 _test_eof22: cs = 22;
goto _test_eof;
856 _test_eof23: cs = 23;
goto _test_eof;
857 _test_eof24: cs = 24;
goto _test_eof;
858 _test_eof25: cs = 25;
goto _test_eof;
859 _test_eof26: cs = 26;
goto _test_eof;
860 _test_eof27: cs = 27;
goto _test_eof;
861 _test_eof28: cs = 28;
goto _test_eof;
867 #line 289 "parser.rl" 885 #line 305 "parser.rl" 898 #line 312 "parser.rl" 912 if ( 49 <= (*p) && (*p) <= 57 )
924 if ( 49 <= (*p) && (*p) <= 57 )
931 if ( 48 <= (*p) && (*p) <= 57 )
935 #line 302 "parser.rl" 936 { p--; {p++; cs = 4;
goto _out;} }
948 if ( 48 <= (*p) && (*p) <= 57 )
952 _test_eof2: cs = 2;
goto _test_eof;
953 _test_eof3: cs = 3;
goto _test_eof;
954 _test_eof4: cs = 4;
goto _test_eof;
955 _test_eof5: cs = 5;
goto _test_eof;
961 #line 314 "parser.rl" 984 #line 339 "parser.rl" 997 #line 346 "parser.rl" 1000 #line 1001 "parser.c" 1011 if ( 49 <= (*p) && (*p) <= 57 )
1023 if ( 49 <= (*p) && (*p) <= 57 )
1040 if ( 48 <= (*p) && (*p) <= 57 )
1052 if ( 48 <= (*p) && (*p) <= 57 )
1054 }
else if ( (*p) >= 45 )
1058 #line 333 "parser.rl" 1059 { p--; {p++; cs = 9;
goto _out;} }
1065 #line 1066 "parser.c" 1075 if ( 48 <= (*p) && (*p) <= 57 )
1082 if ( 48 <= (*p) && (*p) <= 57 )
1094 if ( 48 <= (*p) && (*p) <= 57 )
1096 }
else if ( (*p) >= 45 )
1108 if ( 48 <= (*p) && (*p) <= 57 )
1112 _test_eof2: cs = 2;
goto _test_eof;
1113 _test_eof3: cs = 3;
goto _test_eof;
1114 _test_eof4: cs = 4;
goto _test_eof;
1115 _test_eof8: cs = 8;
goto _test_eof;
1116 _test_eof9: cs = 9;
goto _test_eof;
1117 _test_eof5: cs = 5;
goto _test_eof;
1118 _test_eof6: cs = 6;
goto _test_eof;
1119 _test_eof10: cs = 10;
goto _test_eof;
1120 _test_eof7: cs = 7;
goto _test_eof;
1126 #line 348 "parser.rl" 1142 #line 1143 "parser.c" 1150 #line 391 "parser.rl" 1164 #line 1165 "parser.c" 1169 #line 404 "parser.rl" 1171 #line 1172 "parser.c" 1204 if ( 48 <= (*p) && (*p) <= 57 )
1206 }
else if ( (*p) >= 9 )
1210 #line 368 "parser.rl" 1215 p--; {p++; cs = 3;
goto _out;}
1230 #line 1231 "parser.c" 1238 if ( 9 <= (*p) && (*p) <= 10 )
1260 if ( 48 <= (*p) && (*p) <= 57 )
1262 }
else if ( (*p) >= 9 )
1330 #line 383 "parser.rl" 1331 { p--; {p++; cs = 17;
goto _out;} }
1337 #line 1338 "parser.c" 1372 _test_eof2: cs = 2;
goto _test_eof;
1373 _test_eof3: cs = 3;
goto _test_eof;
1374 _test_eof4: cs = 4;
goto _test_eof;
1375 _test_eof5: cs = 5;
goto _test_eof;
1376 _test_eof6: cs = 6;
goto _test_eof;
1377 _test_eof7: cs = 7;
goto _test_eof;
1378 _test_eof8: cs = 8;
goto _test_eof;
1379 _test_eof9: cs = 9;
goto _test_eof;
1380 _test_eof10: cs = 10;
goto _test_eof;
1381 _test_eof11: cs = 11;
goto _test_eof;
1382 _test_eof12: cs = 12;
goto _test_eof;
1383 _test_eof17: cs = 17;
goto _test_eof;
1384 _test_eof13: cs = 13;
goto _test_eof;
1385 _test_eof14: cs = 14;
goto _test_eof;
1386 _test_eof15: cs = 15;
goto _test_eof;
1387 _test_eof16: cs = 16;
goto _test_eof;
1393 #line 405 "parser.rl" 1405 char *p = string, *pe = string, *unescape;
1409 while (pe < stringEnd) {
1411 unescape = (
char *)
"?";
1416 unescape = (
char *)
"\n";
1419 unescape = (
char *)
"\r";
1422 unescape = (
char *)
"\t";
1425 unescape = (
char *)
"\"";
1428 unescape = (
char *)
"\\";
1431 unescape = (
char *)
"\b";
1434 unescape = (
char *)
"\f";
1437 if (pe > stringEnd - 4) {
1440 "%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
1447 if (pe > stringEnd - 6) {
1450 "%u: incomplete surrogate pair at '%s'", __LINE__, p
1453 if (pe[0] ==
'\\' && pe[1] ==
'u') {
1455 ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
1459 unescape = (
char *)
"?";
1482 #line 1483 "parser.c" 1490 #line 512 "parser.rl" 1512 #line 1513 "parser.c" 1517 #line 533 "parser.rl" 1520 #line 1521 "parser.c" 1541 if ( 0 <= (*p) && (*p) <= 31 )
1545 #line 498 "parser.rl" 1548 if (
NIL_P(*result)) {
1550 {p++; cs = 8;
goto _out;}
1556 #line 509 "parser.rl" 1557 { p--; {p++; cs = 8;
goto _out;} }
1563 #line 1564 "parser.c" 1571 if ( 0 <= (*p) && (*p) <= 31 )
1579 if ( 48 <= (*p) && (*p) <= 57 )
1581 }
else if ( (*p) > 70 ) {
1582 if ( 97 <= (*p) && (*p) <= 102 )
1592 if ( 48 <= (*p) && (*p) <= 57 )
1594 }
else if ( (*p) > 70 ) {
1595 if ( 97 <= (*p) && (*p) <= 102 )
1605 if ( 48 <= (*p) && (*p) <= 57 )
1607 }
else if ( (*p) > 70 ) {
1608 if ( 97 <= (*p) && (*p) <= 102 )
1618 if ( 48 <= (*p) && (*p) <= 57 )
1620 }
else if ( (*p) > 70 ) {
1621 if ( 97 <= (*p) && (*p) <= 102 )
1627 _test_eof2: cs = 2;
goto _test_eof;
1628 _test_eof8: cs = 8;
goto _test_eof;
1629 _test_eof3: cs = 3;
goto _test_eof;
1630 _test_eof4: cs = 4;
goto _test_eof;
1631 _test_eof5: cs = 5;
goto _test_eof;
1632 _test_eof6: cs = 6;
goto _test_eof;
1633 _test_eof7: cs = 7;
goto _test_eof;
1639 #line 535 "parser.rl" 1678 #ifdef HAVE_RUBY_ENCODING_H 1724 if (json->Vsource) {
1727 #ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1733 #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1742 if (
RTEST(max_nesting)) {
1744 json->max_nesting =
FIX2INT(max_nesting);
1746 json->max_nesting = 0;
1749 json->max_nesting = 100;
1755 json->allow_nan = 0;
1761 json->symbolize_names = 0;
1767 json->create_additions = 0;
1769 if (json->symbolize_names && json->create_additions) {
1771 "options :symbolize_names and :create_additions cannot be " 1772 " used in conjunction");
1784 json->object_class =
Qnil;
1790 json->array_class =
Qnil;
1797 json->match_string =
Qnil;
1799 #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1803 json->max_nesting = 100;
1804 json->allow_nan = 0;
1805 json->create_additions = 1;
1807 json->object_class =
Qnil;
1808 json->array_class =
Qnil;
1814 json->Vsource = source;
1819 #line 1820 "parser.c" 1827 #line 728 "parser.rl" 1844 #line 1845 "parser.c" 1849 #line 744 "parser.rl" 1853 #line 1854 "parser.c" 1878 if ( 48 <= (*p) && (*p) <= 57 )
1880 }
else if ( (*p) >= 9 )
1887 #line 720 "parser.rl" 1890 if (np ==
NULL) { p--; {p++; cs = 10;
goto _out;} }
else {p = (( np))-1;}
1897 #line 1898 "parser.c" 1903 if ( 9 <= (*p) && (*p) <= 10 )
1971 _test_eof1: cs = 1;
goto _test_eof;
1972 _test_eof10: cs = 10;
goto _test_eof;
1973 _test_eof2: cs = 2;
goto _test_eof;
1974 _test_eof3: cs = 3;
goto _test_eof;
1975 _test_eof4: cs = 4;
goto _test_eof;
1976 _test_eof5: cs = 5;
goto _test_eof;
1977 _test_eof6: cs = 6;
goto _test_eof;
1978 _test_eof7: cs = 7;
goto _test_eof;
1979 _test_eof8: cs = 8;
goto _test_eof;
1980 _test_eof9: cs = 9;
goto _test_eof;
1986 #line 747 "parser.rl" 2019 #ifdef NEW_TYPEDDATA_WRAPPER 2023 #ifdef RUBY_TYPED_FREE_IMMEDIATELY static size_t JSON_memsize(const void *ptr)
static void fbuffer_clear(FBuffer *fb)
VALUE rb_ary_entry(VALUE ary, long offset)
#define RUBY_TYPED_FREE_IMMEDIATELY
static void JSON_mark(void *ptr)
static VALUE cParser_source(VALUE self)
#define option_given_p(opts, key)
static VALUE convert_encoding(VALUE source)
VALUE rb_ary_push(VALUE ary, VALUE item)
static VALUE eParserError
static VALUE match_string(VALUE match)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
static void fbuffer_append_char(FBuffer *fb, char newchr)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
static VALUE cJSON_parser_s_allocate(VALUE klass)
static VALUE cParser_parse(VALUE self)
static char * JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
static VALUE CMinusInfinity
static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
static const rb_data_type_t JSON_Parser_type
VALUE rb_path2class(const char *)
rb_encoding * rb_utf8_encoding(void)
static char * JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
VALUE rb_str_buf_cat(VALUE, const char *, long)
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
void rb_exc_raise(VALUE mesg)
static char * JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
VALUE rb_require(const char *)
static ID i_deep_const_get
static VALUE eNestingError
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
RUBY_EXTERN VALUE rb_cObject
static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len)
static void JSON_free(void *ptr)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
static FBuffer * fbuffer_alloc(unsigned long initial_length)
VALUE rb_str_resize(VALUE, long)
VALUE rb_const_get(VALUE, ID)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
unsigned char buf[MIME_BUF_SIZE]
static char * JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
#define UNI_SUR_HIGH_START
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
rb_encoding * rb_enc_get(VALUE obj)
static void enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
static void fbuffer_free(FBuffer *fb)
static char * JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
static UTF32 unescape_unicode(const unsigned char *p)
VALUE rb_hash_aref(VALUE hash, VALUE key)
static const char digit_values[256]
#define TypedData_Make_Struct(klass, type, data_type, sval)
#define UNI_REPLACEMENT_CHAR
static ID i_symbolize_names
void rb_gc_mark_maybe(VALUE obj)
static ID i_json_creatable_p
static ID i_create_additions
rb_encoding * rb_ascii8bit_encoding(void)
static char * JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
VALUE rb_str_intern(VALUE)
static int match_i(VALUE regexp, VALUE klass, VALUE memo)
static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
VALUE rb_define_module(const char *name)
VALUE rb_str_buf_new(long)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
double rb_cstr_to_dbl(const char *, int)
VALUE rb_cstr2inum(const char *str, int base)