json 2.6.1 → 2.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/BSDL +22 -0
- data/CHANGES.md +370 -17
- data/LEGAL +20 -0
- data/README.md +96 -213
- data/ext/json/ext/fbuffer/fbuffer.h +190 -118
- data/ext/json/ext/generator/extconf.rb +17 -2
- data/ext/json/ext/generator/generator.c +1532 -1074
- data/ext/json/ext/json.h +183 -0
- data/ext/json/ext/parser/extconf.rb +30 -25
- data/ext/json/ext/parser/parser.c +2837 -3258
- data/ext/json/ext/simd/conf.rb +24 -0
- data/ext/json/ext/simd/simd.h +208 -0
- data/ext/json/ext/vendor/fast_float_parser.h +814 -0
- data/ext/json/ext/vendor/fpconv.c +480 -0
- data/ext/json/ext/vendor/jeaiii-ltoa.h +267 -0
- data/json.gemspec +48 -53
- data/lib/json/add/bigdecimal.rb +39 -10
- data/lib/json/add/complex.rb +29 -6
- data/lib/json/add/core.rb +2 -1
- data/lib/json/add/date.rb +27 -7
- data/lib/json/add/date_time.rb +26 -9
- data/lib/json/add/exception.rb +25 -7
- data/lib/json/add/ostruct.rb +32 -9
- data/lib/json/add/range.rb +33 -8
- data/lib/json/add/rational.rb +28 -6
- data/lib/json/add/regexp.rb +26 -8
- data/lib/json/add/set.rb +25 -6
- data/lib/json/add/string.rb +35 -0
- data/lib/json/add/struct.rb +29 -7
- data/lib/json/add/symbol.rb +34 -7
- data/lib/json/add/time.rb +29 -15
- data/lib/json/common.rb +746 -267
- data/lib/json/ext/generator/state.rb +104 -0
- data/lib/json/ext.rb +61 -5
- data/lib/json/generic_object.rb +7 -11
- data/lib/json/truffle_ruby/generator.rb +790 -0
- data/lib/json/version.rb +3 -7
- data/lib/json.rb +134 -24
- metadata +22 -26
- data/VERSION +0 -1
- data/ext/json/ext/generator/depend +0 -1
- data/ext/json/ext/generator/generator.h +0 -174
- data/ext/json/ext/parser/depend +0 -1
- data/ext/json/ext/parser/parser.h +0 -96
- data/ext/json/ext/parser/parser.rl +0 -977
- data/ext/json/extconf.rb +0 -3
- data/lib/json/pure/generator.rb +0 -479
- data/lib/json/pure/parser.rb +0 -337
- data/lib/json/pure.rb +0 -15
- /data/{LICENSE → COPYING} +0 -0
data/lib/json/version.rb
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module JSON
|
|
3
|
-
|
|
4
|
-
VERSION = '2.6.1'
|
|
5
|
-
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
|
|
6
|
-
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
|
7
|
-
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
|
8
|
-
VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
|
|
4
|
+
VERSION = '2.21.1'
|
|
9
5
|
end
|
data/lib/json.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
require 'json/common'
|
|
3
3
|
|
|
4
4
|
##
|
|
@@ -6,6 +6,15 @@ require 'json/common'
|
|
|
6
6
|
#
|
|
7
7
|
# \JSON is a lightweight data-interchange format.
|
|
8
8
|
#
|
|
9
|
+
# \JSON is easy for us humans to read and write,
|
|
10
|
+
# and equally simple for machines to read (parse) and write (generate).
|
|
11
|
+
#
|
|
12
|
+
# \JSON is language-independent, making it an ideal interchange format
|
|
13
|
+
# for applications in differing programming languages
|
|
14
|
+
# and on differing operating systems.
|
|
15
|
+
#
|
|
16
|
+
# == \JSON Values
|
|
17
|
+
#
|
|
9
18
|
# A \JSON value is one of the following:
|
|
10
19
|
# - Double-quoted text: <tt>"foo"</tt>.
|
|
11
20
|
# - Number: +1+, +1.0+, +2.0e2+.
|
|
@@ -127,6 +136,24 @@ require 'json/common'
|
|
|
127
136
|
#
|
|
128
137
|
# ---
|
|
129
138
|
#
|
|
139
|
+
# Option +allow_duplicate_key+ specifies whether duplicate keys in objects
|
|
140
|
+
# should be ignored or cause an error to be raised:
|
|
141
|
+
#
|
|
142
|
+
# When not specified:
|
|
143
|
+
# # The last value is used and a deprecation warning emitted.
|
|
144
|
+
# JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
|
|
145
|
+
# # warning: detected duplicate keys in JSON object.
|
|
146
|
+
# # This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
|
|
147
|
+
#
|
|
148
|
+
# When set to +true+:
|
|
149
|
+
# # The last value is used.
|
|
150
|
+
# JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
|
|
151
|
+
#
|
|
152
|
+
# When set to +false+, the future default:
|
|
153
|
+
# JSON.parse('{"a": 1, "a":2}') => duplicate key at line 1 column 1 (JSON::ParserError)
|
|
154
|
+
#
|
|
155
|
+
# ---
|
|
156
|
+
#
|
|
130
157
|
# Option +allow_nan+ (boolean) specifies whether to allow
|
|
131
158
|
# NaN, Infinity, and MinusInfinity in +source+;
|
|
132
159
|
# defaults to +false+.
|
|
@@ -143,8 +170,61 @@ require 'json/common'
|
|
|
143
170
|
# ruby = JSON.parse(source, {allow_nan: true})
|
|
144
171
|
# ruby # => [NaN, Infinity, -Infinity]
|
|
145
172
|
#
|
|
173
|
+
# ---
|
|
174
|
+
#
|
|
175
|
+
# Option +allow_trailing_comma+ (boolean) specifies whether to allow
|
|
176
|
+
# trailing commas in objects and arrays;
|
|
177
|
+
# defaults to +false+.
|
|
178
|
+
#
|
|
179
|
+
# With the default, +false+:
|
|
180
|
+
# JSON.parse('[1,]') # unexpected character: ']' at line 1 column 4 (JSON::ParserError)
|
|
181
|
+
#
|
|
182
|
+
# When enabled:
|
|
183
|
+
# JSON.parse('[1,]', allow_trailing_comma: true) # => [1]
|
|
184
|
+
#
|
|
185
|
+
# ---
|
|
186
|
+
#
|
|
187
|
+
# Option +allow_comments+ (boolean) specifies whether to allow
|
|
188
|
+
# JavaScript style comments (either <tt>// comment</tt> or <tt>/* comment */</tt>);
|
|
189
|
+
# defaults to +false+.
|
|
190
|
+
#
|
|
191
|
+
# When not specified, a deprecation warning is emitted if a comment is encountered.
|
|
192
|
+
#
|
|
193
|
+
# When set to +true+, comments are ignored:
|
|
194
|
+
# JSON.parse('/* comment */ {"a": 1, "a":2}') # => {"a" => 2}
|
|
195
|
+
#
|
|
196
|
+
# When set to +false+, the future default:
|
|
197
|
+
# JSON.parse('/* comment */ {"a": 1, "a":2}') # unexpected character: '/' at line 1 column 1 (JSON::ParserError)
|
|
198
|
+
#
|
|
199
|
+
# ---
|
|
200
|
+
#
|
|
201
|
+
# Option +allow_control_characters+ (boolean) specifies whether to allow
|
|
202
|
+
# unescaped ASCII control characters, such as newlines, in strings;
|
|
203
|
+
# defaults to +false+.
|
|
204
|
+
#
|
|
205
|
+
# With the default, +false+:
|
|
206
|
+
# JSON.parse(%{"Hello\nWorld"}) # invalid ASCII control character in string (JSON::ParserError)
|
|
207
|
+
#
|
|
208
|
+
# When enabled:
|
|
209
|
+
# JSON.parse(%{"Hello\nWorld"}, allow_control_characters: true) # => "Hello\nWorld"
|
|
210
|
+
#
|
|
211
|
+
# ---
|
|
212
|
+
#
|
|
213
|
+
# Option +allow_invalid_escape+ (boolean) specifies whether to ignore backslahes that are followed
|
|
214
|
+
# by an invalid escape character in strings;
|
|
215
|
+
# defaults to +false+.
|
|
216
|
+
#
|
|
217
|
+
# With the default, +false+:
|
|
218
|
+
# JSON.parse('"Hell\o"') # invalid escape character in string (JSON::ParserError)
|
|
219
|
+
#
|
|
220
|
+
# When enabled:
|
|
221
|
+
# JSON.parse('"Hell\o"', allow_invalid_escape: true) # => "Hello"
|
|
222
|
+
#
|
|
146
223
|
# ====== Output Options
|
|
147
224
|
#
|
|
225
|
+
# Option +freeze+ (boolean) specifies whether the returned objects will be frozen;
|
|
226
|
+
# defaults to +false+.
|
|
227
|
+
#
|
|
148
228
|
# Option +symbolize_names+ (boolean) specifies whether returned \Hash keys
|
|
149
229
|
# should be Symbols;
|
|
150
230
|
# defaults to +false+ (use Strings).
|
|
@@ -269,8 +349,27 @@ require 'json/common'
|
|
|
269
349
|
# JSON.generate(JSON::MinusInfinity)
|
|
270
350
|
#
|
|
271
351
|
# Allow:
|
|
272
|
-
# ruby = [Float::
|
|
273
|
-
# JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]'
|
|
352
|
+
# ruby = [Float::NAN, Float::INFINITY, JSON::NaN, JSON::Infinity, JSON::MinusInfinity]
|
|
353
|
+
# JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,NaN,Infinity,-Infinity]'
|
|
354
|
+
#
|
|
355
|
+
# ---
|
|
356
|
+
#
|
|
357
|
+
# Option +allow_duplicate_key+ (boolean) specifies whether
|
|
358
|
+
# hashes with duplicate keys should be allowed or produce an error.
|
|
359
|
+
# defaults to emit a deprecation warning.
|
|
360
|
+
#
|
|
361
|
+
# With the default, (not set):
|
|
362
|
+
# Warning[:deprecated] = true
|
|
363
|
+
# JSON.generate({ foo: 1, "foo" => 2 })
|
|
364
|
+
# # warning: detected duplicate key "foo" in {foo: 1, "foo" => 2}.
|
|
365
|
+
# # This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
|
|
366
|
+
# # => '{"foo":1,"foo":2}'
|
|
367
|
+
#
|
|
368
|
+
# With <tt>false</tt>
|
|
369
|
+
# JSON.generate({ foo: 1, "foo" => 2 }, allow_duplicate_key: false)
|
|
370
|
+
# # detected duplicate key "foo" in {foo: 1, "foo" => 2} (JSON::GeneratorError)
|
|
371
|
+
#
|
|
372
|
+
# In version 3.0, <tt>false</tt> will become the default.
|
|
274
373
|
#
|
|
275
374
|
# ---
|
|
276
375
|
#
|
|
@@ -285,6 +384,15 @@ require 'json/common'
|
|
|
285
384
|
# # Raises JSON::NestingError (nesting of 2 is too deep):
|
|
286
385
|
# JSON.generate(obj, max_nesting: 2)
|
|
287
386
|
#
|
|
387
|
+
# ====== Escaping Options
|
|
388
|
+
#
|
|
389
|
+
# Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt>
|
|
390
|
+
# and <tt>'/'</tt> should be escaped as to make the JSON object safe to interpolate in script
|
|
391
|
+
# tags.
|
|
392
|
+
#
|
|
393
|
+
# Options +ascii_only+ (boolean) specifies wether all characters outside the ASCII range
|
|
394
|
+
# should be escaped.
|
|
395
|
+
#
|
|
288
396
|
# ====== Output Options
|
|
289
397
|
#
|
|
290
398
|
# The default formatting options generate the most compact
|
|
@@ -300,7 +408,6 @@ require 'json/common'
|
|
|
300
408
|
# to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.
|
|
301
409
|
# - Option +indent+ (\String) specifies the string (usually spaces) to be
|
|
302
410
|
# used for indentation; defaults to the empty \String, <tt>''</tt>;
|
|
303
|
-
# defaults to the empty \String, <tt>''</tt>;
|
|
304
411
|
# has no effect unless options +array_nl+ or +object_nl+ specify newlines.
|
|
305
412
|
# - Option +space+ (\String) specifies a string (usually a space) to be
|
|
306
413
|
# inserted after the colon in each \JSON object's pair;
|
|
@@ -308,6 +415,11 @@ require 'json/common'
|
|
|
308
415
|
# - Option +space_before+ (\String) specifies a string (usually a space) to be
|
|
309
416
|
# inserted before the colon in each \JSON object's pair;
|
|
310
417
|
# defaults to the empty \String, <tt>''</tt>.
|
|
418
|
+
# - Option +sort_keys+ (boolean or \Proc) controls whether and how the keys of a
|
|
419
|
+
# hash are sorted when generating the output; defaults to <tt>false</tt>.
|
|
420
|
+
# When +true+, keys are sorted lexicographically. When a \Proc, it receives
|
|
421
|
+
# the entire \Hash and must return a \Hash with its pairs in the desired
|
|
422
|
+
# order, allowing for arbitrary sort orders.
|
|
311
423
|
#
|
|
312
424
|
# In this example, +obj+ is used first to generate the shortest
|
|
313
425
|
# \JSON data (no whitespace), then again with all formatting options
|
|
@@ -342,6 +454,9 @@ require 'json/common'
|
|
|
342
454
|
#
|
|
343
455
|
# == \JSON Additions
|
|
344
456
|
#
|
|
457
|
+
# Note that JSON Additions must only be used with trusted data, and is
|
|
458
|
+
# deprecated.
|
|
459
|
+
#
|
|
345
460
|
# When you "round trip" a non-\String object from Ruby to \JSON and back,
|
|
346
461
|
# you have a new \String, instead of the object you began with:
|
|
347
462
|
# ruby0 = Range.new(0, 2)
|
|
@@ -369,13 +484,13 @@ require 'json/common'
|
|
|
369
484
|
# json1 = JSON.generate(ruby)
|
|
370
485
|
# ruby1 = JSON.parse(json1, create_additions: true)
|
|
371
486
|
# # Make a nice display.
|
|
372
|
-
# display =
|
|
373
|
-
#
|
|
374
|
-
#
|
|
375
|
-
#
|
|
376
|
-
#
|
|
377
|
-
#
|
|
378
|
-
#
|
|
487
|
+
# display = <<~EOT
|
|
488
|
+
# Generated JSON:
|
|
489
|
+
# Without addition: #{json0} (#{json0.class})
|
|
490
|
+
# With addition: #{json1} (#{json1.class})
|
|
491
|
+
# Parsed JSON:
|
|
492
|
+
# Without addition: #{ruby0.inspect} (#{ruby0.class})
|
|
493
|
+
# With addition: #{ruby1.inspect} (#{ruby1.class})
|
|
379
494
|
# EOT
|
|
380
495
|
# puts display
|
|
381
496
|
#
|
|
@@ -553,13 +668,13 @@ require 'json/common'
|
|
|
553
668
|
# json1 = JSON.generate(foo1)
|
|
554
669
|
# obj1 = JSON.parse(json1, create_additions: true)
|
|
555
670
|
# # Make a nice display.
|
|
556
|
-
# display =
|
|
557
|
-
#
|
|
558
|
-
#
|
|
559
|
-
#
|
|
560
|
-
#
|
|
561
|
-
#
|
|
562
|
-
#
|
|
671
|
+
# display = <<~EOT
|
|
672
|
+
# Generated JSON:
|
|
673
|
+
# Without custom addition: #{json0} (#{json0.class})
|
|
674
|
+
# With custom addition: #{json1} (#{json1.class})
|
|
675
|
+
# Parsed JSON:
|
|
676
|
+
# Without custom addition: #{obj0.inspect} (#{obj0.class})
|
|
677
|
+
# With custom addition: #{obj1.inspect} (#{obj1.class})
|
|
563
678
|
# EOT
|
|
564
679
|
# puts display
|
|
565
680
|
#
|
|
@@ -574,10 +689,5 @@ require 'json/common'
|
|
|
574
689
|
#
|
|
575
690
|
module JSON
|
|
576
691
|
require 'json/version'
|
|
577
|
-
|
|
578
|
-
begin
|
|
579
|
-
require 'json/ext'
|
|
580
|
-
rescue LoadError
|
|
581
|
-
require 'json/pure'
|
|
582
|
-
end
|
|
692
|
+
require 'json/ext'
|
|
583
693
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: json
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.21.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: This is a JSON implementation as a Ruby extension in C.
|
|
14
13
|
email: flori@ping.de
|
|
@@ -16,25 +15,25 @@ executables: []
|
|
|
16
15
|
extensions:
|
|
17
16
|
- ext/json/ext/generator/extconf.rb
|
|
18
17
|
- ext/json/ext/parser/extconf.rb
|
|
19
|
-
- ext/json/extconf.rb
|
|
20
18
|
extra_rdoc_files:
|
|
21
19
|
- README.md
|
|
22
20
|
files:
|
|
21
|
+
- BSDL
|
|
23
22
|
- CHANGES.md
|
|
24
|
-
-
|
|
23
|
+
- COPYING
|
|
24
|
+
- LEGAL
|
|
25
25
|
- README.md
|
|
26
|
-
- VERSION
|
|
27
26
|
- ext/json/ext/fbuffer/fbuffer.h
|
|
28
|
-
- ext/json/ext/generator/depend
|
|
29
27
|
- ext/json/ext/generator/extconf.rb
|
|
30
28
|
- ext/json/ext/generator/generator.c
|
|
31
|
-
- ext/json/ext/
|
|
32
|
-
- ext/json/ext/parser/depend
|
|
29
|
+
- ext/json/ext/json.h
|
|
33
30
|
- ext/json/ext/parser/extconf.rb
|
|
34
31
|
- ext/json/ext/parser/parser.c
|
|
35
|
-
- ext/json/ext/
|
|
36
|
-
- ext/json/ext/
|
|
37
|
-
- ext/json/
|
|
32
|
+
- ext/json/ext/simd/conf.rb
|
|
33
|
+
- ext/json/ext/simd/simd.h
|
|
34
|
+
- ext/json/ext/vendor/fast_float_parser.h
|
|
35
|
+
- ext/json/ext/vendor/fpconv.c
|
|
36
|
+
- ext/json/ext/vendor/jeaiii-ltoa.h
|
|
38
37
|
- json.gemspec
|
|
39
38
|
- lib/json.rb
|
|
40
39
|
- lib/json/add/bigdecimal.rb
|
|
@@ -48,27 +47,25 @@ files:
|
|
|
48
47
|
- lib/json/add/rational.rb
|
|
49
48
|
- lib/json/add/regexp.rb
|
|
50
49
|
- lib/json/add/set.rb
|
|
50
|
+
- lib/json/add/string.rb
|
|
51
51
|
- lib/json/add/struct.rb
|
|
52
52
|
- lib/json/add/symbol.rb
|
|
53
53
|
- lib/json/add/time.rb
|
|
54
54
|
- lib/json/common.rb
|
|
55
55
|
- lib/json/ext.rb
|
|
56
|
+
- lib/json/ext/generator/state.rb
|
|
56
57
|
- lib/json/generic_object.rb
|
|
57
|
-
- lib/json/
|
|
58
|
-
- lib/json/pure/generator.rb
|
|
59
|
-
- lib/json/pure/parser.rb
|
|
58
|
+
- lib/json/truffle_ruby/generator.rb
|
|
60
59
|
- lib/json/version.rb
|
|
61
|
-
homepage:
|
|
60
|
+
homepage: https://github.com/ruby/json
|
|
62
61
|
licenses:
|
|
63
62
|
- Ruby
|
|
64
63
|
metadata:
|
|
65
|
-
bug_tracker_uri: https://github.com/
|
|
66
|
-
changelog_uri: https://github.com/
|
|
67
|
-
documentation_uri:
|
|
68
|
-
homepage_uri:
|
|
69
|
-
source_code_uri: https://github.com/
|
|
70
|
-
wiki_uri: https://github.com/flori/json/wiki
|
|
71
|
-
post_install_message:
|
|
64
|
+
bug_tracker_uri: https://github.com/ruby/json/issues
|
|
65
|
+
changelog_uri: https://github.com/ruby/json/blob/master/CHANGES.md
|
|
66
|
+
documentation_uri: https://docs.ruby-lang.org/en/master/JSON.html
|
|
67
|
+
homepage_uri: https://github.com/ruby/json
|
|
68
|
+
source_code_uri: https://github.com/ruby/json
|
|
72
69
|
rdoc_options:
|
|
73
70
|
- "--title"
|
|
74
71
|
- JSON implementation for Ruby
|
|
@@ -80,15 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
80
77
|
requirements:
|
|
81
78
|
- - ">="
|
|
82
79
|
- !ruby/object:Gem::Version
|
|
83
|
-
version: '2.
|
|
80
|
+
version: '2.7'
|
|
84
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
82
|
requirements:
|
|
86
83
|
- - ">="
|
|
87
84
|
- !ruby/object:Gem::Version
|
|
88
85
|
version: '0'
|
|
89
86
|
requirements: []
|
|
90
|
-
rubygems_version:
|
|
91
|
-
signing_key:
|
|
87
|
+
rubygems_version: 4.0.12
|
|
92
88
|
specification_version: 4
|
|
93
89
|
summary: JSON Implementation for Ruby
|
|
94
90
|
test_files: []
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.6.1
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
generator.o: generator.c generator.h $(srcdir)/../fbuffer/fbuffer.h
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
#ifndef _GENERATOR_H_
|
|
2
|
-
#define _GENERATOR_H_
|
|
3
|
-
|
|
4
|
-
#include <math.h>
|
|
5
|
-
#include <ctype.h>
|
|
6
|
-
|
|
7
|
-
#include "ruby.h"
|
|
8
|
-
|
|
9
|
-
#ifdef HAVE_RUBY_RE_H
|
|
10
|
-
#include "ruby/re.h"
|
|
11
|
-
#else
|
|
12
|
-
#include "re.h"
|
|
13
|
-
#endif
|
|
14
|
-
|
|
15
|
-
#ifndef rb_intern_str
|
|
16
|
-
#define rb_intern_str(string) SYM2ID(rb_str_intern(string))
|
|
17
|
-
#endif
|
|
18
|
-
|
|
19
|
-
#ifndef rb_obj_instance_variables
|
|
20
|
-
#define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
|
|
24
|
-
|
|
25
|
-
/* unicode definitions */
|
|
26
|
-
|
|
27
|
-
#define UNI_STRICT_CONVERSION 1
|
|
28
|
-
|
|
29
|
-
typedef unsigned long UTF32; /* at least 32 bits */
|
|
30
|
-
typedef unsigned short UTF16; /* at least 16 bits */
|
|
31
|
-
typedef unsigned char UTF8; /* typically 8 bits */
|
|
32
|
-
|
|
33
|
-
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
|
|
34
|
-
#define UNI_MAX_BMP (UTF32)0x0000FFFF
|
|
35
|
-
#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
|
|
36
|
-
#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
|
|
37
|
-
#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
|
|
38
|
-
|
|
39
|
-
#define UNI_SUR_HIGH_START (UTF32)0xD800
|
|
40
|
-
#define UNI_SUR_HIGH_END (UTF32)0xDBFF
|
|
41
|
-
#define UNI_SUR_LOW_START (UTF32)0xDC00
|
|
42
|
-
#define UNI_SUR_LOW_END (UTF32)0xDFFF
|
|
43
|
-
|
|
44
|
-
static const int halfShift = 10; /* used for shifting by 10 bits */
|
|
45
|
-
|
|
46
|
-
static const UTF32 halfBase = 0x0010000UL;
|
|
47
|
-
static const UTF32 halfMask = 0x3FFUL;
|
|
48
|
-
|
|
49
|
-
static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
|
|
50
|
-
static void unicode_escape(char *buf, UTF16 character);
|
|
51
|
-
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
|
|
52
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escape_slash);
|
|
53
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slash);
|
|
54
|
-
static char *fstrndup(const char *ptr, unsigned long len);
|
|
55
|
-
|
|
56
|
-
/* ruby api and some helpers */
|
|
57
|
-
|
|
58
|
-
typedef struct JSON_Generator_StateStruct {
|
|
59
|
-
char *indent;
|
|
60
|
-
long indent_len;
|
|
61
|
-
char *space;
|
|
62
|
-
long space_len;
|
|
63
|
-
char *space_before;
|
|
64
|
-
long space_before_len;
|
|
65
|
-
char *object_nl;
|
|
66
|
-
long object_nl_len;
|
|
67
|
-
char *array_nl;
|
|
68
|
-
long array_nl_len;
|
|
69
|
-
FBuffer *array_delim;
|
|
70
|
-
FBuffer *object_delim;
|
|
71
|
-
FBuffer *object_delim2;
|
|
72
|
-
long max_nesting;
|
|
73
|
-
char allow_nan;
|
|
74
|
-
char ascii_only;
|
|
75
|
-
char escape_slash;
|
|
76
|
-
long depth;
|
|
77
|
-
long buffer_initial_length;
|
|
78
|
-
} JSON_Generator_State;
|
|
79
|
-
|
|
80
|
-
#define GET_STATE_TO(self, state) \
|
|
81
|
-
TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
|
|
82
|
-
|
|
83
|
-
#define GET_STATE(self) \
|
|
84
|
-
JSON_Generator_State *state; \
|
|
85
|
-
GET_STATE_TO(self, state)
|
|
86
|
-
|
|
87
|
-
#define GENERATE_JSON(type) \
|
|
88
|
-
FBuffer *buffer; \
|
|
89
|
-
VALUE Vstate; \
|
|
90
|
-
JSON_Generator_State *state; \
|
|
91
|
-
\
|
|
92
|
-
rb_scan_args(argc, argv, "01", &Vstate); \
|
|
93
|
-
Vstate = cState_from_state_s(cState, Vstate); \
|
|
94
|
-
TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
|
|
95
|
-
buffer = cState_prepare_buffer(Vstate); \
|
|
96
|
-
generate_json_##type(buffer, Vstate, state, self); \
|
|
97
|
-
return fbuffer_to_s(buffer)
|
|
98
|
-
|
|
99
|
-
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
|
|
100
|
-
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
|
|
101
|
-
#ifdef RUBY_INTEGER_UNIFICATION
|
|
102
|
-
static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
|
|
103
|
-
#else
|
|
104
|
-
static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
|
|
105
|
-
static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
|
|
106
|
-
#endif
|
|
107
|
-
static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
|
|
108
|
-
static VALUE mString_included_s(VALUE self, VALUE modul);
|
|
109
|
-
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
|
|
110
|
-
static VALUE mString_to_json_raw_object(VALUE self);
|
|
111
|
-
static VALUE mString_to_json_raw(int argc, VALUE *argv, VALUE self);
|
|
112
|
-
static VALUE mString_Extend_json_create(VALUE self, VALUE o);
|
|
113
|
-
static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self);
|
|
114
|
-
static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
|
|
115
|
-
static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
|
|
116
|
-
static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
|
|
117
|
-
static void State_free(void *state);
|
|
118
|
-
static VALUE cState_s_allocate(VALUE klass);
|
|
119
|
-
static VALUE cState_configure(VALUE self, VALUE opts);
|
|
120
|
-
static VALUE cState_to_h(VALUE self);
|
|
121
|
-
static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
122
|
-
static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
123
|
-
static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
124
|
-
static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
125
|
-
static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
126
|
-
static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
127
|
-
static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
128
|
-
#ifdef RUBY_INTEGER_UNIFICATION
|
|
129
|
-
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
130
|
-
#endif
|
|
131
|
-
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
132
|
-
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
133
|
-
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
134
|
-
static VALUE cState_partial_generate(VALUE self, VALUE obj);
|
|
135
|
-
static VALUE cState_generate(VALUE self, VALUE obj);
|
|
136
|
-
static VALUE cState_initialize(int argc, VALUE *argv, VALUE self);
|
|
137
|
-
static VALUE cState_from_state_s(VALUE self, VALUE opts);
|
|
138
|
-
static VALUE cState_indent(VALUE self);
|
|
139
|
-
static VALUE cState_indent_set(VALUE self, VALUE indent);
|
|
140
|
-
static VALUE cState_space(VALUE self);
|
|
141
|
-
static VALUE cState_space_set(VALUE self, VALUE space);
|
|
142
|
-
static VALUE cState_space_before(VALUE self);
|
|
143
|
-
static VALUE cState_space_before_set(VALUE self, VALUE space_before);
|
|
144
|
-
static VALUE cState_object_nl(VALUE self);
|
|
145
|
-
static VALUE cState_object_nl_set(VALUE self, VALUE object_nl);
|
|
146
|
-
static VALUE cState_array_nl(VALUE self);
|
|
147
|
-
static VALUE cState_array_nl_set(VALUE self, VALUE array_nl);
|
|
148
|
-
static VALUE cState_max_nesting(VALUE self);
|
|
149
|
-
static VALUE cState_max_nesting_set(VALUE self, VALUE depth);
|
|
150
|
-
static VALUE cState_allow_nan_p(VALUE self);
|
|
151
|
-
static VALUE cState_ascii_only_p(VALUE self);
|
|
152
|
-
static VALUE cState_depth(VALUE self);
|
|
153
|
-
static VALUE cState_depth_set(VALUE self, VALUE depth);
|
|
154
|
-
static VALUE cState_escape_slash(VALUE self);
|
|
155
|
-
static VALUE cState_escape_slash_set(VALUE self, VALUE depth);
|
|
156
|
-
static FBuffer *cState_prepare_buffer(VALUE self);
|
|
157
|
-
#ifndef ZALLOC
|
|
158
|
-
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|
|
159
|
-
static inline void *ruby_zalloc(size_t n)
|
|
160
|
-
{
|
|
161
|
-
void *p = ruby_xmalloc(n);
|
|
162
|
-
memset(p, 0, n);
|
|
163
|
-
return p;
|
|
164
|
-
}
|
|
165
|
-
#endif
|
|
166
|
-
#ifdef TypedData_Make_Struct
|
|
167
|
-
static const rb_data_type_t JSON_Generator_State_type;
|
|
168
|
-
#define NEW_TYPEDDATA_WRAPPER 1
|
|
169
|
-
#else
|
|
170
|
-
#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
|
|
171
|
-
#define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
|
|
172
|
-
#endif
|
|
173
|
-
|
|
174
|
-
#endif
|
data/ext/json/ext/parser/depend
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
parser.o: parser.c parser.h $(srcdir)/../fbuffer/fbuffer.h
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
#ifndef _PARSER_H_
|
|
2
|
-
#define _PARSER_H_
|
|
3
|
-
|
|
4
|
-
#include "ruby.h"
|
|
5
|
-
|
|
6
|
-
#ifndef HAVE_RUBY_RE_H
|
|
7
|
-
#include "re.h"
|
|
8
|
-
#endif
|
|
9
|
-
|
|
10
|
-
#ifdef HAVE_RUBY_ST_H
|
|
11
|
-
#include "ruby/st.h"
|
|
12
|
-
#else
|
|
13
|
-
#include "st.h"
|
|
14
|
-
#endif
|
|
15
|
-
|
|
16
|
-
#ifndef MAYBE_UNUSED
|
|
17
|
-
# define MAYBE_UNUSED(x) x
|
|
18
|
-
#endif
|
|
19
|
-
|
|
20
|
-
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
|
|
21
|
-
|
|
22
|
-
/* unicode */
|
|
23
|
-
|
|
24
|
-
typedef unsigned long UTF32; /* at least 32 bits */
|
|
25
|
-
typedef unsigned short UTF16; /* at least 16 bits */
|
|
26
|
-
typedef unsigned char UTF8; /* typically 8 bits */
|
|
27
|
-
|
|
28
|
-
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
|
|
29
|
-
#define UNI_SUR_HIGH_START (UTF32)0xD800
|
|
30
|
-
#define UNI_SUR_HIGH_END (UTF32)0xDBFF
|
|
31
|
-
#define UNI_SUR_LOW_START (UTF32)0xDC00
|
|
32
|
-
#define UNI_SUR_LOW_END (UTF32)0xDFFF
|
|
33
|
-
|
|
34
|
-
typedef struct JSON_ParserStruct {
|
|
35
|
-
VALUE Vsource;
|
|
36
|
-
char *source;
|
|
37
|
-
long len;
|
|
38
|
-
char *memo;
|
|
39
|
-
VALUE create_id;
|
|
40
|
-
int max_nesting;
|
|
41
|
-
int allow_nan;
|
|
42
|
-
int parsing_name;
|
|
43
|
-
int symbolize_names;
|
|
44
|
-
int freeze;
|
|
45
|
-
VALUE object_class;
|
|
46
|
-
VALUE array_class;
|
|
47
|
-
VALUE decimal_class;
|
|
48
|
-
int create_additions;
|
|
49
|
-
VALUE match_string;
|
|
50
|
-
FBuffer *fbuffer;
|
|
51
|
-
} JSON_Parser;
|
|
52
|
-
|
|
53
|
-
#define GET_PARSER \
|
|
54
|
-
GET_PARSER_INIT; \
|
|
55
|
-
if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
|
|
56
|
-
#define GET_PARSER_INIT \
|
|
57
|
-
JSON_Parser *json; \
|
|
58
|
-
TypedData_Get_Struct(self, JSON_Parser, &JSON_Parser_type, json)
|
|
59
|
-
|
|
60
|
-
#define MinusInfinity "-Infinity"
|
|
61
|
-
#define EVIL 0x666
|
|
62
|
-
|
|
63
|
-
static UTF32 unescape_unicode(const unsigned char *p);
|
|
64
|
-
static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
|
|
65
|
-
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
|
66
|
-
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
|
67
|
-
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
|
|
68
|
-
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
|
|
69
|
-
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
|
|
70
|
-
static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int symbolize);
|
|
71
|
-
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
|
|
72
|
-
static VALUE convert_encoding(VALUE source);
|
|
73
|
-
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
|
|
74
|
-
static VALUE cParser_parse(VALUE self);
|
|
75
|
-
static void JSON_mark(void *json);
|
|
76
|
-
static void JSON_free(void *json);
|
|
77
|
-
static VALUE cJSON_parser_s_allocate(VALUE klass);
|
|
78
|
-
static VALUE cParser_source(VALUE self);
|
|
79
|
-
#ifndef ZALLOC
|
|
80
|
-
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|
|
81
|
-
static inline void *ruby_zalloc(size_t n)
|
|
82
|
-
{
|
|
83
|
-
void *p = ruby_xmalloc(n);
|
|
84
|
-
memset(p, 0, n);
|
|
85
|
-
return p;
|
|
86
|
-
}
|
|
87
|
-
#endif
|
|
88
|
-
#ifdef TypedData_Make_Struct
|
|
89
|
-
static const rb_data_type_t JSON_Parser_type;
|
|
90
|
-
#define NEW_TYPEDDATA_WRAPPER 1
|
|
91
|
-
#else
|
|
92
|
-
#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, JSON_free, json)
|
|
93
|
-
#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
|
|
94
|
-
#endif
|
|
95
|
-
|
|
96
|
-
#endif
|