scout 5.6.7 → 5.6.8.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/CHANGELOG.markdown +4 -0
  2. data/lib/scout/version.rb +1 -1
  3. data/vendor/json_pure/.gitignore +12 -0
  4. data/vendor/json_pure/.travis.yml +20 -0
  5. data/vendor/json_pure/CHANGES +120 -0
  6. data/vendor/json_pure/COPYING-json-jruby +57 -0
  7. data/vendor/json_pure/Gemfile +11 -0
  8. data/vendor/json_pure/README-json-jruby.markdown +33 -0
  9. data/vendor/json_pure/{README → README.rdoc} +7 -7
  10. data/vendor/json_pure/Rakefile +305 -185
  11. data/vendor/json_pure/VERSION +1 -1
  12. data/vendor/json_pure/diagrams/.keep +0 -0
  13. data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +181 -0
  14. data/vendor/json_pure/ext/json/ext/generator/depend +1 -0
  15. data/vendor/json_pure/ext/json/ext/generator/extconf.rb +4 -6
  16. data/vendor/json_pure/ext/json/ext/generator/generator.c +463 -369
  17. data/vendor/json_pure/ext/json/ext/generator/generator.h +44 -66
  18. data/vendor/json_pure/ext/json/ext/parser/depend +1 -0
  19. data/vendor/json_pure/ext/json/ext/parser/extconf.rb +3 -5
  20. data/vendor/json_pure/ext/json/ext/parser/parser.c +580 -311
  21. data/vendor/json_pure/ext/json/ext/parser/parser.h +14 -8
  22. data/vendor/json_pure/ext/json/ext/parser/parser.rl +242 -107
  23. data/vendor/json_pure/install.rb +8 -11
  24. data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +167 -0
  25. data/vendor/json_pure/java/src/json/ext/Generator.java +444 -0
  26. data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +232 -0
  27. data/vendor/json_pure/java/src/json/ext/GeneratorService.java +43 -0
  28. data/vendor/json_pure/java/src/json/ext/GeneratorState.java +543 -0
  29. data/vendor/json_pure/java/src/json/ext/OptionsReader.java +114 -0
  30. data/vendor/json_pure/java/src/json/ext/Parser.java +2644 -0
  31. data/vendor/json_pure/java/src/json/ext/Parser.rl +968 -0
  32. data/vendor/json_pure/java/src/json/ext/ParserService.java +35 -0
  33. data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +121 -0
  34. data/vendor/json_pure/java/src/json/ext/StringDecoder.java +167 -0
  35. data/vendor/json_pure/java/src/json/ext/StringEncoder.java +106 -0
  36. data/vendor/json_pure/java/src/json/ext/Utils.java +89 -0
  37. data/vendor/json_pure/json-java.gemspec +23 -0
  38. data/vendor/json_pure/json.gemspec +37 -0
  39. data/vendor/json_pure/json_pure.gemspec +39 -0
  40. data/vendor/json_pure/lib/json.rb +52 -0
  41. data/vendor/json_pure/lib/json/add/bigdecimal.rb +28 -0
  42. data/vendor/json_pure/lib/json/add/complex.rb +22 -0
  43. data/vendor/json_pure/lib/json/add/core.rb +9 -146
  44. data/vendor/json_pure/lib/json/add/date.rb +34 -0
  45. data/vendor/json_pure/lib/json/add/date_time.rb +50 -0
  46. data/vendor/json_pure/lib/json/add/exception.rb +31 -0
  47. data/vendor/json_pure/lib/json/add/ostruct.rb +31 -0
  48. data/vendor/json_pure/lib/json/add/range.rb +29 -0
  49. data/vendor/json_pure/lib/json/add/rational.rb +22 -0
  50. data/vendor/json_pure/lib/json/add/regexp.rb +30 -0
  51. data/vendor/json_pure/lib/json/add/struct.rb +30 -0
  52. data/vendor/json_pure/lib/json/add/symbol.rb +25 -0
  53. data/vendor/json_pure/lib/json/add/time.rb +38 -0
  54. data/vendor/json_pure/lib/json/common.rb +157 -67
  55. data/vendor/json_pure/lib/json/ext.rb +8 -2
  56. data/vendor/json_pure/lib/json/ext/.keep +0 -0
  57. data/vendor/json_pure/lib/json/generic_object.rb +70 -0
  58. data/vendor/json_pure/lib/json/pure.rb +8 -64
  59. data/vendor/json_pure/lib/json/pure/generator.rb +183 -113
  60. data/vendor/json_pure/lib/json/pure/parser.rb +118 -66
  61. data/vendor/json_pure/lib/json/version.rb +1 -1
  62. data/vendor/json_pure/tests/fixtures/fail18.json +1 -1
  63. data/vendor/json_pure/tests/setup_variant.rb +11 -0
  64. data/vendor/json_pure/tests/test_json.rb +233 -28
  65. data/vendor/json_pure/tests/test_json_addition.rb +68 -34
  66. data/vendor/json_pure/tests/test_json_encoding.rb +11 -14
  67. data/vendor/json_pure/tests/test_json_fixtures.rb +11 -10
  68. data/vendor/json_pure/tests/test_json_generate.rb +207 -7
  69. data/vendor/json_pure/tests/test_json_generic_object.rb +75 -0
  70. data/vendor/json_pure/tests/test_json_string_matching.rb +39 -0
  71. data/vendor/json_pure/tests/test_json_unicode.rb +3 -7
  72. data/vendor/json_pure/tools/fuzz.rb +1 -1
  73. data/vendor/json_pure/tools/server.rb +1 -0
  74. metadata +87 -94
  75. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +0 -52
  76. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +0 -1000
  77. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +0 -1001
  78. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +0 -900
  79. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +0 -901
  80. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +0 -1000
  81. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +0 -1001
  82. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +0 -261
  83. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +0 -1000
  84. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +0 -1001
  85. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +0 -1000
  86. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +0 -1001
  87. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +0 -1000
  88. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +0 -1001
  89. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +0 -262
  90. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +0 -1000
  91. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +0 -1001
  92. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +0 -82
  93. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +0 -34
  94. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +0 -900
  95. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +0 -901
  96. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +0 -81
  97. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +0 -1000
  98. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +0 -1001
  99. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +0 -82
  100. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +0 -1000
  101. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +0 -1001
  102. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +0 -82
  103. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +0 -1000
  104. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +0 -1001
  105. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +0 -82
  106. data/vendor/json_pure/benchmarks/generator2_benchmark.rb +0 -222
  107. data/vendor/json_pure/benchmarks/generator_benchmark.rb +0 -224
  108. data/vendor/json_pure/benchmarks/ohai.json +0 -1216
  109. data/vendor/json_pure/benchmarks/ohai.ruby +0 -1
  110. data/vendor/json_pure/benchmarks/parser2_benchmark.rb +0 -251
  111. data/vendor/json_pure/benchmarks/parser_benchmark.rb +0 -259
  112. data/vendor/json_pure/bin/edit_json.rb +0 -9
  113. data/vendor/json_pure/bin/prettify_json.rb +0 -75
  114. data/vendor/json_pure/lib/json/Array.xpm +0 -21
  115. data/vendor/json_pure/lib/json/FalseClass.xpm +0 -21
  116. data/vendor/json_pure/lib/json/Hash.xpm +0 -21
  117. data/vendor/json_pure/lib/json/Key.xpm +0 -73
  118. data/vendor/json_pure/lib/json/NilClass.xpm +0 -21
  119. data/vendor/json_pure/lib/json/Numeric.xpm +0 -28
  120. data/vendor/json_pure/lib/json/String.xpm +0 -96
  121. data/vendor/json_pure/lib/json/TrueClass.xpm +0 -21
  122. data/vendor/json_pure/lib/json/add/rails.rb +0 -58
  123. data/vendor/json_pure/lib/json/editor.rb +0 -1371
  124. data/vendor/json_pure/lib/json/json.xpm +0 -1499
  125. data/vendor/json_pure/tests/test_json_rails.rb +0 -144
@@ -2,85 +2,34 @@
2
2
  #define _GENERATOR_H_
3
3
 
4
4
  #include <string.h>
5
- #include <assert.h>
6
5
  #include <math.h>
6
+ #include <ctype.h>
7
7
 
8
8
  #include "ruby.h"
9
9
 
10
- #if HAVE_RUBY_RE_H
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
- #define FORCE_UTF8(obj)
23
- #endif
24
-
25
- #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
26
-
27
- #ifndef RHASH_SIZE
28
- #define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries)
13
+ #include "re.h"
29
14
  #endif
30
15
 
31
- #ifndef RFLOAT_VALUE
32
- #define RFLOAT_VALUE(val) (RFLOAT(val)->value)
16
+ #ifndef rb_intern_str
17
+ #define rb_intern_str(string) SYM2ID(rb_str_intern(string))
33
18
  #endif
34
19
 
35
- #ifndef RARRAY_PTR
36
- #define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
20
+ #ifndef rb_obj_instance_variables
21
+ #define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
37
22
  #endif
38
- #ifndef RARRAY_LEN
39
- #define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
40
- #endif
41
- #ifndef RSTRING_PTR
42
- #define RSTRING_PTR(string) RSTRING(string)->ptr
43
- #endif
44
- #ifndef RSTRING_LEN
45
- #define RSTRING_LEN(string) RSTRING(string)->len
46
- #endif
47
-
48
- #define RSTRING_PAIR(string) RSTRING_PTR(string), RSTRING_LEN(string)
49
-
50
- /* fbuffer implementation */
51
23
 
52
- typedef struct FBufferStruct {
53
- unsigned int initial_length;
54
- char *ptr;
55
- unsigned int len;
56
- unsigned int capa;
57
- } FBuffer;
58
-
59
- #define FBUFFER_INITIAL_LENGTH 4096
60
-
61
- #define FBUFFER_PTR(fb) (fb->ptr)
62
- #define FBUFFER_LEN(fb) (fb->len)
63
- #define FBUFFER_CAPA(fb) (fb->capa)
64
- #define FBUFFER_PAIR(fb) FBUFFER_PTR(fb), FBUFFER_LEN(fb)
65
-
66
- static char *fstrndup(const char *ptr, int len);
67
- static FBuffer *fbuffer_alloc();
68
- static FBuffer *fbuffer_alloc_with_length(unsigned initial_length);
69
- static void fbuffer_free(FBuffer *fb);
70
- static void fbuffer_free_only_buffer(FBuffer *fb);
71
- static void fbuffer_clear(FBuffer *fb);
72
- static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned int len);
73
- static void fbuffer_append_long(FBuffer *fb, long number);
74
- static void fbuffer_append_char(FBuffer *fb, char newchr);
75
- static FBuffer *fbuffer_dup(FBuffer *fb);
24
+ #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
76
25
 
77
26
  /* unicode defintions */
78
27
 
79
28
  #define UNI_STRICT_CONVERSION 1
80
29
 
81
- typedef unsigned long UTF32; /* at least 32 bits */
82
- typedef unsigned short UTF16; /* at least 16 bits */
83
- typedef unsigned char UTF8; /* typically 8 bits */
30
+ typedef unsigned long UTF32; /* at least 32 bits */
31
+ typedef unsigned short UTF16; /* at least 16 bits */
32
+ typedef unsigned char UTF8; /* typically 8 bits */
84
33
 
85
34
  #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
86
35
  #define UNI_MAX_BMP (UTF32)0x0000FFFF
@@ -98,11 +47,12 @@ static const int halfShift = 10; /* used for shifting by 10 bits */
98
47
  static const UTF32 halfBase = 0x0010000UL;
99
48
  static const UTF32 halfMask = 0x3FFUL;
100
49
 
101
- static unsigned char isLegalUTF8(const UTF8 *source, int length);
50
+ static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
102
51
  static void unicode_escape(char *buf, UTF16 character);
103
52
  static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
104
53
  static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
105
54
  static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string);
55
+ static char *fstrndup(const char *ptr, unsigned long len);
106
56
 
107
57
  /* ruby api and some helpers */
108
58
 
@@ -123,15 +73,31 @@ typedef struct JSON_Generator_StateStruct {
123
73
  long max_nesting;
124
74
  char allow_nan;
125
75
  char ascii_only;
76
+ char quirks_mode;
77
+ long depth;
78
+ long buffer_initial_length;
126
79
  } JSON_Generator_State;
127
80
 
128
81
  #define GET_STATE(self) \
129
82
  JSON_Generator_State *state; \
130
83
  Data_Get_Struct(self, JSON_Generator_State, state)
131
84
 
85
+ #define GENERATE_JSON(type) \
86
+ FBuffer *buffer; \
87
+ VALUE Vstate; \
88
+ JSON_Generator_State *state; \
89
+ \
90
+ rb_scan_args(argc, argv, "01", &Vstate); \
91
+ Vstate = cState_from_state_s(cState, Vstate); \
92
+ Data_Get_Struct(Vstate, JSON_Generator_State, state); \
93
+ buffer = cState_prepare_buffer(Vstate); \
94
+ generate_json_##type(buffer, Vstate, state, self); \
95
+ return fbuffer_to_s(buffer)
96
+
132
97
  static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
133
98
  static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
134
- static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
99
+ static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
100
+ static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
135
101
  static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
136
102
  static VALUE mString_included_s(VALUE self, VALUE modul);
137
103
  static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
@@ -147,8 +113,17 @@ static JSON_Generator_State *State_allocate();
147
113
  static VALUE cState_s_allocate(VALUE klass);
148
114
  static VALUE cState_configure(VALUE self, VALUE opts);
149
115
  static VALUE cState_to_h(VALUE self);
150
- static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj, long depth);
151
- static VALUE cState_partial_generate(VALUE self, VALUE obj, VALUE depth);
116
+ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
117
+ static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
118
+ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
119
+ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
120
+ static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
121
+ static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
122
+ static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
123
+ static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
124
+ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
125
+ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
126
+ static VALUE cState_partial_generate(VALUE self, VALUE obj);
152
127
  static VALUE cState_generate(VALUE self, VALUE obj);
153
128
  static VALUE cState_initialize(int argc, VALUE *argv, VALUE self);
154
129
  static VALUE cState_from_state_s(VALUE self, VALUE opts);
@@ -166,5 +141,8 @@ static VALUE cState_max_nesting(VALUE self);
166
141
  static VALUE cState_max_nesting_set(VALUE self, VALUE depth);
167
142
  static VALUE cState_allow_nan_p(VALUE self);
168
143
  static VALUE cState_ascii_only_p(VALUE self);
144
+ static VALUE cState_depth(VALUE self);
145
+ static VALUE cState_depth_set(VALUE self, VALUE depth);
146
+ static FBuffer *cState_prepare_buffer(VALUE self);
169
147
 
170
148
  #endif
@@ -0,0 +1 @@
1
+ parser.o: parser.c parser.h $(srcdir)/../fbuffer/fbuffer.h
@@ -1,15 +1,13 @@
1
1
  require 'mkmf'
2
- require 'rbconfig'
3
2
 
4
3
  unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
5
4
  $CFLAGS << ' -O3'
6
5
  end
7
6
  if CONFIG['CC'] =~ /gcc/
8
7
  $CFLAGS << ' -Wall'
9
- #unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
10
- # $CFLAGS << ' -O0 -ggdb'
11
- #end
8
+ if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
9
+ $CFLAGS << ' -O0 -ggdb'
10
+ end
12
11
  end
13
12
 
14
- have_header("re.h")
15
13
  create_makefile 'json/ext/parser'
@@ -1,10 +1,11 @@
1
1
 
2
2
  #line 1 "parser.rl"
3
+ #include "../fbuffer/fbuffer.h"
3
4
  #include "parser.h"
4
5
 
5
6
  /* unicode */
6
7
 
7
- static const char digit_values[256] = {
8
+ static const char digit_values[256] = {
8
9
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
9
10
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
10
11
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
@@ -40,7 +41,7 @@ static UTF32 unescape_unicode(const unsigned char *p)
40
41
  return result;
41
42
  }
42
43
 
43
- static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
44
+ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
44
45
  {
45
46
  int len = 1;
46
47
  if (ch <= 0x7F) {
@@ -69,7 +70,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
69
70
  #ifdef HAVE_RUBY_ENCODING_H
70
71
  static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
71
72
  CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
72
- static ID i_encoding, i_encode, i_encode_bang, i_force_encoding;
73
+ static ID i_encoding, i_encode;
73
74
  #else
74
75
  static ID i_iconv;
75
76
  #endif
@@ -78,15 +79,16 @@ static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
78
79
  static VALUE CNaN, CInfinity, CMinusInfinity;
79
80
 
80
81
  static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
81
- i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_object_class,
82
- i_array_class, i_key_p, i_deep_const_get;
82
+ i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_quirks_mode,
83
+ i_object_class, i_array_class, i_key_p, i_deep_const_get, i_match,
84
+ i_match_string, i_aset, i_aref, i_leftshift;
83
85
 
84
86
 
85
- #line 108 "parser.rl"
87
+ #line 110 "parser.rl"
86
88
 
87
89
 
88
90
 
89
- #line 90 "parser.c"
91
+ #line 92 "parser.c"
90
92
  static const int JSON_object_start = 1;
91
93
  static const int JSON_object_first_final = 27;
92
94
  static const int JSON_object_error = 0;
@@ -94,7 +96,7 @@ static const int JSON_object_error = 0;
94
96
  static const int JSON_object_en_main = 1;
95
97
 
96
98
 
97
- #line 143 "parser.rl"
99
+ #line 151 "parser.rl"
98
100
 
99
101
 
100
102
  static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -109,15 +111,15 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
109
111
 
110
112
  *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
111
113
 
112
-
113
- #line 114 "parser.c"
114
+
115
+ #line 116 "parser.c"
114
116
  {
115
117
  cs = JSON_object_start;
116
118
  }
117
119
 
118
- #line 158 "parser.rl"
119
-
120
- #line 121 "parser.c"
120
+ #line 166 "parser.rl"
121
+
122
+ #line 123 "parser.c"
121
123
  {
122
124
  if ( p == pe )
123
125
  goto _test_eof;
@@ -145,7 +147,7 @@ case 2:
145
147
  goto st2;
146
148
  goto st0;
147
149
  tr2:
148
- #line 127 "parser.rl"
150
+ #line 133 "parser.rl"
149
151
  {
150
152
  char *np;
151
153
  json->parsing_name = 1;
@@ -158,7 +160,7 @@ st3:
158
160
  if ( ++p == pe )
159
161
  goto _test_eof3;
160
162
  case 3:
161
- #line 161 "parser.c"
163
+ #line 164 "parser.c"
162
164
  switch( (*p) ) {
163
165
  case 13: goto st3;
164
166
  case 32: goto st3;
@@ -225,14 +227,18 @@ case 8:
225
227
  goto st8;
226
228
  goto st0;
227
229
  tr11:
228
- #line 116 "parser.rl"
230
+ #line 118 "parser.rl"
229
231
  {
230
232
  VALUE v = Qnil;
231
- char *np = JSON_parse_value(json, p, pe, &v);
233
+ char *np = JSON_parse_value(json, p, pe, &v);
232
234
  if (np == NULL) {
233
235
  p--; {p++; cs = 9; goto _out;}
234
236
  } else {
235
- rb_hash_aset(*result, last_name, v);
237
+ if (NIL_P(json->object_class)) {
238
+ rb_hash_aset(*result, last_name, v);
239
+ } else {
240
+ rb_funcall(*result, i_aset, 2, last_name, v);
241
+ }
236
242
  {p = (( np))-1;}
237
243
  }
238
244
  }
@@ -241,7 +247,7 @@ st9:
241
247
  if ( ++p == pe )
242
248
  goto _test_eof9;
243
249
  case 9:
244
- #line 244 "parser.c"
250
+ #line 251 "parser.c"
245
251
  switch( (*p) ) {
246
252
  case 13: goto st9;
247
253
  case 32: goto st9;
@@ -330,14 +336,14 @@ case 18:
330
336
  goto st9;
331
337
  goto st18;
332
338
  tr4:
333
- #line 134 "parser.rl"
339
+ #line 141 "parser.rl"
334
340
  { p--; {p++; cs = 27; goto _out;} }
335
341
  goto st27;
336
342
  st27:
337
343
  if ( ++p == pe )
338
344
  goto _test_eof27;
339
345
  case 27:
340
- #line 340 "parser.c"
346
+ #line 347 "parser.c"
341
347
  goto st0;
342
348
  st19:
343
349
  if ( ++p == pe )
@@ -404,45 +410,50 @@ case 26:
404
410
  goto st2;
405
411
  goto st26;
406
412
  }
407
- _test_eof2: cs = 2; goto _test_eof;
408
- _test_eof3: cs = 3; goto _test_eof;
409
- _test_eof4: cs = 4; goto _test_eof;
410
- _test_eof5: cs = 5; goto _test_eof;
411
- _test_eof6: cs = 6; goto _test_eof;
412
- _test_eof7: cs = 7; goto _test_eof;
413
- _test_eof8: cs = 8; goto _test_eof;
414
- _test_eof9: cs = 9; goto _test_eof;
415
- _test_eof10: cs = 10; goto _test_eof;
416
- _test_eof11: cs = 11; goto _test_eof;
417
- _test_eof12: cs = 12; goto _test_eof;
418
- _test_eof13: cs = 13; goto _test_eof;
419
- _test_eof14: cs = 14; goto _test_eof;
420
- _test_eof15: cs = 15; goto _test_eof;
421
- _test_eof16: cs = 16; goto _test_eof;
422
- _test_eof17: cs = 17; goto _test_eof;
423
- _test_eof18: cs = 18; goto _test_eof;
424
- _test_eof27: cs = 27; goto _test_eof;
425
- _test_eof19: cs = 19; goto _test_eof;
426
- _test_eof20: cs = 20; goto _test_eof;
427
- _test_eof21: cs = 21; goto _test_eof;
428
- _test_eof22: cs = 22; goto _test_eof;
429
- _test_eof23: cs = 23; goto _test_eof;
430
- _test_eof24: cs = 24; goto _test_eof;
431
- _test_eof25: cs = 25; goto _test_eof;
432
- _test_eof26: cs = 26; goto _test_eof;
413
+ _test_eof2: cs = 2; goto _test_eof;
414
+ _test_eof3: cs = 3; goto _test_eof;
415
+ _test_eof4: cs = 4; goto _test_eof;
416
+ _test_eof5: cs = 5; goto _test_eof;
417
+ _test_eof6: cs = 6; goto _test_eof;
418
+ _test_eof7: cs = 7; goto _test_eof;
419
+ _test_eof8: cs = 8; goto _test_eof;
420
+ _test_eof9: cs = 9; goto _test_eof;
421
+ _test_eof10: cs = 10; goto _test_eof;
422
+ _test_eof11: cs = 11; goto _test_eof;
423
+ _test_eof12: cs = 12; goto _test_eof;
424
+ _test_eof13: cs = 13; goto _test_eof;
425
+ _test_eof14: cs = 14; goto _test_eof;
426
+ _test_eof15: cs = 15; goto _test_eof;
427
+ _test_eof16: cs = 16; goto _test_eof;
428
+ _test_eof17: cs = 17; goto _test_eof;
429
+ _test_eof18: cs = 18; goto _test_eof;
430
+ _test_eof27: cs = 27; goto _test_eof;
431
+ _test_eof19: cs = 19; goto _test_eof;
432
+ _test_eof20: cs = 20; goto _test_eof;
433
+ _test_eof21: cs = 21; goto _test_eof;
434
+ _test_eof22: cs = 22; goto _test_eof;
435
+ _test_eof23: cs = 23; goto _test_eof;
436
+ _test_eof24: cs = 24; goto _test_eof;
437
+ _test_eof25: cs = 25; goto _test_eof;
438
+ _test_eof26: cs = 26; goto _test_eof;
433
439
 
434
440
  _test_eof: {}
435
441
  _out: {}
436
442
  }
437
443
 
438
- #line 159 "parser.rl"
444
+ #line 167 "parser.rl"
439
445
 
440
446
  if (cs >= JSON_object_first_final) {
441
- if (RTEST(json->create_id)) {
442
- VALUE klassname = rb_hash_aref(*result, json->create_id);
447
+ if (json->create_additions) {
448
+ VALUE klassname;
449
+ if (NIL_P(json->object_class)) {
450
+ klassname = rb_hash_aref(*result, json->create_id);
451
+ } else {
452
+ klassname = rb_funcall(*result, i_aref, 1, json->create_id);
453
+ }
443
454
  if (!NIL_P(klassname)) {
444
455
  VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
445
- if RTEST(rb_funcall(klass, i_json_creatable_p, 0)) {
456
+ if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
446
457
  *result = rb_funcall(klass, i_json_create, 1, *result);
447
458
  }
448
459
  }
@@ -454,7 +465,8 @@ case 26:
454
465
  }
455
466
 
456
467
 
457
- #line 457 "parser.c"
468
+
469
+ #line 470 "parser.c"
458
470
  static const int JSON_value_start = 1;
459
471
  static const int JSON_value_first_final = 21;
460
472
  static const int JSON_value_error = 0;
@@ -462,22 +474,22 @@ static const int JSON_value_error = 0;
462
474
  static const int JSON_value_en_main = 1;
463
475
 
464
476
 
465
- #line 257 "parser.rl"
477
+ #line 271 "parser.rl"
466
478
 
467
479
 
468
480
  static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
469
481
  {
470
482
  int cs = EVIL;
471
483
 
472
-
473
- #line 473 "parser.c"
484
+
485
+ #line 486 "parser.c"
474
486
  {
475
487
  cs = JSON_value_start;
476
488
  }
477
489
 
478
- #line 264 "parser.rl"
479
-
480
- #line 480 "parser.c"
490
+ #line 278 "parser.rl"
491
+
492
+ #line 493 "parser.c"
481
493
  {
482
494
  if ( p == pe )
483
495
  goto _test_eof;
@@ -502,17 +514,17 @@ st0:
502
514
  cs = 0;
503
515
  goto _out;
504
516
  tr0:
505
- #line 205 "parser.rl"
517
+ #line 219 "parser.rl"
506
518
  {
507
519
  char *np = JSON_parse_string(json, p, pe, result);
508
520
  if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
509
521
  }
510
522
  goto st21;
511
523
  tr2:
512
- #line 210 "parser.rl"
524
+ #line 224 "parser.rl"
513
525
  {
514
526
  char *np;
515
- if(pe > p + 9 && !strncmp(MinusInfinity, p, 9)) {
527
+ if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
516
528
  if (json->allow_nan) {
517
529
  *result = CMinusInfinity;
518
530
  {p = (( p + 10))-1;}
@@ -529,8 +541,8 @@ tr2:
529
541
  }
530
542
  goto st21;
531
543
  tr5:
532
- #line 228 "parser.rl"
533
- {
544
+ #line 242 "parser.rl"
545
+ {
534
546
  char *np;
535
547
  json->current_nesting++;
536
548
  np = JSON_parse_array(json, p, pe, result);
@@ -539,8 +551,8 @@ tr5:
539
551
  }
540
552
  goto st21;
541
553
  tr9:
542
- #line 236 "parser.rl"
543
- {
554
+ #line 250 "parser.rl"
555
+ {
544
556
  char *np;
545
557
  json->current_nesting++;
546
558
  np = JSON_parse_object(json, p, pe, result);
@@ -549,7 +561,7 @@ tr9:
549
561
  }
550
562
  goto st21;
551
563
  tr16:
552
- #line 198 "parser.rl"
564
+ #line 212 "parser.rl"
553
565
  {
554
566
  if (json->allow_nan) {
555
567
  *result = CInfinity;
@@ -559,7 +571,7 @@ tr16:
559
571
  }
560
572
  goto st21;
561
573
  tr18:
562
- #line 191 "parser.rl"
574
+ #line 205 "parser.rl"
563
575
  {
564
576
  if (json->allow_nan) {
565
577
  *result = CNaN;
@@ -569,19 +581,19 @@ tr18:
569
581
  }
570
582
  goto st21;
571
583
  tr22:
572
- #line 185 "parser.rl"
584
+ #line 199 "parser.rl"
573
585
  {
574
586
  *result = Qfalse;
575
587
  }
576
588
  goto st21;
577
589
  tr25:
578
- #line 182 "parser.rl"
590
+ #line 196 "parser.rl"
579
591
  {
580
592
  *result = Qnil;
581
593
  }
582
594
  goto st21;
583
595
  tr28:
584
- #line 188 "parser.rl"
596
+ #line 202 "parser.rl"
585
597
  {
586
598
  *result = Qtrue;
587
599
  }
@@ -590,9 +602,9 @@ st21:
590
602
  if ( ++p == pe )
591
603
  goto _test_eof21;
592
604
  case 21:
593
- #line 244 "parser.rl"
605
+ #line 258 "parser.rl"
594
606
  { p--; {p++; cs = 21; goto _out;} }
595
- #line 595 "parser.c"
607
+ #line 608 "parser.c"
596
608
  goto st0;
597
609
  st2:
598
610
  if ( ++p == pe )
@@ -728,32 +740,32 @@ case 20:
728
740
  goto tr28;
729
741
  goto st0;
730
742
  }
731
- _test_eof21: cs = 21; goto _test_eof;
732
- _test_eof2: cs = 2; goto _test_eof;
733
- _test_eof3: cs = 3; goto _test_eof;
734
- _test_eof4: cs = 4; goto _test_eof;
735
- _test_eof5: cs = 5; goto _test_eof;
736
- _test_eof6: cs = 6; goto _test_eof;
737
- _test_eof7: cs = 7; goto _test_eof;
738
- _test_eof8: cs = 8; goto _test_eof;
739
- _test_eof9: cs = 9; goto _test_eof;
740
- _test_eof10: cs = 10; goto _test_eof;
741
- _test_eof11: cs = 11; goto _test_eof;
742
- _test_eof12: cs = 12; goto _test_eof;
743
- _test_eof13: cs = 13; goto _test_eof;
744
- _test_eof14: cs = 14; goto _test_eof;
745
- _test_eof15: cs = 15; goto _test_eof;
746
- _test_eof16: cs = 16; goto _test_eof;
747
- _test_eof17: cs = 17; goto _test_eof;
748
- _test_eof18: cs = 18; goto _test_eof;
749
- _test_eof19: cs = 19; goto _test_eof;
750
- _test_eof20: cs = 20; goto _test_eof;
743
+ _test_eof21: cs = 21; goto _test_eof;
744
+ _test_eof2: cs = 2; goto _test_eof;
745
+ _test_eof3: cs = 3; goto _test_eof;
746
+ _test_eof4: cs = 4; goto _test_eof;
747
+ _test_eof5: cs = 5; goto _test_eof;
748
+ _test_eof6: cs = 6; goto _test_eof;
749
+ _test_eof7: cs = 7; goto _test_eof;
750
+ _test_eof8: cs = 8; goto _test_eof;
751
+ _test_eof9: cs = 9; goto _test_eof;
752
+ _test_eof10: cs = 10; goto _test_eof;
753
+ _test_eof11: cs = 11; goto _test_eof;
754
+ _test_eof12: cs = 12; goto _test_eof;
755
+ _test_eof13: cs = 13; goto _test_eof;
756
+ _test_eof14: cs = 14; goto _test_eof;
757
+ _test_eof15: cs = 15; goto _test_eof;
758
+ _test_eof16: cs = 16; goto _test_eof;
759
+ _test_eof17: cs = 17; goto _test_eof;
760
+ _test_eof18: cs = 18; goto _test_eof;
761
+ _test_eof19: cs = 19; goto _test_eof;
762
+ _test_eof20: cs = 20; goto _test_eof;
751
763
 
752
764
  _test_eof: {}
753
765
  _out: {}
754
766
  }
755
767
 
756
- #line 265 "parser.rl"
768
+ #line 279 "parser.rl"
757
769
 
758
770
  if (cs >= JSON_value_first_final) {
759
771
  return p;
@@ -763,31 +775,31 @@ case 20:
763
775
  }
764
776
 
765
777
 
766
- #line 766 "parser.c"
778
+ #line 779 "parser.c"
767
779
  static const int JSON_integer_start = 1;
768
- static const int JSON_integer_first_final = 5;
780
+ static const int JSON_integer_first_final = 3;
769
781
  static const int JSON_integer_error = 0;
770
782
 
771
783
  static const int JSON_integer_en_main = 1;
772
784
 
773
785
 
774
- #line 281 "parser.rl"
786
+ #line 295 "parser.rl"
775
787
 
776
788
 
777
789
  static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
778
790
  {
779
791
  int cs = EVIL;
780
792
 
781
-
782
- #line 782 "parser.c"
793
+
794
+ #line 795 "parser.c"
783
795
  {
784
796
  cs = JSON_integer_start;
785
797
  }
786
798
 
787
- #line 288 "parser.rl"
799
+ #line 302 "parser.rl"
788
800
  json->memo = p;
789
-
790
- #line 790 "parser.c"
801
+
802
+ #line 803 "parser.c"
791
803
  {
792
804
  if ( p == pe )
793
805
  goto _test_eof;
@@ -799,7 +811,7 @@ case 1:
799
811
  case 48: goto st3;
800
812
  }
801
813
  if ( 49 <= (*p) && (*p) <= 57 )
802
- goto st4;
814
+ goto st5;
803
815
  goto st0;
804
816
  st0:
805
817
  cs = 0;
@@ -811,7 +823,7 @@ case 2:
811
823
  if ( (*p) == 48 )
812
824
  goto st3;
813
825
  if ( 49 <= (*p) && (*p) <= 57 )
814
- goto st4;
826
+ goto st5;
815
827
  goto st0;
816
828
  st3:
817
829
  if ( ++p == pe )
@@ -821,37 +833,40 @@ case 3:
821
833
  goto st0;
822
834
  goto tr4;
823
835
  tr4:
824
- #line 278 "parser.rl"
825
- { p--; {p++; cs = 5; goto _out;} }
826
- goto st5;
827
- st5:
828
- if ( ++p == pe )
829
- goto _test_eof5;
830
- case 5:
831
- #line 831 "parser.c"
832
- goto st0;
836
+ #line 292 "parser.rl"
837
+ { p--; {p++; cs = 4; goto _out;} }
838
+ goto st4;
833
839
  st4:
834
840
  if ( ++p == pe )
835
841
  goto _test_eof4;
836
842
  case 4:
843
+ #line 844 "parser.c"
844
+ goto st0;
845
+ st5:
846
+ if ( ++p == pe )
847
+ goto _test_eof5;
848
+ case 5:
837
849
  if ( 48 <= (*p) && (*p) <= 57 )
838
- goto st4;
850
+ goto st5;
839
851
  goto tr4;
840
852
  }
841
- _test_eof2: cs = 2; goto _test_eof;
842
- _test_eof3: cs = 3; goto _test_eof;
843
- _test_eof5: cs = 5; goto _test_eof;
844
- _test_eof4: cs = 4; goto _test_eof;
853
+ _test_eof2: cs = 2; goto _test_eof;
854
+ _test_eof3: cs = 3; goto _test_eof;
855
+ _test_eof4: cs = 4; goto _test_eof;
856
+ _test_eof5: cs = 5; goto _test_eof;
845
857
 
846
858
  _test_eof: {}
847
859
  _out: {}
848
860
  }
849
861
 
850
- #line 290 "parser.rl"
862
+ #line 304 "parser.rl"
851
863
 
852
864
  if (cs >= JSON_integer_first_final) {
853
865
  long len = p - json->memo;
854
- *result = rb_Integer(rb_str_new(json->memo, len));
866
+ fbuffer_clear(json->fbuffer);
867
+ fbuffer_append(json->fbuffer, json->memo, len);
868
+ fbuffer_append_char(json->fbuffer, '\0');
869
+ *result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
855
870
  return p + 1;
856
871
  } else {
857
872
  return NULL;
@@ -859,31 +874,31 @@ case 4:
859
874
  }
860
875
 
861
876
 
862
- #line 862 "parser.c"
877
+ #line 878 "parser.c"
863
878
  static const int JSON_float_start = 1;
864
- static const int JSON_float_first_final = 10;
879
+ static const int JSON_float_first_final = 8;
865
880
  static const int JSON_float_error = 0;
866
881
 
867
882
  static const int JSON_float_en_main = 1;
868
883
 
869
884
 
870
- #line 312 "parser.rl"
885
+ #line 329 "parser.rl"
871
886
 
872
887
 
873
888
  static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
874
889
  {
875
890
  int cs = EVIL;
876
891
 
877
-
878
- #line 878 "parser.c"
892
+
893
+ #line 894 "parser.c"
879
894
  {
880
895
  cs = JSON_float_start;
881
896
  }
882
897
 
883
- #line 319 "parser.rl"
898
+ #line 336 "parser.rl"
884
899
  json->memo = p;
885
-
886
- #line 886 "parser.c"
900
+
901
+ #line 902 "parser.c"
887
902
  {
888
903
  if ( p == pe )
889
904
  goto _test_eof;
@@ -895,7 +910,7 @@ case 1:
895
910
  case 48: goto st3;
896
911
  }
897
912
  if ( 49 <= (*p) && (*p) <= 57 )
898
- goto st9;
913
+ goto st7;
899
914
  goto st0;
900
915
  st0:
901
916
  cs = 0;
@@ -907,7 +922,7 @@ case 2:
907
922
  if ( (*p) == 48 )
908
923
  goto st3;
909
924
  if ( 49 <= (*p) && (*p) <= 57 )
910
- goto st9;
925
+ goto st7;
911
926
  goto st0;
912
927
  st3:
913
928
  if ( ++p == pe )
@@ -915,8 +930,8 @@ st3:
915
930
  case 3:
916
931
  switch( (*p) ) {
917
932
  case 46: goto st4;
918
- case 69: goto st6;
919
- case 101: goto st6;
933
+ case 69: goto st5;
934
+ case 101: goto st5;
920
935
  }
921
936
  goto st0;
922
937
  st4:
@@ -924,96 +939,99 @@ st4:
924
939
  goto _test_eof4;
925
940
  case 4:
926
941
  if ( 48 <= (*p) && (*p) <= 57 )
927
- goto st5;
942
+ goto st8;
928
943
  goto st0;
929
- st5:
944
+ st8:
930
945
  if ( ++p == pe )
931
- goto _test_eof5;
932
- case 5:
946
+ goto _test_eof8;
947
+ case 8:
933
948
  switch( (*p) ) {
934
- case 69: goto st6;
935
- case 101: goto st6;
949
+ case 69: goto st5;
950
+ case 101: goto st5;
936
951
  }
937
952
  if ( (*p) > 46 ) {
938
953
  if ( 48 <= (*p) && (*p) <= 57 )
939
- goto st5;
954
+ goto st8;
940
955
  } else if ( (*p) >= 45 )
941
956
  goto st0;
942
- goto tr7;
943
- tr7:
944
- #line 306 "parser.rl"
945
- { p--; {p++; cs = 10; goto _out;} }
946
- goto st10;
947
- st10:
957
+ goto tr9;
958
+ tr9:
959
+ #line 323 "parser.rl"
960
+ { p--; {p++; cs = 9; goto _out;} }
961
+ goto st9;
962
+ st9:
948
963
  if ( ++p == pe )
949
- goto _test_eof10;
950
- case 10:
951
- #line 951 "parser.c"
964
+ goto _test_eof9;
965
+ case 9:
966
+ #line 967 "parser.c"
952
967
  goto st0;
953
- st6:
968
+ st5:
954
969
  if ( ++p == pe )
955
- goto _test_eof6;
956
- case 6:
970
+ goto _test_eof5;
971
+ case 5:
957
972
  switch( (*p) ) {
958
- case 43: goto st7;
959
- case 45: goto st7;
973
+ case 43: goto st6;
974
+ case 45: goto st6;
960
975
  }
961
976
  if ( 48 <= (*p) && (*p) <= 57 )
962
- goto st8;
977
+ goto st10;
963
978
  goto st0;
964
- st7:
979
+ st6:
965
980
  if ( ++p == pe )
966
- goto _test_eof7;
967
- case 7:
981
+ goto _test_eof6;
982
+ case 6:
968
983
  if ( 48 <= (*p) && (*p) <= 57 )
969
- goto st8;
984
+ goto st10;
970
985
  goto st0;
971
- st8:
986
+ st10:
972
987
  if ( ++p == pe )
973
- goto _test_eof8;
974
- case 8:
988
+ goto _test_eof10;
989
+ case 10:
975
990
  switch( (*p) ) {
976
991
  case 69: goto st0;
977
992
  case 101: goto st0;
978
993
  }
979
994
  if ( (*p) > 46 ) {
980
995
  if ( 48 <= (*p) && (*p) <= 57 )
981
- goto st8;
996
+ goto st10;
982
997
  } else if ( (*p) >= 45 )
983
998
  goto st0;
984
- goto tr7;
985
- st9:
999
+ goto tr9;
1000
+ st7:
986
1001
  if ( ++p == pe )
987
- goto _test_eof9;
988
- case 9:
1002
+ goto _test_eof7;
1003
+ case 7:
989
1004
  switch( (*p) ) {
990
1005
  case 46: goto st4;
991
- case 69: goto st6;
992
- case 101: goto st6;
1006
+ case 69: goto st5;
1007
+ case 101: goto st5;
993
1008
  }
994
1009
  if ( 48 <= (*p) && (*p) <= 57 )
995
- goto st9;
1010
+ goto st7;
996
1011
  goto st0;
997
1012
  }
998
- _test_eof2: cs = 2; goto _test_eof;
999
- _test_eof3: cs = 3; goto _test_eof;
1000
- _test_eof4: cs = 4; goto _test_eof;
1001
- _test_eof5: cs = 5; goto _test_eof;
1002
- _test_eof10: cs = 10; goto _test_eof;
1003
- _test_eof6: cs = 6; goto _test_eof;
1004
- _test_eof7: cs = 7; goto _test_eof;
1005
- _test_eof8: cs = 8; goto _test_eof;
1006
- _test_eof9: cs = 9; goto _test_eof;
1013
+ _test_eof2: cs = 2; goto _test_eof;
1014
+ _test_eof3: cs = 3; goto _test_eof;
1015
+ _test_eof4: cs = 4; goto _test_eof;
1016
+ _test_eof8: cs = 8; goto _test_eof;
1017
+ _test_eof9: cs = 9; goto _test_eof;
1018
+ _test_eof5: cs = 5; goto _test_eof;
1019
+ _test_eof6: cs = 6; goto _test_eof;
1020
+ _test_eof10: cs = 10; goto _test_eof;
1021
+ _test_eof7: cs = 7; goto _test_eof;
1007
1022
 
1008
1023
  _test_eof: {}
1009
1024
  _out: {}
1010
1025
  }
1011
1026
 
1012
- #line 321 "parser.rl"
1027
+ #line 338 "parser.rl"
1013
1028
 
1014
1029
  if (cs >= JSON_float_first_final) {
1015
1030
  long len = p - json->memo;
1016
- *result = rb_Float(rb_str_new(json->memo, len));
1031
+ fbuffer_clear(json->fbuffer);
1032
+ fbuffer_append(json->fbuffer, json->memo, len);
1033
+ fbuffer_append_char(json->fbuffer, '\0');
1034
+ *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
1017
1035
  return p + 1;
1018
1036
  } else {
1019
1037
  return NULL;
@@ -1022,7 +1040,7 @@ case 9:
1022
1040
 
1023
1041
 
1024
1042
 
1025
- #line 1025 "parser.c"
1043
+ #line 1044 "parser.c"
1026
1044
  static const int JSON_array_start = 1;
1027
1045
  static const int JSON_array_first_final = 17;
1028
1046
  static const int JSON_array_error = 0;
@@ -1030,7 +1048,7 @@ static const int JSON_array_error = 0;
1030
1048
  static const int JSON_array_en_main = 1;
1031
1049
 
1032
1050
 
1033
- #line 357 "parser.rl"
1051
+ #line 381 "parser.rl"
1034
1052
 
1035
1053
 
1036
1054
  static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1043,15 +1061,15 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
1043
1061
  }
1044
1062
  *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
1045
1063
 
1046
-
1047
- #line 1047 "parser.c"
1064
+
1065
+ #line 1066 "parser.c"
1048
1066
  {
1049
1067
  cs = JSON_array_start;
1050
1068
  }
1051
1069
 
1052
- #line 370 "parser.rl"
1053
-
1054
- #line 1054 "parser.c"
1070
+ #line 394 "parser.rl"
1071
+
1072
+ #line 1073 "parser.c"
1055
1073
  {
1056
1074
  if ( p == pe )
1057
1075
  goto _test_eof;
@@ -1090,14 +1108,18 @@ case 2:
1090
1108
  goto st2;
1091
1109
  goto st0;
1092
1110
  tr2:
1093
- #line 338 "parser.rl"
1111
+ #line 358 "parser.rl"
1094
1112
  {
1095
1113
  VALUE v = Qnil;
1096
- char *np = JSON_parse_value(json, p, pe, &v);
1114
+ char *np = JSON_parse_value(json, p, pe, &v);
1097
1115
  if (np == NULL) {
1098
1116
  p--; {p++; cs = 3; goto _out;}
1099
1117
  } else {
1100
- rb_ary_push(*result, v);
1118
+ if (NIL_P(json->array_class)) {
1119
+ rb_ary_push(*result, v);
1120
+ } else {
1121
+ rb_funcall(*result, i_leftshift, 1, v);
1122
+ }
1101
1123
  {p = (( np))-1;}
1102
1124
  }
1103
1125
  }
@@ -1106,7 +1128,7 @@ st3:
1106
1128
  if ( ++p == pe )
1107
1129
  goto _test_eof3;
1108
1130
  case 3:
1109
- #line 1109 "parser.c"
1131
+ #line 1132 "parser.c"
1110
1132
  switch( (*p) ) {
1111
1133
  case 13: goto st3;
1112
1134
  case 32: goto st3;
@@ -1206,14 +1228,14 @@ case 12:
1206
1228
  goto st3;
1207
1229
  goto st12;
1208
1230
  tr4:
1209
- #line 349 "parser.rl"
1231
+ #line 373 "parser.rl"
1210
1232
  { p--; {p++; cs = 17; goto _out;} }
1211
1233
  goto st17;
1212
1234
  st17:
1213
1235
  if ( ++p == pe )
1214
1236
  goto _test_eof17;
1215
1237
  case 17:
1216
- #line 1216 "parser.c"
1238
+ #line 1239 "parser.c"
1217
1239
  goto st0;
1218
1240
  st13:
1219
1241
  if ( ++p == pe )
@@ -1248,28 +1270,28 @@ case 16:
1248
1270
  goto st2;
1249
1271
  goto st16;
1250
1272
  }
1251
- _test_eof2: cs = 2; goto _test_eof;
1252
- _test_eof3: cs = 3; goto _test_eof;
1253
- _test_eof4: cs = 4; goto _test_eof;
1254
- _test_eof5: cs = 5; goto _test_eof;
1255
- _test_eof6: cs = 6; goto _test_eof;
1256
- _test_eof7: cs = 7; goto _test_eof;
1257
- _test_eof8: cs = 8; goto _test_eof;
1258
- _test_eof9: cs = 9; goto _test_eof;
1259
- _test_eof10: cs = 10; goto _test_eof;
1260
- _test_eof11: cs = 11; goto _test_eof;
1261
- _test_eof12: cs = 12; goto _test_eof;
1262
- _test_eof17: cs = 17; goto _test_eof;
1263
- _test_eof13: cs = 13; goto _test_eof;
1264
- _test_eof14: cs = 14; goto _test_eof;
1265
- _test_eof15: cs = 15; goto _test_eof;
1266
- _test_eof16: cs = 16; goto _test_eof;
1273
+ _test_eof2: cs = 2; goto _test_eof;
1274
+ _test_eof3: cs = 3; goto _test_eof;
1275
+ _test_eof4: cs = 4; goto _test_eof;
1276
+ _test_eof5: cs = 5; goto _test_eof;
1277
+ _test_eof6: cs = 6; goto _test_eof;
1278
+ _test_eof7: cs = 7; goto _test_eof;
1279
+ _test_eof8: cs = 8; goto _test_eof;
1280
+ _test_eof9: cs = 9; goto _test_eof;
1281
+ _test_eof10: cs = 10; goto _test_eof;
1282
+ _test_eof11: cs = 11; goto _test_eof;
1283
+ _test_eof12: cs = 12; goto _test_eof;
1284
+ _test_eof17: cs = 17; goto _test_eof;
1285
+ _test_eof13: cs = 13; goto _test_eof;
1286
+ _test_eof14: cs = 14; goto _test_eof;
1287
+ _test_eof15: cs = 15; goto _test_eof;
1288
+ _test_eof16: cs = 16; goto _test_eof;
1267
1289
 
1268
1290
  _test_eof: {}
1269
1291
  _out: {}
1270
1292
  }
1271
1293
 
1272
- #line 371 "parser.rl"
1294
+ #line 395 "parser.rl"
1273
1295
 
1274
1296
  if(cs >= JSON_array_first_final) {
1275
1297
  return p + 1;
@@ -1283,6 +1305,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1283
1305
  {
1284
1306
  char *p = string, *pe = string, *unescape;
1285
1307
  int unescape_len;
1308
+ char buf[4];
1286
1309
 
1287
1310
  while (pe < stringEnd) {
1288
1311
  if (*pe == '\\') {
@@ -1312,10 +1335,9 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1312
1335
  unescape = (char *) "\f";
1313
1336
  break;
1314
1337
  case 'u':
1315
- if (pe > stringEnd - 4) {
1338
+ if (pe > stringEnd - 4) {
1316
1339
  return Qnil;
1317
1340
  } else {
1318
- char buf[4];
1319
1341
  UTF32 ch = unescape_unicode((unsigned char *) ++pe);
1320
1342
  pe += 3;
1321
1343
  if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
@@ -1350,7 +1372,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1350
1372
  }
1351
1373
 
1352
1374
 
1353
- #line 1353 "parser.c"
1375
+ #line 1376 "parser.c"
1354
1376
  static const int JSON_string_start = 1;
1355
1377
  static const int JSON_string_first_final = 8;
1356
1378
  static const int JSON_string_error = 0;
@@ -1358,24 +1380,37 @@ static const int JSON_string_error = 0;
1358
1380
  static const int JSON_string_en_main = 1;
1359
1381
 
1360
1382
 
1361
- #line 470 "parser.rl"
1383
+ #line 494 "parser.rl"
1362
1384
 
1363
1385
 
1386
+ static int
1387
+ match_i(VALUE regexp, VALUE klass, VALUE memo)
1388
+ {
1389
+ if (regexp == Qundef) return ST_STOP;
1390
+ if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) &&
1391
+ RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) {
1392
+ rb_ary_push(memo, klass);
1393
+ return ST_STOP;
1394
+ }
1395
+ return ST_CONTINUE;
1396
+ }
1397
+
1364
1398
  static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
1365
1399
  {
1366
1400
  int cs = EVIL;
1401
+ VALUE match_string;
1367
1402
 
1368
1403
  *result = rb_str_buf_new(0);
1369
-
1370
- #line 1370 "parser.c"
1404
+
1405
+ #line 1406 "parser.c"
1371
1406
  {
1372
1407
  cs = JSON_string_start;
1373
1408
  }
1374
1409
 
1375
- #line 478 "parser.rl"
1410
+ #line 515 "parser.rl"
1376
1411
  json->memo = p;
1377
-
1378
- #line 1378 "parser.c"
1412
+
1413
+ #line 1414 "parser.c"
1379
1414
  {
1380
1415
  if ( p == pe )
1381
1416
  goto _test_eof;
@@ -1400,25 +1435,25 @@ case 2:
1400
1435
  goto st0;
1401
1436
  goto st2;
1402
1437
  tr2:
1403
- #line 456 "parser.rl"
1438
+ #line 480 "parser.rl"
1404
1439
  {
1405
1440
  *result = json_string_unescape(*result, json->memo + 1, p);
1406
1441
  if (NIL_P(*result)) {
1407
- p--;
1408
- {p++; cs = 8; goto _out;}
1409
- } else {
1410
- FORCE_UTF8(*result);
1411
- {p = (( p + 1))-1;}
1412
- }
1413
- }
1414
- #line 467 "parser.rl"
1442
+ p--;
1443
+ {p++; cs = 8; goto _out;}
1444
+ } else {
1445
+ FORCE_UTF8(*result);
1446
+ {p = (( p + 1))-1;}
1447
+ }
1448
+ }
1449
+ #line 491 "parser.rl"
1415
1450
  { p--; {p++; cs = 8; goto _out;} }
1416
1451
  goto st8;
1417
1452
  st8:
1418
1453
  if ( ++p == pe )
1419
1454
  goto _test_eof8;
1420
1455
  case 8:
1421
- #line 1421 "parser.c"
1456
+ #line 1457 "parser.c"
1422
1457
  goto st0;
1423
1458
  st3:
1424
1459
  if ( ++p == pe )
@@ -1482,19 +1517,30 @@ case 7:
1482
1517
  goto st2;
1483
1518
  goto st0;
1484
1519
  }
1485
- _test_eof2: cs = 2; goto _test_eof;
1486
- _test_eof8: cs = 8; goto _test_eof;
1487
- _test_eof3: cs = 3; goto _test_eof;
1488
- _test_eof4: cs = 4; goto _test_eof;
1489
- _test_eof5: cs = 5; goto _test_eof;
1490
- _test_eof6: cs = 6; goto _test_eof;
1491
- _test_eof7: cs = 7; goto _test_eof;
1520
+ _test_eof2: cs = 2; goto _test_eof;
1521
+ _test_eof8: cs = 8; goto _test_eof;
1522
+ _test_eof3: cs = 3; goto _test_eof;
1523
+ _test_eof4: cs = 4; goto _test_eof;
1524
+ _test_eof5: cs = 5; goto _test_eof;
1525
+ _test_eof6: cs = 6; goto _test_eof;
1526
+ _test_eof7: cs = 7; goto _test_eof;
1492
1527
 
1493
1528
  _test_eof: {}
1494
1529
  _out: {}
1495
1530
  }
1496
1531
 
1497
- #line 480 "parser.rl"
1532
+ #line 517 "parser.rl"
1533
+
1534
+ if (json->create_additions && RTEST(match_string = json->match_string)) {
1535
+ VALUE klass;
1536
+ VALUE memo = rb_ary_new2(2);
1537
+ rb_ary_push(memo, *result);
1538
+ rb_hash_foreach(match_string, match_i, memo);
1539
+ klass = rb_ary_entry(memo, 1);
1540
+ if (RTEST(klass)) {
1541
+ *result = rb_funcall(klass, i_json_create, 1, *result);
1542
+ }
1543
+ }
1498
1544
 
1499
1545
  if (json->symbolize_names && json->parsing_name) {
1500
1546
  *result = rb_str_intern(*result);
@@ -1506,20 +1552,7 @@ case 7:
1506
1552
  }
1507
1553
  }
1508
1554
 
1509
-
1510
-
1511
- #line 1511 "parser.c"
1512
- static const int JSON_start = 1;
1513
- static const int JSON_first_final = 10;
1514
- static const int JSON_error = 0;
1515
-
1516
- static const int JSON_en_main = 1;
1517
-
1518
-
1519
- #line 517 "parser.rl"
1520
-
1521
-
1522
- /*
1555
+ /*
1523
1556
  * Document-class: JSON::Ext::Parser
1524
1557
  *
1525
1558
  * This is the JSON parser implemented as a C extension. It can be configured
@@ -1543,22 +1576,15 @@ static VALUE convert_encoding(VALUE source)
1543
1576
  VALUE encoding = rb_funcall(source, i_encoding, 0);
1544
1577
  if (encoding == CEncoding_ASCII_8BIT) {
1545
1578
  if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
1546
- source = rb_str_dup(source);
1547
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_32BE);
1548
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
1579
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
1549
1580
  } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
1550
- source = rb_str_dup(source);
1551
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_16BE);
1552
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
1581
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
1553
1582
  } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
1554
- source = rb_str_dup(source);
1555
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_32LE);
1556
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
1583
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
1557
1584
  } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
1558
- source = rb_str_dup(source);
1559
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_16LE);
1560
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
1585
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
1561
1586
  } else {
1587
+ source = rb_str_dup(source);
1562
1588
  FORCE_UTF8(source);
1563
1589
  }
1564
1590
  } else {
@@ -1592,7 +1618,7 @@ static VALUE convert_encoding(VALUE source)
1592
1618
  * _opts_ can have the following keys:
1593
1619
  * * *max_nesting*: The maximum depth of nesting allowed in the parsed data
1594
1620
  * structures. Disable depth checking with :max_nesting => false|nil|0, it
1595
- * defaults to 19.
1621
+ * defaults to 100.
1596
1622
  * * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
1597
1623
  * defiance of RFC 4627 to be parsed by the Parser. This option defaults to
1598
1624
  * false.
@@ -1607,14 +1633,13 @@ static VALUE convert_encoding(VALUE source)
1607
1633
  */
1608
1634
  static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1609
1635
  {
1610
- char *ptr;
1611
- long len;
1612
1636
  VALUE source, opts;
1613
- GET_PARSER;
1637
+ GET_PARSER_INIT;
1638
+
1639
+ if (json->Vsource) {
1640
+ rb_raise(rb_eTypeError, "already initialized instance");
1641
+ }
1614
1642
  rb_scan_args(argc, argv, "11", &source, &opts);
1615
- source = convert_encoding(StringValue(source));
1616
- ptr = RSTRING_PTR(source);
1617
- len = RSTRING_LEN(source);
1618
1643
  if (!NIL_P(opts)) {
1619
1644
  opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
1620
1645
  if (NIL_P(opts)) {
@@ -1630,30 +1655,36 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1630
1655
  json->max_nesting = 0;
1631
1656
  }
1632
1657
  } else {
1633
- json->max_nesting = 19;
1658
+ json->max_nesting = 100;
1634
1659
  }
1635
1660
  tmp = ID2SYM(i_allow_nan);
1636
1661
  if (option_given_p(opts, tmp)) {
1637
- VALUE allow_nan = rb_hash_aref(opts, tmp);
1638
- json->allow_nan = RTEST(allow_nan) ? 1 : 0;
1662
+ json->allow_nan = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1639
1663
  } else {
1640
1664
  json->allow_nan = 0;
1641
1665
  }
1642
1666
  tmp = ID2SYM(i_symbolize_names);
1643
1667
  if (option_given_p(opts, tmp)) {
1644
- VALUE symbolize_names = rb_hash_aref(opts, tmp);
1645
- json->symbolize_names = RTEST(symbolize_names) ? 1 : 0;
1668
+ json->symbolize_names = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
1646
1669
  } else {
1647
1670
  json->symbolize_names = 0;
1648
1671
  }
1672
+ tmp = ID2SYM(i_quirks_mode);
1673
+ if (option_given_p(opts, tmp)) {
1674
+ VALUE quirks_mode = rb_hash_aref(opts, tmp);
1675
+ json->quirks_mode = RTEST(quirks_mode) ? 1 : 0;
1676
+ } else {
1677
+ json->quirks_mode = 0;
1678
+ }
1649
1679
  tmp = ID2SYM(i_create_additions);
1650
1680
  if (option_given_p(opts, tmp)) {
1651
- VALUE create_additions = rb_hash_aref(opts, tmp);
1652
- if (RTEST(create_additions)) {
1653
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
1654
- } else {
1655
- json->create_id = Qnil;
1656
- }
1681
+ json->create_additions = RTEST(rb_hash_aref(opts, tmp));
1682
+ } else {
1683
+ json->create_additions = 0;
1684
+ }
1685
+ tmp = ID2SYM(i_create_id);
1686
+ if (option_given_p(opts, tmp)) {
1687
+ json->create_id = rb_hash_aref(opts, tmp);
1657
1688
  } else {
1658
1689
  json->create_id = rb_funcall(mJSON, i_create_id, 0);
1659
1690
  }
@@ -1669,45 +1700,64 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1669
1700
  } else {
1670
1701
  json->array_class = Qnil;
1671
1702
  }
1703
+ tmp = ID2SYM(i_match_string);
1704
+ if (option_given_p(opts, tmp)) {
1705
+ VALUE match_string = rb_hash_aref(opts, tmp);
1706
+ json->match_string = RTEST(match_string) ? match_string : Qnil;
1707
+ } else {
1708
+ json->match_string = Qnil;
1709
+ }
1672
1710
  }
1673
1711
  } else {
1674
- json->max_nesting = 19;
1712
+ json->max_nesting = 100;
1675
1713
  json->allow_nan = 0;
1714
+ json->create_additions = 1;
1676
1715
  json->create_id = rb_funcall(mJSON, i_create_id, 0);
1677
1716
  json->object_class = Qnil;
1678
1717
  json->array_class = Qnil;
1679
1718
  }
1719
+ source = rb_convert_type(source, T_STRING, "String", "to_str");
1720
+ if (!json->quirks_mode) {
1721
+ source = convert_encoding(StringValue(source));
1722
+ }
1680
1723
  json->current_nesting = 0;
1681
- json->len = len;
1682
- json->source = ptr;
1724
+ StringValue(source);
1725
+ json->len = RSTRING_LEN(source);
1726
+ json->source = RSTRING_PTR(source);;
1683
1727
  json->Vsource = source;
1684
1728
  return self;
1685
1729
  }
1686
1730
 
1687
- /*
1688
- * call-seq: parse()
1689
- *
1690
- * Parses the current JSON text _source_ and returns the complete data
1691
- * structure as a result.
1692
- */
1693
- static VALUE cParser_parse(VALUE self)
1731
+
1732
+ #line 1733 "parser.c"
1733
+ static const int JSON_start = 1;
1734
+ static const int JSON_first_final = 10;
1735
+ static const int JSON_error = 0;
1736
+
1737
+ static const int JSON_en_main = 1;
1738
+
1739
+
1740
+ #line 740 "parser.rl"
1741
+
1742
+
1743
+ static VALUE cParser_parse_strict(VALUE self)
1694
1744
  {
1695
1745
  char *p, *pe;
1696
1746
  int cs = EVIL;
1697
1747
  VALUE result = Qnil;
1698
1748
  GET_PARSER;
1699
1749
 
1700
-
1701
- #line 1701 "parser.c"
1750
+
1751
+ #line 1752 "parser.c"
1702
1752
  {
1703
1753
  cs = JSON_start;
1704
1754
  }
1705
1755
 
1706
- #line 698 "parser.rl"
1756
+ #line 750 "parser.rl"
1707
1757
  p = json->source;
1708
1758
  pe = p + json->len;
1709
-
1710
- #line 1710 "parser.c"
1759
+
1760
+ #line 1761 "parser.c"
1711
1761
  {
1712
1762
  if ( p == pe )
1713
1763
  goto _test_eof;
@@ -1763,7 +1813,7 @@ case 5:
1763
1813
  goto st1;
1764
1814
  goto st5;
1765
1815
  tr3:
1766
- #line 506 "parser.rl"
1816
+ #line 729 "parser.rl"
1767
1817
  {
1768
1818
  char *np;
1769
1819
  json->current_nesting = 1;
@@ -1772,7 +1822,7 @@ tr3:
1772
1822
  }
1773
1823
  goto st10;
1774
1824
  tr4:
1775
- #line 499 "parser.rl"
1825
+ #line 722 "parser.rl"
1776
1826
  {
1777
1827
  char *np;
1778
1828
  json->current_nesting = 1;
@@ -1784,7 +1834,7 @@ st10:
1784
1834
  if ( ++p == pe )
1785
1835
  goto _test_eof10;
1786
1836
  case 10:
1787
- #line 1787 "parser.c"
1837
+ #line 1838 "parser.c"
1788
1838
  switch( (*p) ) {
1789
1839
  case 13: goto st10;
1790
1840
  case 32: goto st10;
@@ -1826,22 +1876,22 @@ case 9:
1826
1876
  goto st10;
1827
1877
  goto st9;
1828
1878
  }
1829
- _test_eof1: cs = 1; goto _test_eof;
1830
- _test_eof2: cs = 2; goto _test_eof;
1831
- _test_eof3: cs = 3; goto _test_eof;
1832
- _test_eof4: cs = 4; goto _test_eof;
1833
- _test_eof5: cs = 5; goto _test_eof;
1834
- _test_eof10: cs = 10; goto _test_eof;
1835
- _test_eof6: cs = 6; goto _test_eof;
1836
- _test_eof7: cs = 7; goto _test_eof;
1837
- _test_eof8: cs = 8; goto _test_eof;
1838
- _test_eof9: cs = 9; goto _test_eof;
1879
+ _test_eof1: cs = 1; goto _test_eof;
1880
+ _test_eof2: cs = 2; goto _test_eof;
1881
+ _test_eof3: cs = 3; goto _test_eof;
1882
+ _test_eof4: cs = 4; goto _test_eof;
1883
+ _test_eof5: cs = 5; goto _test_eof;
1884
+ _test_eof10: cs = 10; goto _test_eof;
1885
+ _test_eof6: cs = 6; goto _test_eof;
1886
+ _test_eof7: cs = 7; goto _test_eof;
1887
+ _test_eof8: cs = 8; goto _test_eof;
1888
+ _test_eof9: cs = 9; goto _test_eof;
1839
1889
 
1840
1890
  _test_eof: {}
1841
1891
  _out: {}
1842
1892
  }
1843
1893
 
1844
- #line 701 "parser.rl"
1894
+ #line 753 "parser.rl"
1845
1895
 
1846
1896
  if (cs >= JSON_first_final && p == pe) {
1847
1897
  return result;
@@ -1851,10 +1901,202 @@ case 9:
1851
1901
  }
1852
1902
  }
1853
1903
 
1904
+
1905
+
1906
+ #line 1907 "parser.c"
1907
+ static const int JSON_quirks_mode_start = 1;
1908
+ static const int JSON_quirks_mode_first_final = 10;
1909
+ static const int JSON_quirks_mode_error = 0;
1910
+
1911
+ static const int JSON_quirks_mode_en_main = 1;
1912
+
1913
+
1914
+ #line 778 "parser.rl"
1915
+
1916
+
1917
+ static VALUE cParser_parse_quirks_mode(VALUE self)
1918
+ {
1919
+ char *p, *pe;
1920
+ int cs = EVIL;
1921
+ VALUE result = Qnil;
1922
+ GET_PARSER;
1923
+
1924
+
1925
+ #line 1926 "parser.c"
1926
+ {
1927
+ cs = JSON_quirks_mode_start;
1928
+ }
1929
+
1930
+ #line 788 "parser.rl"
1931
+ p = json->source;
1932
+ pe = p + json->len;
1933
+
1934
+ #line 1935 "parser.c"
1935
+ {
1936
+ if ( p == pe )
1937
+ goto _test_eof;
1938
+ switch ( cs )
1939
+ {
1940
+ st1:
1941
+ if ( ++p == pe )
1942
+ goto _test_eof1;
1943
+ case 1:
1944
+ switch( (*p) ) {
1945
+ case 13: goto st1;
1946
+ case 32: goto st1;
1947
+ case 34: goto tr2;
1948
+ case 45: goto tr2;
1949
+ case 47: goto st6;
1950
+ case 73: goto tr2;
1951
+ case 78: goto tr2;
1952
+ case 91: goto tr2;
1953
+ case 102: goto tr2;
1954
+ case 110: goto tr2;
1955
+ case 116: goto tr2;
1956
+ case 123: goto tr2;
1957
+ }
1958
+ if ( (*p) > 10 ) {
1959
+ if ( 48 <= (*p) && (*p) <= 57 )
1960
+ goto tr2;
1961
+ } else if ( (*p) >= 9 )
1962
+ goto st1;
1963
+ goto st0;
1964
+ st0:
1965
+ cs = 0;
1966
+ goto _out;
1967
+ tr2:
1968
+ #line 770 "parser.rl"
1969
+ {
1970
+ char *np = JSON_parse_value(json, p, pe, &result);
1971
+ if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1972
+ }
1973
+ goto st10;
1974
+ st10:
1975
+ if ( ++p == pe )
1976
+ goto _test_eof10;
1977
+ case 10:
1978
+ #line 1979 "parser.c"
1979
+ switch( (*p) ) {
1980
+ case 13: goto st10;
1981
+ case 32: goto st10;
1982
+ case 47: goto st2;
1983
+ }
1984
+ if ( 9 <= (*p) && (*p) <= 10 )
1985
+ goto st10;
1986
+ goto st0;
1987
+ st2:
1988
+ if ( ++p == pe )
1989
+ goto _test_eof2;
1990
+ case 2:
1991
+ switch( (*p) ) {
1992
+ case 42: goto st3;
1993
+ case 47: goto st5;
1994
+ }
1995
+ goto st0;
1996
+ st3:
1997
+ if ( ++p == pe )
1998
+ goto _test_eof3;
1999
+ case 3:
2000
+ if ( (*p) == 42 )
2001
+ goto st4;
2002
+ goto st3;
2003
+ st4:
2004
+ if ( ++p == pe )
2005
+ goto _test_eof4;
2006
+ case 4:
2007
+ switch( (*p) ) {
2008
+ case 42: goto st4;
2009
+ case 47: goto st10;
2010
+ }
2011
+ goto st3;
2012
+ st5:
2013
+ if ( ++p == pe )
2014
+ goto _test_eof5;
2015
+ case 5:
2016
+ if ( (*p) == 10 )
2017
+ goto st10;
2018
+ goto st5;
2019
+ st6:
2020
+ if ( ++p == pe )
2021
+ goto _test_eof6;
2022
+ case 6:
2023
+ switch( (*p) ) {
2024
+ case 42: goto st7;
2025
+ case 47: goto st9;
2026
+ }
2027
+ goto st0;
2028
+ st7:
2029
+ if ( ++p == pe )
2030
+ goto _test_eof7;
2031
+ case 7:
2032
+ if ( (*p) == 42 )
2033
+ goto st8;
2034
+ goto st7;
2035
+ st8:
2036
+ if ( ++p == pe )
2037
+ goto _test_eof8;
2038
+ case 8:
2039
+ switch( (*p) ) {
2040
+ case 42: goto st8;
2041
+ case 47: goto st1;
2042
+ }
2043
+ goto st7;
2044
+ st9:
2045
+ if ( ++p == pe )
2046
+ goto _test_eof9;
2047
+ case 9:
2048
+ if ( (*p) == 10 )
2049
+ goto st1;
2050
+ goto st9;
2051
+ }
2052
+ _test_eof1: cs = 1; goto _test_eof;
2053
+ _test_eof10: cs = 10; goto _test_eof;
2054
+ _test_eof2: cs = 2; goto _test_eof;
2055
+ _test_eof3: cs = 3; goto _test_eof;
2056
+ _test_eof4: cs = 4; goto _test_eof;
2057
+ _test_eof5: cs = 5; goto _test_eof;
2058
+ _test_eof6: cs = 6; goto _test_eof;
2059
+ _test_eof7: cs = 7; goto _test_eof;
2060
+ _test_eof8: cs = 8; goto _test_eof;
2061
+ _test_eof9: cs = 9; goto _test_eof;
2062
+
2063
+ _test_eof: {}
2064
+ _out: {}
2065
+ }
2066
+
2067
+ #line 791 "parser.rl"
2068
+
2069
+ if (cs >= JSON_quirks_mode_first_final && p == pe) {
2070
+ return result;
2071
+ } else {
2072
+ rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
2073
+ return Qnil;
2074
+ }
2075
+ }
2076
+
2077
+ /*
2078
+ * call-seq: parse()
2079
+ *
2080
+ * Parses the current JSON text _source_ and returns the complete data
2081
+ * structure as a result.
2082
+ */
2083
+ static VALUE cParser_parse(VALUE self)
2084
+ {
2085
+ GET_PARSER;
2086
+
2087
+ if (json->quirks_mode) {
2088
+ return cParser_parse_quirks_mode(self);
2089
+ } else {
2090
+ return cParser_parse_strict(self);
2091
+ }
2092
+ }
2093
+
2094
+
1854
2095
  static JSON_Parser *JSON_allocate()
1855
2096
  {
1856
2097
  JSON_Parser *json = ALLOC(JSON_Parser);
1857
2098
  MEMZERO(json, JSON_Parser, 1);
2099
+ json->fbuffer = fbuffer_alloc(0);
1858
2100
  return json;
1859
2101
  }
1860
2102
 
@@ -1864,10 +2106,12 @@ static void JSON_mark(JSON_Parser *json)
1864
2106
  rb_gc_mark_maybe(json->create_id);
1865
2107
  rb_gc_mark_maybe(json->object_class);
1866
2108
  rb_gc_mark_maybe(json->array_class);
2109
+ rb_gc_mark_maybe(json->match_string);
1867
2110
  }
1868
2111
 
1869
2112
  static void JSON_free(JSON_Parser *json)
1870
2113
  {
2114
+ fbuffer_free(json->fbuffer);
1871
2115
  ruby_xfree(json);
1872
2116
  }
1873
2117
 
@@ -1889,6 +2133,18 @@ static VALUE cParser_source(VALUE self)
1889
2133
  return rb_str_dup(json->Vsource);
1890
2134
  }
1891
2135
 
2136
+ /*
2137
+ * call-seq: quirks_mode?()
2138
+ *
2139
+ * Returns a true, if this parser is in quirks_mode, false otherwise.
2140
+ */
2141
+ static VALUE cParser_quirks_mode_p(VALUE self)
2142
+ {
2143
+ GET_PARSER;
2144
+ return json->quirks_mode ? Qtrue : Qfalse;
2145
+ }
2146
+
2147
+
1892
2148
  void Init_parser()
1893
2149
  {
1894
2150
  rb_require("json/common");
@@ -1901,6 +2157,7 @@ void Init_parser()
1901
2157
  rb_define_method(cParser, "initialize", cParser_initialize, -1);
1902
2158
  rb_define_method(cParser, "parse", cParser_parse, 0);
1903
2159
  rb_define_method(cParser, "source", cParser_source, 0);
2160
+ rb_define_method(cParser, "quirks_mode?", cParser_quirks_mode_p, 0);
1904
2161
 
1905
2162
  CNaN = rb_const_get(mJSON, rb_intern("NaN"));
1906
2163
  CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
@@ -1914,10 +2171,16 @@ void Init_parser()
1914
2171
  i_max_nesting = rb_intern("max_nesting");
1915
2172
  i_allow_nan = rb_intern("allow_nan");
1916
2173
  i_symbolize_names = rb_intern("symbolize_names");
2174
+ i_quirks_mode = rb_intern("quirks_mode");
1917
2175
  i_object_class = rb_intern("object_class");
1918
2176
  i_array_class = rb_intern("array_class");
2177
+ i_match = rb_intern("match");
2178
+ i_match_string = rb_intern("match_string");
1919
2179
  i_key_p = rb_intern("key?");
1920
2180
  i_deep_const_get = rb_intern("deep_const_get");
2181
+ i_aset = rb_intern("[]=");
2182
+ i_aref = rb_intern("[]");
2183
+ i_leftshift = rb_intern("<<");
1921
2184
  #ifdef HAVE_RUBY_ENCODING_H
1922
2185
  CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
1923
2186
  CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
@@ -1927,9 +2190,15 @@ void Init_parser()
1927
2190
  CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
1928
2191
  i_encoding = rb_intern("encoding");
1929
2192
  i_encode = rb_intern("encode");
1930
- i_encode_bang = rb_intern("encode!");
1931
- i_force_encoding = rb_intern("force_encoding");
1932
2193
  #else
1933
2194
  i_iconv = rb_intern("iconv");
1934
2195
  #endif
1935
2196
  }
2197
+
2198
+ /*
2199
+ * Local variables:
2200
+ * mode: c
2201
+ * c-file-style: ruby
2202
+ * indent-tabs-mode: nil
2203
+ * End:
2204
+ */