json_pure 1.8.3 → 1.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +5 -13
- data/CHANGES +2 -1
- data/Gemfile +1 -4
- data/{README.rdoc → README.md} +30 -41
- data/Rakefile +7 -6
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +38 -4
- data/ext/json/ext/generator/generator.h +7 -0
- data/ext/json/ext/parser/parser.c +166 -142
- data/ext/json/ext/parser/parser.rl +52 -28
- data/java/src/json/ext/Generator.java +8 -5
- data/json-java.gemspec +15 -0
- data/json.gemspec +0 -0
- data/json_pure.gemspec +23 -23
- data/lib/json/pure/generator.rb +10 -2
- data/lib/json/version.rb +1 -1
- data/tests/test_json.rb +0 -34
- data/tests/test_json_generate.rb +11 -0
- data/tools/diff.sh +18 -0
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82bc88d9e5afaffd558ed7f2c88883aff647f4c7
|
4
|
+
data.tar.gz: 87c506de4cf87feafa319b163c1a6d9003f55560
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27f0f711bebcf336039ea88125990ce8502ab0cca9dc3ca9ec755b2f450880d472c17442f4e25baa728cb0bdf7125c00e97a834f763e7ab5ebb0673a0c641dcb
|
7
|
+
data.tar.gz: ce9f3d42f35845b76d23ea8614907853413629e8e0293bd404884936cfec42a5194669ae109aa9f7ca09692001361f328402b02054097a470ebe921ade151760
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -4,23 +4,15 @@ language: ruby
|
|
4
4
|
|
5
5
|
# Specify which ruby versions you wish to run your tests on, each version will be used
|
6
6
|
rvm:
|
7
|
-
- 1.8.7
|
8
|
-
- 1.9.2
|
9
7
|
- 1.9.3
|
10
8
|
- 2.0.0
|
11
9
|
- 2.1
|
12
|
-
- 2.2.1
|
13
|
-
- 2.2.2
|
14
10
|
- 2.2
|
15
|
-
-
|
16
|
-
-
|
17
|
-
- jruby-18mode
|
18
|
-
- jruby-19mode
|
19
|
-
- ruby-head
|
11
|
+
- 2.3.3
|
12
|
+
- 2.4.0
|
20
13
|
matrix:
|
21
|
-
|
22
|
-
- rvm:
|
23
|
-
|
14
|
+
include:
|
15
|
+
- rvm: jruby
|
16
|
+
env: JRUBY_OPTS="--2.0"
|
24
17
|
script: "bundle exec rake"
|
25
|
-
|
26
18
|
sudo: false
|
data/CHANGES
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
2015-09-11 (1.8.
|
1
|
+
2015-09-11 (1.8.5)
|
2
2
|
* There were still some mentions of dual GPL licensing in the source, but JSON
|
3
3
|
has just the Ruby license that itself includes an explicit dual-licensing
|
4
4
|
clause that allows covered software to be distributed under the terms of
|
@@ -6,6 +6,7 @@
|
|
6
6
|
however a GPL compatible license according to the Free Software Foundation.
|
7
7
|
I changed these mentions to be consistent with the Ruby license setting in
|
8
8
|
the gemspec files which were already correct now.
|
9
|
+
---------- (1.8.4) Skipped.
|
9
10
|
2015-06-01 (1.8.3)
|
10
11
|
* Fix potential memory leak, thx to nobu.
|
11
12
|
2015-01-08 (1.8.2)
|
data/Gemfile
CHANGED
data/{README.rdoc → README.md}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
# JSON implementation for Ruby {<img src="https://secure.travis-ci.org/flori/json.png" />}[http://travis-ci.org/flori/json]
|
2
2
|
|
3
|
-
|
3
|
+
## Description
|
4
4
|
|
5
5
|
This is a implementation of the JSON specification according to RFC 4627
|
6
6
|
http://www.ietf.org/rfc/rfc4627.txt . Starting from version 1.0.0 on there
|
@@ -11,17 +11,17 @@ will be two variants available:
|
|
11
11
|
* The quite a bit faster native extension variant, which is in parts
|
12
12
|
implemented in C or Java and comes with its own unicode conversion
|
13
13
|
functions and a parser generated by the ragel state machine compiler
|
14
|
-
http://www.
|
14
|
+
http://www.complang.org/ragel/ .
|
15
15
|
|
16
16
|
Both variants of the JSON generator generate UTF-8 character sequences by
|
17
|
-
default. If an :
|
17
|
+
default. If an :ascii\_only option with a true value is given, they escape all
|
18
18
|
non-ASCII and control characters with \uXXXX escape sequences, and support
|
19
19
|
UTF-16 surrogate pairs in order to be able to generate the whole range of
|
20
20
|
unicode code points.
|
21
21
|
|
22
22
|
All strings, that are to be encoded as JSON strings, should be UTF-8 byte
|
23
23
|
sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
|
24
|
-
encoded, please use the
|
24
|
+
encoded, please use the to\_json\_raw\_object method of String (which produces
|
25
25
|
an object, that contains a byte array) and decode the result on the receiving
|
26
26
|
endpoint.
|
27
27
|
|
@@ -32,7 +32,7 @@ String#encoding set. If a document string has ASCII-8BIT as an encoding the
|
|
32
32
|
parser attempts to figure out which of the UTF encodings from above it is and
|
33
33
|
trys to parse it.
|
34
34
|
|
35
|
-
|
35
|
+
## Installation
|
36
36
|
|
37
37
|
It's recommended to use the extension variant of JSON, because it's faster than
|
38
38
|
the pure ruby variant. If you cannot build it on your system, you can settle
|
@@ -63,29 +63,18 @@ with:
|
|
63
63
|
|
64
64
|
# gem install json_pure
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
If you want to build the extensions yourself you need rake:
|
69
|
-
|
70
|
-
You can get it from rubyforge:
|
71
|
-
http://rubyforge.org/projects/rake
|
72
|
-
|
73
|
-
or just type
|
74
|
-
|
75
|
-
# gem install rake
|
76
|
-
|
77
|
-
for the installation via rubygems.
|
66
|
+
## Compiling the extensions yourself
|
78
67
|
|
79
68
|
If you want to create the parser.c file from its parser.rl file or draw nice
|
80
|
-
graphviz images of the state machines, you need ragel from:
|
81
|
-
|
69
|
+
graphviz images of the state machines, you need ragel from:
|
70
|
+
http://www.complang.org/ragel/
|
82
71
|
|
83
|
-
|
72
|
+
## Usage
|
84
73
|
|
85
74
|
To use JSON you can
|
86
75
|
require 'json'
|
87
76
|
to load the installed variant (either the extension 'json' or the pure
|
88
|
-
variant '
|
77
|
+
variant 'json\_pure'). If you have installed the extension variant, you can
|
89
78
|
pick either the extension variant or the pure variant by typing
|
90
79
|
require 'json/ext'
|
91
80
|
or
|
@@ -98,8 +87,8 @@ Now you can parse a JSON document into a ruby data structure by calling
|
|
98
87
|
If you want to generate a JSON document from a ruby data structure call
|
99
88
|
JSON.generate(data)
|
100
89
|
|
101
|
-
You can also use the
|
102
|
-
verbosely and nicely) or
|
90
|
+
You can also use the pretty\_generate method (which formats the output more
|
91
|
+
verbosely and nicely) or fast\_generate (which doesn't do any of the security
|
103
92
|
checks generate performs, e. g. nesting deepness checks).
|
104
93
|
|
105
94
|
To create a valid JSON document you have to make sure, that the output is
|
@@ -134,7 +123,7 @@ To get the best compatibility to rails' JSON implementation, you can
|
|
134
123
|
Both of the additions attempt to require 'json' (like above) first, if it has
|
135
124
|
not been required yet.
|
136
125
|
|
137
|
-
|
126
|
+
## More Examples
|
138
127
|
|
139
128
|
To create a JSON document from a ruby data structure, you can call
|
140
129
|
JSON.generate like that:
|
@@ -151,11 +140,11 @@ JSON.parse on it:
|
|
151
140
|
Note, that the range from the original data structure is a simple
|
152
141
|
string now. The reason for this is, that JSON doesn't support ranges
|
153
142
|
or arbitrary classes. In this case the json library falls back to call
|
154
|
-
Object#
|
143
|
+
Object#to\_json, which is the same as #to\_s.to\_json.
|
155
144
|
|
156
145
|
It's possible to add JSON support serialization to arbitrary classes by
|
157
|
-
simply implementing a more specialized version of the #
|
158
|
-
should return a JSON object (a hash converted to JSON with #
|
146
|
+
simply implementing a more specialized version of the #to\_json method, that
|
147
|
+
should return a JSON object (a hash converted to JSON with #to\_json) like
|
159
148
|
this (don't forget the *a for all the arguments):
|
160
149
|
|
161
150
|
class Range
|
@@ -167,15 +156,15 @@ this (don't forget the *a for all the arguments):
|
|
167
156
|
end
|
168
157
|
end
|
169
158
|
|
170
|
-
The hash key '
|
159
|
+
The hash key 'json\_class' is the class, that will be asked to deserialise the
|
171
160
|
JSON representation later. In this case it's 'Range', but any namespace of
|
172
161
|
the form 'A::B' or '::A::B' will do. All other keys are arbitrary and can be
|
173
162
|
used to store the necessary data to configure the object to be deserialised.
|
174
163
|
|
175
|
-
If a the key '
|
176
|
-
if the given class responds to the
|
164
|
+
If a the key 'json\_class' is found in a JSON object, the JSON parser checks
|
165
|
+
if the given class responds to the json\_create class method. If so, it is
|
177
166
|
called with the JSON object converted to a Ruby hash. So a range can
|
178
|
-
be deserialised by implementing Range.
|
167
|
+
be deserialised by implementing Range.json\_create like this:
|
179
168
|
|
180
169
|
class Range
|
181
170
|
def self.json_create(o)
|
@@ -193,7 +182,7 @@ Now it possible to serialise/deserialise ranges as well:
|
|
193
182
|
JSON.generate always creates the shortest possible string representation of a
|
194
183
|
ruby data structure in one line. This is good for data storage or network
|
195
184
|
protocols, but not so good for humans to read. Fortunately there's also
|
196
|
-
JSON.
|
185
|
+
JSON.pretty\_generate (or JSON.pretty\_generate) that creates a more readable
|
197
186
|
output:
|
198
187
|
|
199
188
|
puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
|
@@ -217,14 +206,14 @@ output:
|
|
217
206
|
]
|
218
207
|
|
219
208
|
There are also the methods Kernel#j for generate, and Kernel#jj for
|
220
|
-
|
209
|
+
pretty\_generate output to the console, that work analogous to Core Ruby's p and
|
221
210
|
the pp library's pp methods.
|
222
211
|
|
223
212
|
The script tools/server.rb contains a small example if you want to test, how
|
224
213
|
receiving a JSON object from a webrick server in your browser with the
|
225
214
|
javasript prototype library http://www.prototypejs.org works.
|
226
215
|
|
227
|
-
|
216
|
+
## Speed Comparisons
|
228
217
|
|
229
218
|
I have created some benchmark results (see the benchmarks/data-p4-3Ghz
|
230
219
|
subdir of the package) for the JSON-parser to estimate the speed up in the C
|
@@ -303,10 +292,10 @@ speed:
|
|
303
292
|
|
304
293
|
In the table above 1-3 are JSON::Ext::Generator methods. 4, 6, and 7 are
|
305
294
|
JSON::Pure::Generator methods and 5 is the Rails JSON generator. It is now a
|
306
|
-
bit faster than the
|
295
|
+
bit faster than the generator\_safe and generator\_pretty methods of the pure
|
307
296
|
variant but slower than the others.
|
308
297
|
|
309
|
-
To achieve the fastest JSON document output, you can use the
|
298
|
+
To achieve the fastest JSON document output, you can use the fast\_generate
|
310
299
|
method. Beware, that this will disable the checking for circular Ruby data
|
311
300
|
structures, which may cause JSON to go into an infinite loop.
|
312
301
|
|
@@ -337,19 +326,19 @@ Here are the median comparisons for completeness' sake:
|
|
337
326
|
calls/sec ( time) -> speed covers
|
338
327
|
secs/call
|
339
328
|
|
340
|
-
|
329
|
+
## Author
|
341
330
|
|
342
331
|
Florian Frank <mailto:flori@ping.de>
|
343
332
|
|
344
|
-
|
333
|
+
## License
|
345
334
|
|
346
335
|
Ruby License, see https://www.ruby-lang.org/en/about/license.txt.
|
347
336
|
|
348
|
-
|
337
|
+
## Download
|
349
338
|
|
350
339
|
The latest version of this library can be downloaded at
|
351
340
|
|
352
|
-
*
|
341
|
+
* https://rubygems.org/gems/json
|
353
342
|
|
354
343
|
Online Documentation should be located at
|
355
344
|
|
data/Rakefile
CHANGED
@@ -83,12 +83,12 @@ if defined?(Gem) and defined?(Gem::PackageTask)
|
|
83
83
|
s.files = PKG_FILES
|
84
84
|
|
85
85
|
s.require_path = 'lib'
|
86
|
-
s.add_development_dependency 'permutation'
|
87
86
|
s.add_development_dependency 'rake'
|
87
|
+
s.add_development_dependency 'test-unit', '~> 2.0'
|
88
88
|
|
89
|
-
s.extra_rdoc_files << 'README.
|
89
|
+
s.extra_rdoc_files << 'README.md'
|
90
90
|
s.rdoc_options <<
|
91
|
-
'--title' << 'JSON implemention for
|
91
|
+
'--title' << 'JSON implemention for Ruby' << '--main' << 'README.md'
|
92
92
|
s.test_files.concat Dir['./tests/test_*.rb']
|
93
93
|
|
94
94
|
s.author = "Florian Frank"
|
@@ -120,11 +120,12 @@ if defined?(Gem) and defined?(Gem::PackageTask)
|
|
120
120
|
s.extensions = FileList['ext/**/extconf.rb']
|
121
121
|
|
122
122
|
s.require_path = 'lib'
|
123
|
-
s.add_development_dependency '
|
123
|
+
s.add_development_dependency 'rake'
|
124
|
+
s.add_development_dependency 'test-unit', '~> 2.0'
|
124
125
|
|
125
|
-
s.extra_rdoc_files << 'README.
|
126
|
+
s.extra_rdoc_files << 'README.md'
|
126
127
|
s.rdoc_options <<
|
127
|
-
'--title' << 'JSON implemention for Ruby' << '--main' << 'README.
|
128
|
+
'--title' << 'JSON implemention for Ruby' << '--main' << 'README.md'
|
128
129
|
s.test_files.concat Dir['./tests/test_*.rb']
|
129
130
|
|
130
131
|
s.author = "Florian Frank"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.8.
|
1
|
+
1.8.5
|
@@ -7,7 +7,13 @@ static ID i_encoding, i_encode;
|
|
7
7
|
#endif
|
8
8
|
|
9
9
|
static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
|
10
|
-
mHash, mArray,
|
10
|
+
mHash, mArray,
|
11
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
12
|
+
mInteger,
|
13
|
+
#else
|
14
|
+
mFixnum, mBignum,
|
15
|
+
#endif
|
16
|
+
mFloat, mString, mString_Extend,
|
11
17
|
mTrueClass, mFalseClass, mNilClass, eGeneratorError,
|
12
18
|
eNestingError, CRegexp_MULTILINE, CJSON_SAFE_STATE_PROTOTYPE,
|
13
19
|
i_SAFE_STATE_PROTOTYPE;
|
@@ -342,6 +348,18 @@ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) {
|
|
342
348
|
GENERATE_JSON(array);
|
343
349
|
}
|
344
350
|
|
351
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
352
|
+
/*
|
353
|
+
* call-seq: to_json(*)
|
354
|
+
*
|
355
|
+
* Returns a JSON string representation for this Integer number.
|
356
|
+
*/
|
357
|
+
static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self)
|
358
|
+
{
|
359
|
+
GENERATE_JSON(integer);
|
360
|
+
}
|
361
|
+
|
362
|
+
#else
|
345
363
|
/*
|
346
364
|
* call-seq: to_json(*)
|
347
365
|
*
|
@@ -361,6 +379,7 @@ static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self)
|
|
361
379
|
{
|
362
380
|
GENERATE_JSON(bignum);
|
363
381
|
}
|
382
|
+
#endif
|
364
383
|
|
365
384
|
/*
|
366
385
|
* call-seq: to_json(*)
|
@@ -825,6 +844,16 @@ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
825
844
|
fbuffer_append_str(buffer, tmp);
|
826
845
|
}
|
827
846
|
|
847
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
848
|
+
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
849
|
+
{
|
850
|
+
if (FIXNUM_P(obj))
|
851
|
+
generate_json_fixnum(buffer, Vstate, state, obj);
|
852
|
+
else
|
853
|
+
generate_json_bignum(buffer, Vstate, state, obj);
|
854
|
+
}
|
855
|
+
#endif
|
856
|
+
|
828
857
|
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
829
858
|
{
|
830
859
|
double value = RFLOAT_VALUE(obj);
|
@@ -858,9 +887,9 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
|
|
858
887
|
generate_json_false(buffer, Vstate, state, obj);
|
859
888
|
} else if (obj == Qtrue) {
|
860
889
|
generate_json_true(buffer, Vstate, state, obj);
|
861
|
-
} else if (
|
890
|
+
} else if (FIXNUM_P(obj)) {
|
862
891
|
generate_json_fixnum(buffer, Vstate, state, obj);
|
863
|
-
} else if (
|
892
|
+
} else if (RB_TYPE_P(obj, T_BIGNUM)) {
|
864
893
|
generate_json_bignum(buffer, Vstate, state, obj);
|
865
894
|
} else if (klass == rb_cFloat) {
|
866
895
|
generate_json_float(buffer, Vstate, state, obj);
|
@@ -871,7 +900,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
|
|
871
900
|
} else {
|
872
901
|
tmp = rb_funcall(obj, i_to_s, 0);
|
873
902
|
Check_Type(tmp, T_STRING);
|
874
|
-
|
903
|
+
generate_json_string(buffer, Vstate, state, tmp);
|
875
904
|
}
|
876
905
|
}
|
877
906
|
|
@@ -1402,10 +1431,15 @@ void Init_generator(void)
|
|
1402
1431
|
rb_define_method(mHash, "to_json", mHash_to_json, -1);
|
1403
1432
|
mArray = rb_define_module_under(mGeneratorMethods, "Array");
|
1404
1433
|
rb_define_method(mArray, "to_json", mArray_to_json, -1);
|
1434
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
1435
|
+
mInteger = rb_define_module_under(mGeneratorMethods, "Integer");
|
1436
|
+
rb_define_method(mInteger, "to_json", mInteger_to_json, -1);
|
1437
|
+
#else
|
1405
1438
|
mFixnum = rb_define_module_under(mGeneratorMethods, "Fixnum");
|
1406
1439
|
rb_define_method(mFixnum, "to_json", mFixnum_to_json, -1);
|
1407
1440
|
mBignum = rb_define_module_under(mGeneratorMethods, "Bignum");
|
1408
1441
|
rb_define_method(mBignum, "to_json", mBignum_to_json, -1);
|
1442
|
+
#endif
|
1409
1443
|
mFloat = rb_define_module_under(mGeneratorMethods, "Float");
|
1410
1444
|
rb_define_method(mFloat, "to_json", mFloat_to_json, -1);
|
1411
1445
|
mString = rb_define_module_under(mGeneratorMethods, "String");
|
@@ -99,8 +99,12 @@ typedef struct JSON_Generator_StateStruct {
|
|
99
99
|
|
100
100
|
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
|
101
101
|
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
|
102
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
103
|
+
static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
|
104
|
+
#else
|
102
105
|
static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
|
103
106
|
static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
|
107
|
+
#endif
|
104
108
|
static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
|
105
109
|
static VALUE mString_included_s(VALUE self, VALUE modul);
|
106
110
|
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
|
@@ -122,6 +126,9 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
122
126
|
static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
123
127
|
static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
124
128
|
static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
129
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
130
|
+
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
131
|
+
#endif
|
125
132
|
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
126
133
|
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
127
134
|
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
@@ -3,6 +3,28 @@
|
|
3
3
|
#include "../fbuffer/fbuffer.h"
|
4
4
|
#include "parser.h"
|
5
5
|
|
6
|
+
#if defined HAVE_RUBY_ENCODING_H
|
7
|
+
# define EXC_ENCODING UTF_8,
|
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
|
+
|
6
28
|
/* unicode */
|
7
29
|
|
8
30
|
static const char digit_values[256] = {
|
@@ -68,9 +90,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
|
|
68
90
|
}
|
69
91
|
|
70
92
|
#ifdef HAVE_RUBY_ENCODING_H
|
71
|
-
static
|
72
|
-
CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
|
73
|
-
static ID i_encoding, i_encode;
|
93
|
+
static rb_encoding *UTF_8, *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
|
74
94
|
#else
|
75
95
|
static ID i_iconv;
|
76
96
|
#endif
|
@@ -84,19 +104,19 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
|
84
104
|
i_match_string, i_aset, i_aref, i_leftshift;
|
85
105
|
|
86
106
|
|
87
|
-
#line
|
107
|
+
#line 130 "parser.rl"
|
88
108
|
|
89
109
|
|
90
110
|
|
91
|
-
#line
|
92
|
-
|
93
|
-
|
94
|
-
|
111
|
+
#line 112 "parser.c"
|
112
|
+
static const int JSON_object_start = 1;
|
113
|
+
static const int JSON_object_first_final = 27;
|
114
|
+
static const int JSON_object_error = 0;
|
95
115
|
|
96
|
-
|
116
|
+
static const int JSON_object_en_main = 1;
|
97
117
|
|
98
118
|
|
99
|
-
#line
|
119
|
+
#line 171 "parser.rl"
|
100
120
|
|
101
121
|
|
102
122
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -112,14 +132,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
112
132
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
113
133
|
|
114
134
|
|
115
|
-
#line
|
135
|
+
#line 136 "parser.c"
|
116
136
|
{
|
117
137
|
cs = JSON_object_start;
|
118
138
|
}
|
119
139
|
|
120
|
-
#line
|
140
|
+
#line 186 "parser.rl"
|
121
141
|
|
122
|
-
#line
|
142
|
+
#line 143 "parser.c"
|
123
143
|
{
|
124
144
|
if ( p == pe )
|
125
145
|
goto _test_eof;
|
@@ -147,7 +167,7 @@ case 2:
|
|
147
167
|
goto st2;
|
148
168
|
goto st0;
|
149
169
|
tr2:
|
150
|
-
#line
|
170
|
+
#line 153 "parser.rl"
|
151
171
|
{
|
152
172
|
char *np;
|
153
173
|
json->parsing_name = 1;
|
@@ -160,7 +180,7 @@ st3:
|
|
160
180
|
if ( ++p == pe )
|
161
181
|
goto _test_eof3;
|
162
182
|
case 3:
|
163
|
-
#line
|
183
|
+
#line 184 "parser.c"
|
164
184
|
switch( (*p) ) {
|
165
185
|
case 13: goto st3;
|
166
186
|
case 32: goto st3;
|
@@ -227,7 +247,7 @@ case 8:
|
|
227
247
|
goto st8;
|
228
248
|
goto st0;
|
229
249
|
tr11:
|
230
|
-
#line
|
250
|
+
#line 138 "parser.rl"
|
231
251
|
{
|
232
252
|
VALUE v = Qnil;
|
233
253
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -247,7 +267,7 @@ st9:
|
|
247
267
|
if ( ++p == pe )
|
248
268
|
goto _test_eof9;
|
249
269
|
case 9:
|
250
|
-
#line
|
270
|
+
#line 271 "parser.c"
|
251
271
|
switch( (*p) ) {
|
252
272
|
case 13: goto st9;
|
253
273
|
case 32: goto st9;
|
@@ -336,14 +356,14 @@ case 18:
|
|
336
356
|
goto st9;
|
337
357
|
goto st18;
|
338
358
|
tr4:
|
339
|
-
#line
|
359
|
+
#line 161 "parser.rl"
|
340
360
|
{ p--; {p++; cs = 27; goto _out;} }
|
341
361
|
goto st27;
|
342
362
|
st27:
|
343
363
|
if ( ++p == pe )
|
344
364
|
goto _test_eof27;
|
345
365
|
case 27:
|
346
|
-
#line
|
366
|
+
#line 367 "parser.c"
|
347
367
|
goto st0;
|
348
368
|
st19:
|
349
369
|
if ( ++p == pe )
|
@@ -441,7 +461,7 @@ case 26:
|
|
441
461
|
_out: {}
|
442
462
|
}
|
443
463
|
|
444
|
-
#line
|
464
|
+
#line 187 "parser.rl"
|
445
465
|
|
446
466
|
if (cs >= JSON_object_first_final) {
|
447
467
|
if (json->create_additions) {
|
@@ -466,15 +486,15 @@ case 26:
|
|
466
486
|
|
467
487
|
|
468
488
|
|
469
|
-
#line
|
470
|
-
|
471
|
-
|
472
|
-
|
489
|
+
#line 490 "parser.c"
|
490
|
+
static const int JSON_value_start = 1;
|
491
|
+
static const int JSON_value_first_final = 21;
|
492
|
+
static const int JSON_value_error = 0;
|
473
493
|
|
474
|
-
|
494
|
+
static const int JSON_value_en_main = 1;
|
475
495
|
|
476
496
|
|
477
|
-
#line
|
497
|
+
#line 291 "parser.rl"
|
478
498
|
|
479
499
|
|
480
500
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -482,14 +502,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
482
502
|
int cs = EVIL;
|
483
503
|
|
484
504
|
|
485
|
-
#line
|
505
|
+
#line 506 "parser.c"
|
486
506
|
{
|
487
507
|
cs = JSON_value_start;
|
488
508
|
}
|
489
509
|
|
490
|
-
#line
|
510
|
+
#line 298 "parser.rl"
|
491
511
|
|
492
|
-
#line
|
512
|
+
#line 513 "parser.c"
|
493
513
|
{
|
494
514
|
if ( p == pe )
|
495
515
|
goto _test_eof;
|
@@ -514,14 +534,14 @@ st0:
|
|
514
534
|
cs = 0;
|
515
535
|
goto _out;
|
516
536
|
tr0:
|
517
|
-
#line
|
537
|
+
#line 239 "parser.rl"
|
518
538
|
{
|
519
539
|
char *np = JSON_parse_string(json, p, pe, result);
|
520
540
|
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
521
541
|
}
|
522
542
|
goto st21;
|
523
543
|
tr2:
|
524
|
-
#line
|
544
|
+
#line 244 "parser.rl"
|
525
545
|
{
|
526
546
|
char *np;
|
527
547
|
if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
|
@@ -530,7 +550,7 @@ tr2:
|
|
530
550
|
{p = (( p + 10))-1;}
|
531
551
|
p--; {p++; cs = 21; goto _out;}
|
532
552
|
} else {
|
533
|
-
|
553
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
534
554
|
}
|
535
555
|
}
|
536
556
|
np = JSON_parse_float(json, p, pe, result);
|
@@ -541,7 +561,7 @@ tr2:
|
|
541
561
|
}
|
542
562
|
goto st21;
|
543
563
|
tr5:
|
544
|
-
#line
|
564
|
+
#line 262 "parser.rl"
|
545
565
|
{
|
546
566
|
char *np;
|
547
567
|
json->current_nesting++;
|
@@ -551,7 +571,7 @@ tr5:
|
|
551
571
|
}
|
552
572
|
goto st21;
|
553
573
|
tr9:
|
554
|
-
#line
|
574
|
+
#line 270 "parser.rl"
|
555
575
|
{
|
556
576
|
char *np;
|
557
577
|
json->current_nesting++;
|
@@ -561,39 +581,39 @@ tr9:
|
|
561
581
|
}
|
562
582
|
goto st21;
|
563
583
|
tr16:
|
564
|
-
#line
|
584
|
+
#line 232 "parser.rl"
|
565
585
|
{
|
566
586
|
if (json->allow_nan) {
|
567
587
|
*result = CInfinity;
|
568
588
|
} else {
|
569
|
-
|
589
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
|
570
590
|
}
|
571
591
|
}
|
572
592
|
goto st21;
|
573
593
|
tr18:
|
574
|
-
#line
|
594
|
+
#line 225 "parser.rl"
|
575
595
|
{
|
576
596
|
if (json->allow_nan) {
|
577
597
|
*result = CNaN;
|
578
598
|
} else {
|
579
|
-
|
599
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
|
580
600
|
}
|
581
601
|
}
|
582
602
|
goto st21;
|
583
603
|
tr22:
|
584
|
-
#line
|
604
|
+
#line 219 "parser.rl"
|
585
605
|
{
|
586
606
|
*result = Qfalse;
|
587
607
|
}
|
588
608
|
goto st21;
|
589
609
|
tr25:
|
590
|
-
#line
|
610
|
+
#line 216 "parser.rl"
|
591
611
|
{
|
592
612
|
*result = Qnil;
|
593
613
|
}
|
594
614
|
goto st21;
|
595
615
|
tr28:
|
596
|
-
#line
|
616
|
+
#line 222 "parser.rl"
|
597
617
|
{
|
598
618
|
*result = Qtrue;
|
599
619
|
}
|
@@ -602,9 +622,9 @@ st21:
|
|
602
622
|
if ( ++p == pe )
|
603
623
|
goto _test_eof21;
|
604
624
|
case 21:
|
605
|
-
#line
|
625
|
+
#line 278 "parser.rl"
|
606
626
|
{ p--; {p++; cs = 21; goto _out;} }
|
607
|
-
#line
|
627
|
+
#line 628 "parser.c"
|
608
628
|
goto st0;
|
609
629
|
st2:
|
610
630
|
if ( ++p == pe )
|
@@ -765,7 +785,7 @@ case 20:
|
|
765
785
|
_out: {}
|
766
786
|
}
|
767
787
|
|
768
|
-
#line
|
788
|
+
#line 299 "parser.rl"
|
769
789
|
|
770
790
|
if (cs >= JSON_value_first_final) {
|
771
791
|
return p;
|
@@ -775,15 +795,15 @@ case 20:
|
|
775
795
|
}
|
776
796
|
|
777
797
|
|
778
|
-
#line
|
779
|
-
|
780
|
-
|
781
|
-
|
798
|
+
#line 799 "parser.c"
|
799
|
+
static const int JSON_integer_start = 1;
|
800
|
+
static const int JSON_integer_first_final = 3;
|
801
|
+
static const int JSON_integer_error = 0;
|
782
802
|
|
783
|
-
|
803
|
+
static const int JSON_integer_en_main = 1;
|
784
804
|
|
785
805
|
|
786
|
-
#line
|
806
|
+
#line 315 "parser.rl"
|
787
807
|
|
788
808
|
|
789
809
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -791,15 +811,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
791
811
|
int cs = EVIL;
|
792
812
|
|
793
813
|
|
794
|
-
#line
|
814
|
+
#line 815 "parser.c"
|
795
815
|
{
|
796
816
|
cs = JSON_integer_start;
|
797
817
|
}
|
798
818
|
|
799
|
-
#line
|
819
|
+
#line 322 "parser.rl"
|
800
820
|
json->memo = p;
|
801
821
|
|
802
|
-
#line
|
822
|
+
#line 823 "parser.c"
|
803
823
|
{
|
804
824
|
if ( p == pe )
|
805
825
|
goto _test_eof;
|
@@ -833,14 +853,14 @@ case 3:
|
|
833
853
|
goto st0;
|
834
854
|
goto tr4;
|
835
855
|
tr4:
|
836
|
-
#line
|
856
|
+
#line 312 "parser.rl"
|
837
857
|
{ p--; {p++; cs = 4; goto _out;} }
|
838
858
|
goto st4;
|
839
859
|
st4:
|
840
860
|
if ( ++p == pe )
|
841
861
|
goto _test_eof4;
|
842
862
|
case 4:
|
843
|
-
#line
|
863
|
+
#line 864 "parser.c"
|
844
864
|
goto st0;
|
845
865
|
st5:
|
846
866
|
if ( ++p == pe )
|
@@ -859,7 +879,7 @@ case 5:
|
|
859
879
|
_out: {}
|
860
880
|
}
|
861
881
|
|
862
|
-
#line
|
882
|
+
#line 324 "parser.rl"
|
863
883
|
|
864
884
|
if (cs >= JSON_integer_first_final) {
|
865
885
|
long len = p - json->memo;
|
@@ -874,15 +894,15 @@ case 5:
|
|
874
894
|
}
|
875
895
|
|
876
896
|
|
877
|
-
#line
|
878
|
-
|
879
|
-
|
880
|
-
|
897
|
+
#line 898 "parser.c"
|
898
|
+
static const int JSON_float_start = 1;
|
899
|
+
static const int JSON_float_first_final = 8;
|
900
|
+
static const int JSON_float_error = 0;
|
881
901
|
|
882
|
-
|
902
|
+
static const int JSON_float_en_main = 1;
|
883
903
|
|
884
904
|
|
885
|
-
#line
|
905
|
+
#line 349 "parser.rl"
|
886
906
|
|
887
907
|
|
888
908
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -890,15 +910,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
890
910
|
int cs = EVIL;
|
891
911
|
|
892
912
|
|
893
|
-
#line
|
913
|
+
#line 914 "parser.c"
|
894
914
|
{
|
895
915
|
cs = JSON_float_start;
|
896
916
|
}
|
897
917
|
|
898
|
-
#line
|
918
|
+
#line 356 "parser.rl"
|
899
919
|
json->memo = p;
|
900
920
|
|
901
|
-
#line
|
921
|
+
#line 922 "parser.c"
|
902
922
|
{
|
903
923
|
if ( p == pe )
|
904
924
|
goto _test_eof;
|
@@ -956,14 +976,14 @@ case 8:
|
|
956
976
|
goto st0;
|
957
977
|
goto tr9;
|
958
978
|
tr9:
|
959
|
-
#line
|
979
|
+
#line 343 "parser.rl"
|
960
980
|
{ p--; {p++; cs = 9; goto _out;} }
|
961
981
|
goto st9;
|
962
982
|
st9:
|
963
983
|
if ( ++p == pe )
|
964
984
|
goto _test_eof9;
|
965
985
|
case 9:
|
966
|
-
#line
|
986
|
+
#line 987 "parser.c"
|
967
987
|
goto st0;
|
968
988
|
st5:
|
969
989
|
if ( ++p == pe )
|
@@ -1024,7 +1044,7 @@ case 7:
|
|
1024
1044
|
_out: {}
|
1025
1045
|
}
|
1026
1046
|
|
1027
|
-
#line
|
1047
|
+
#line 358 "parser.rl"
|
1028
1048
|
|
1029
1049
|
if (cs >= JSON_float_first_final) {
|
1030
1050
|
long len = p - json->memo;
|
@@ -1040,15 +1060,15 @@ case 7:
|
|
1040
1060
|
|
1041
1061
|
|
1042
1062
|
|
1043
|
-
#line
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1063
|
+
#line 1064 "parser.c"
|
1064
|
+
static const int JSON_array_start = 1;
|
1065
|
+
static const int JSON_array_first_final = 17;
|
1066
|
+
static const int JSON_array_error = 0;
|
1047
1067
|
|
1048
|
-
|
1068
|
+
static const int JSON_array_en_main = 1;
|
1049
1069
|
|
1050
1070
|
|
1051
|
-
#line
|
1071
|
+
#line 401 "parser.rl"
|
1052
1072
|
|
1053
1073
|
|
1054
1074
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -1062,14 +1082,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
1062
1082
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
1063
1083
|
|
1064
1084
|
|
1065
|
-
#line
|
1085
|
+
#line 1086 "parser.c"
|
1066
1086
|
{
|
1067
1087
|
cs = JSON_array_start;
|
1068
1088
|
}
|
1069
1089
|
|
1070
|
-
#line
|
1090
|
+
#line 414 "parser.rl"
|
1071
1091
|
|
1072
|
-
#line
|
1092
|
+
#line 1093 "parser.c"
|
1073
1093
|
{
|
1074
1094
|
if ( p == pe )
|
1075
1095
|
goto _test_eof;
|
@@ -1108,7 +1128,7 @@ case 2:
|
|
1108
1128
|
goto st2;
|
1109
1129
|
goto st0;
|
1110
1130
|
tr2:
|
1111
|
-
#line
|
1131
|
+
#line 378 "parser.rl"
|
1112
1132
|
{
|
1113
1133
|
VALUE v = Qnil;
|
1114
1134
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -1128,7 +1148,7 @@ st3:
|
|
1128
1148
|
if ( ++p == pe )
|
1129
1149
|
goto _test_eof3;
|
1130
1150
|
case 3:
|
1131
|
-
#line
|
1151
|
+
#line 1152 "parser.c"
|
1132
1152
|
switch( (*p) ) {
|
1133
1153
|
case 13: goto st3;
|
1134
1154
|
case 32: goto st3;
|
@@ -1228,14 +1248,14 @@ case 12:
|
|
1228
1248
|
goto st3;
|
1229
1249
|
goto st12;
|
1230
1250
|
tr4:
|
1231
|
-
#line
|
1251
|
+
#line 393 "parser.rl"
|
1232
1252
|
{ p--; {p++; cs = 17; goto _out;} }
|
1233
1253
|
goto st17;
|
1234
1254
|
st17:
|
1235
1255
|
if ( ++p == pe )
|
1236
1256
|
goto _test_eof17;
|
1237
1257
|
case 17:
|
1238
|
-
#line
|
1258
|
+
#line 1259 "parser.c"
|
1239
1259
|
goto st0;
|
1240
1260
|
st13:
|
1241
1261
|
if ( ++p == pe )
|
@@ -1291,12 +1311,12 @@ case 16:
|
|
1291
1311
|
_out: {}
|
1292
1312
|
}
|
1293
1313
|
|
1294
|
-
#line
|
1314
|
+
#line 415 "parser.rl"
|
1295
1315
|
|
1296
1316
|
if(cs >= JSON_array_first_final) {
|
1297
1317
|
return p + 1;
|
1298
1318
|
} else {
|
1299
|
-
|
1319
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
1300
1320
|
return NULL;
|
1301
1321
|
}
|
1302
1322
|
}
|
@@ -1372,15 +1392,15 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
|
|
1372
1392
|
}
|
1373
1393
|
|
1374
1394
|
|
1375
|
-
#line
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1395
|
+
#line 1396 "parser.c"
|
1396
|
+
static const int JSON_string_start = 1;
|
1397
|
+
static const int JSON_string_first_final = 8;
|
1398
|
+
static const int JSON_string_error = 0;
|
1379
1399
|
|
1380
|
-
|
1400
|
+
static const int JSON_string_en_main = 1;
|
1381
1401
|
|
1382
1402
|
|
1383
|
-
#line
|
1403
|
+
#line 514 "parser.rl"
|
1384
1404
|
|
1385
1405
|
|
1386
1406
|
static int
|
@@ -1402,15 +1422,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
1402
1422
|
|
1403
1423
|
*result = rb_str_buf_new(0);
|
1404
1424
|
|
1405
|
-
#line
|
1425
|
+
#line 1426 "parser.c"
|
1406
1426
|
{
|
1407
1427
|
cs = JSON_string_start;
|
1408
1428
|
}
|
1409
1429
|
|
1410
|
-
#line
|
1430
|
+
#line 535 "parser.rl"
|
1411
1431
|
json->memo = p;
|
1412
1432
|
|
1413
|
-
#line
|
1433
|
+
#line 1434 "parser.c"
|
1414
1434
|
{
|
1415
1435
|
if ( p == pe )
|
1416
1436
|
goto _test_eof;
|
@@ -1435,7 +1455,7 @@ case 2:
|
|
1435
1455
|
goto st0;
|
1436
1456
|
goto st2;
|
1437
1457
|
tr2:
|
1438
|
-
#line
|
1458
|
+
#line 500 "parser.rl"
|
1439
1459
|
{
|
1440
1460
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
1441
1461
|
if (NIL_P(*result)) {
|
@@ -1446,14 +1466,14 @@ tr2:
|
|
1446
1466
|
{p = (( p + 1))-1;}
|
1447
1467
|
}
|
1448
1468
|
}
|
1449
|
-
#line
|
1469
|
+
#line 511 "parser.rl"
|
1450
1470
|
{ p--; {p++; cs = 8; goto _out;} }
|
1451
1471
|
goto st8;
|
1452
1472
|
st8:
|
1453
1473
|
if ( ++p == pe )
|
1454
1474
|
goto _test_eof8;
|
1455
1475
|
case 8:
|
1456
|
-
#line
|
1476
|
+
#line 1477 "parser.c"
|
1457
1477
|
goto st0;
|
1458
1478
|
st3:
|
1459
1479
|
if ( ++p == pe )
|
@@ -1529,7 +1549,7 @@ case 7:
|
|
1529
1549
|
_out: {}
|
1530
1550
|
}
|
1531
1551
|
|
1532
|
-
#line
|
1552
|
+
#line 537 "parser.rl"
|
1533
1553
|
|
1534
1554
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
1535
1555
|
VALUE klass;
|
@@ -1566,29 +1586,29 @@ case 7:
|
|
1566
1586
|
|
1567
1587
|
static VALUE convert_encoding(VALUE source)
|
1568
1588
|
{
|
1569
|
-
char *ptr = RSTRING_PTR(source);
|
1589
|
+
const char *ptr = RSTRING_PTR(source);
|
1570
1590
|
long len = RSTRING_LEN(source);
|
1571
1591
|
if (len < 2) {
|
1572
1592
|
rb_raise(eParserError, "A JSON text must at least contain two octets!");
|
1573
1593
|
}
|
1574
1594
|
#ifdef HAVE_RUBY_ENCODING_H
|
1575
1595
|
{
|
1576
|
-
|
1577
|
-
if (
|
1596
|
+
rb_encoding *enc = rb_enc_get(source);
|
1597
|
+
if (enc == rb_ascii8bit_encoding()) {
|
1578
1598
|
if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
|
1579
|
-
source =
|
1599
|
+
source = rb_str_conv_enc(source, UTF_32BE, rb_utf8_encoding());
|
1580
1600
|
} else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
|
1581
|
-
source =
|
1601
|
+
source = rb_str_conv_enc(source, UTF_16BE, rb_utf8_encoding());
|
1582
1602
|
} else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
|
1583
|
-
source =
|
1603
|
+
source = rb_str_conv_enc(source, UTF_32LE, rb_utf8_encoding());
|
1584
1604
|
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
|
1585
|
-
source =
|
1605
|
+
source = rb_str_conv_enc(source, UTF_16LE, rb_utf8_encoding());
|
1586
1606
|
} else {
|
1587
1607
|
source = rb_str_dup(source);
|
1588
1608
|
FORCE_UTF8(source);
|
1589
1609
|
}
|
1590
1610
|
} else {
|
1591
|
-
source =
|
1611
|
+
source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
|
1592
1612
|
}
|
1593
1613
|
}
|
1594
1614
|
#else
|
@@ -1639,12 +1659,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1639
1659
|
if (json->Vsource) {
|
1640
1660
|
rb_raise(rb_eTypeError, "already initialized instance");
|
1641
1661
|
}
|
1662
|
+
#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
1663
|
+
rb_scan_args(argc, argv, "1:", &source, &opts);
|
1664
|
+
#else
|
1642
1665
|
rb_scan_args(argc, argv, "11", &source, &opts);
|
1666
|
+
#endif
|
1643
1667
|
if (!NIL_P(opts)) {
|
1668
|
+
#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
1644
1669
|
opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
|
1645
1670
|
if (NIL_P(opts)) {
|
1646
1671
|
rb_raise(rb_eArgError, "opts needs to be like a hash");
|
1647
1672
|
} else {
|
1673
|
+
#endif
|
1648
1674
|
VALUE tmp = ID2SYM(i_max_nesting);
|
1649
1675
|
if (option_given_p(opts, tmp)) {
|
1650
1676
|
VALUE max_nesting = rb_hash_aref(opts, tmp);
|
@@ -1707,7 +1733,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1707
1733
|
} else {
|
1708
1734
|
json->match_string = Qnil;
|
1709
1735
|
}
|
1736
|
+
#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
1710
1737
|
}
|
1738
|
+
#endif
|
1711
1739
|
} else {
|
1712
1740
|
json->max_nesting = 100;
|
1713
1741
|
json->allow_nan = 0;
|
@@ -1716,12 +1744,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1716
1744
|
json->object_class = Qnil;
|
1717
1745
|
json->array_class = Qnil;
|
1718
1746
|
}
|
1719
|
-
|
1747
|
+
StringValue(source);
|
1720
1748
|
if (!json->quirks_mode) {
|
1721
|
-
|
1749
|
+
source = convert_encoding(source);
|
1722
1750
|
}
|
1723
1751
|
json->current_nesting = 0;
|
1724
|
-
StringValue(source);
|
1725
1752
|
json->len = RSTRING_LEN(source);
|
1726
1753
|
json->source = RSTRING_PTR(source);;
|
1727
1754
|
json->Vsource = source;
|
@@ -1729,15 +1756,15 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1729
1756
|
}
|
1730
1757
|
|
1731
1758
|
|
1732
|
-
#line
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1759
|
+
#line 1760 "parser.c"
|
1760
|
+
static const int JSON_start = 1;
|
1761
|
+
static const int JSON_first_final = 10;
|
1762
|
+
static const int JSON_error = 0;
|
1736
1763
|
|
1737
|
-
|
1764
|
+
static const int JSON_en_main = 1;
|
1738
1765
|
|
1739
1766
|
|
1740
|
-
#line
|
1767
|
+
#line 767 "parser.rl"
|
1741
1768
|
|
1742
1769
|
|
1743
1770
|
static VALUE cParser_parse_strict(VALUE self)
|
@@ -1748,16 +1775,16 @@ static VALUE cParser_parse_strict(VALUE self)
|
|
1748
1775
|
GET_PARSER;
|
1749
1776
|
|
1750
1777
|
|
1751
|
-
#line
|
1778
|
+
#line 1779 "parser.c"
|
1752
1779
|
{
|
1753
1780
|
cs = JSON_start;
|
1754
1781
|
}
|
1755
1782
|
|
1756
|
-
#line
|
1783
|
+
#line 777 "parser.rl"
|
1757
1784
|
p = json->source;
|
1758
1785
|
pe = p + json->len;
|
1759
1786
|
|
1760
|
-
#line
|
1787
|
+
#line 1788 "parser.c"
|
1761
1788
|
{
|
1762
1789
|
if ( p == pe )
|
1763
1790
|
goto _test_eof;
|
@@ -1813,7 +1840,7 @@ case 5:
|
|
1813
1840
|
goto st1;
|
1814
1841
|
goto st5;
|
1815
1842
|
tr3:
|
1816
|
-
#line
|
1843
|
+
#line 756 "parser.rl"
|
1817
1844
|
{
|
1818
1845
|
char *np;
|
1819
1846
|
json->current_nesting = 1;
|
@@ -1822,7 +1849,7 @@ tr3:
|
|
1822
1849
|
}
|
1823
1850
|
goto st10;
|
1824
1851
|
tr4:
|
1825
|
-
#line
|
1852
|
+
#line 749 "parser.rl"
|
1826
1853
|
{
|
1827
1854
|
char *np;
|
1828
1855
|
json->current_nesting = 1;
|
@@ -1834,7 +1861,7 @@ st10:
|
|
1834
1861
|
if ( ++p == pe )
|
1835
1862
|
goto _test_eof10;
|
1836
1863
|
case 10:
|
1837
|
-
#line
|
1864
|
+
#line 1865 "parser.c"
|
1838
1865
|
switch( (*p) ) {
|
1839
1866
|
case 13: goto st10;
|
1840
1867
|
case 32: goto st10;
|
@@ -1891,27 +1918,27 @@ case 9:
|
|
1891
1918
|
_out: {}
|
1892
1919
|
}
|
1893
1920
|
|
1894
|
-
#line
|
1921
|
+
#line 780 "parser.rl"
|
1895
1922
|
|
1896
1923
|
if (cs >= JSON_first_final && p == pe) {
|
1897
1924
|
return result;
|
1898
1925
|
} else {
|
1899
|
-
|
1926
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
1900
1927
|
return Qnil;
|
1901
1928
|
}
|
1902
1929
|
}
|
1903
1930
|
|
1904
1931
|
|
1905
1932
|
|
1906
|
-
#line
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1933
|
+
#line 1934 "parser.c"
|
1934
|
+
static const int JSON_quirks_mode_start = 1;
|
1935
|
+
static const int JSON_quirks_mode_first_final = 10;
|
1936
|
+
static const int JSON_quirks_mode_error = 0;
|
1910
1937
|
|
1911
|
-
|
1938
|
+
static const int JSON_quirks_mode_en_main = 1;
|
1912
1939
|
|
1913
1940
|
|
1914
|
-
#line
|
1941
|
+
#line 805 "parser.rl"
|
1915
1942
|
|
1916
1943
|
|
1917
1944
|
static VALUE cParser_parse_quirks_mode(VALUE self)
|
@@ -1922,16 +1949,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
|
|
1922
1949
|
GET_PARSER;
|
1923
1950
|
|
1924
1951
|
|
1925
|
-
#line
|
1952
|
+
#line 1953 "parser.c"
|
1926
1953
|
{
|
1927
1954
|
cs = JSON_quirks_mode_start;
|
1928
1955
|
}
|
1929
1956
|
|
1930
|
-
#line
|
1957
|
+
#line 815 "parser.rl"
|
1931
1958
|
p = json->source;
|
1932
1959
|
pe = p + json->len;
|
1933
1960
|
|
1934
|
-
#line
|
1961
|
+
#line 1962 "parser.c"
|
1935
1962
|
{
|
1936
1963
|
if ( p == pe )
|
1937
1964
|
goto _test_eof;
|
@@ -1965,7 +1992,7 @@ st0:
|
|
1965
1992
|
cs = 0;
|
1966
1993
|
goto _out;
|
1967
1994
|
tr2:
|
1968
|
-
#line
|
1995
|
+
#line 797 "parser.rl"
|
1969
1996
|
{
|
1970
1997
|
char *np = JSON_parse_value(json, p, pe, &result);
|
1971
1998
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
@@ -1975,7 +2002,7 @@ st10:
|
|
1975
2002
|
if ( ++p == pe )
|
1976
2003
|
goto _test_eof10;
|
1977
2004
|
case 10:
|
1978
|
-
#line
|
2005
|
+
#line 2006 "parser.c"
|
1979
2006
|
switch( (*p) ) {
|
1980
2007
|
case 13: goto st10;
|
1981
2008
|
case 32: goto st10;
|
@@ -2064,12 +2091,12 @@ case 9:
|
|
2064
2091
|
_out: {}
|
2065
2092
|
}
|
2066
2093
|
|
2067
|
-
#line
|
2094
|
+
#line 818 "parser.rl"
|
2068
2095
|
|
2069
2096
|
if (cs >= JSON_quirks_mode_first_final && p == pe) {
|
2070
2097
|
return result;
|
2071
2098
|
} else {
|
2072
|
-
|
2099
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
2073
2100
|
return Qnil;
|
2074
2101
|
}
|
2075
2102
|
}
|
@@ -2194,14 +2221,11 @@ void Init_parser(void)
|
|
2194
2221
|
i_aref = rb_intern("[]");
|
2195
2222
|
i_leftshift = rb_intern("<<");
|
2196
2223
|
#ifdef HAVE_RUBY_ENCODING_H
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
|
2203
|
-
i_encoding = rb_intern("encoding");
|
2204
|
-
i_encode = rb_intern("encode");
|
2224
|
+
UTF_8 = rb_utf8_encoding();
|
2225
|
+
UTF_16BE = rb_enc_find("utf-16be");
|
2226
|
+
UTF_16LE = rb_enc_find("utf-16le");
|
2227
|
+
UTF_32BE = rb_enc_find("utf-32be");
|
2228
|
+
UTF_32LE = rb_enc_find("utf-32le");
|
2205
2229
|
#else
|
2206
2230
|
i_iconv = rb_intern("iconv");
|
2207
2231
|
#endif
|