json 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -5
- data/CHANGES.md +33 -0
- data/README.md +16 -0
- data/Rakefile +8 -87
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +119 -6
- data/ext/json/ext/generator/generator.h +5 -2
- data/ext/json/ext/parser/extconf.rb +25 -0
- data/ext/json/ext/parser/parser.c +99 -71
- data/ext/json/ext/parser/parser.h +1 -0
- data/ext/json/ext/parser/parser.rl +29 -1
- data/ext/json/extconf.rb +1 -0
- data/java/src/json/ext/Generator.java +11 -30
- data/java/src/json/ext/GeneratorState.java +30 -0
- data/java/src/json/ext/Parser.java +85 -73
- data/java/src/json/ext/Parser.rl +14 -2
- data/java/src/json/ext/StringEncoder.java +8 -2
- data/json-java.gemspec +22 -21
- data/json.gemspec +0 -0
- data/json_pure.gemspec +8 -13
- data/lib/json/add/complex.rb +0 -1
- data/lib/json/add/rational.rb +0 -1
- data/lib/json/common.rb +339 -113
- data/lib/json/pure/generator.rb +29 -9
- data/lib/json/pure/parser.rb +22 -4
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +549 -29
- data/tests/json_addition_test.rb +0 -4
- data/tests/json_common_interface_test.rb +43 -0
- data/tests/json_fixtures_test.rb +9 -1
- data/tests/json_generator_test.rb +13 -2
- data/tests/json_parser_test.rb +25 -0
- data/tests/test_helper.rb +3 -3
- metadata +23 -12
data/lib/json/pure/parser.rb
CHANGED
@@ -49,7 +49,7 @@ module JSON
|
|
49
49
|
)+
|
50
50
|
)mx
|
51
51
|
|
52
|
-
|
52
|
+
UNPARSED = Object.new.freeze
|
53
53
|
|
54
54
|
# Creates a new JSON::Pure::Parser instance for the string _source_.
|
55
55
|
#
|
@@ -61,12 +61,14 @@ module JSON
|
|
61
61
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
62
62
|
# defiance of RFC 7159 to be parsed by the Parser. This option defaults
|
63
63
|
# to false.
|
64
|
+
# * *freeze*: If set to true, all parsed objects will be frozen. Parsed
|
65
|
+
# string will be deduplicated if possible.
|
64
66
|
# * *symbolize_names*: If set to true, returns symbols for the names
|
65
67
|
# (keys) in a JSON object. Otherwise strings are returned, which is
|
66
68
|
# also the default. It's not possible to use this option in
|
67
69
|
# conjunction with the *create_additions* option.
|
68
70
|
# * *create_additions*: If set to true, the Parser creates
|
69
|
-
# additions when
|
71
|
+
# additions when a matching class and create_id are found. This
|
70
72
|
# option defaults to false.
|
71
73
|
# * *object_class*: Defaults to Hash
|
72
74
|
# * *array_class*: Defaults to Array
|
@@ -86,6 +88,7 @@ module JSON
|
|
86
88
|
end
|
87
89
|
@allow_nan = !!opts[:allow_nan]
|
88
90
|
@symbolize_names = !!opts[:symbolize_names]
|
91
|
+
@freeze = !!opts[:freeze]
|
89
92
|
if opts.key?(:create_additions)
|
90
93
|
@create_additions = !!opts[:create_additions]
|
91
94
|
else
|
@@ -120,6 +123,7 @@ module JSON
|
|
120
123
|
obj = parse_value
|
121
124
|
UNPARSED.equal?(obj) and raise ParserError,
|
122
125
|
"source is not valid JSON!"
|
126
|
+
obj.freeze if @freeze
|
123
127
|
end
|
124
128
|
while !eos? && skip(IGNORE) do end
|
125
129
|
eos? or raise ParserError, "source is not valid JSON!"
|
@@ -161,6 +165,7 @@ module JSON
|
|
161
165
|
EMPTY_8BIT_STRING.force_encoding Encoding::ASCII_8BIT
|
162
166
|
end
|
163
167
|
|
168
|
+
STR_UMINUS = ''.respond_to?(:-@)
|
164
169
|
def parse_string
|
165
170
|
if scan(STRING)
|
166
171
|
return '' if self[1].empty?
|
@@ -180,6 +185,15 @@ module JSON
|
|
180
185
|
if string.respond_to?(:force_encoding)
|
181
186
|
string.force_encoding(::Encoding::UTF_8)
|
182
187
|
end
|
188
|
+
|
189
|
+
if @freeze
|
190
|
+
if STR_UMINUS
|
191
|
+
string = -string
|
192
|
+
else
|
193
|
+
string.freeze
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
183
197
|
if @create_additions and @match_string
|
184
198
|
for (regexp, klass) in @match_string
|
185
199
|
klass.json_creatable? or next
|
@@ -242,8 +256,10 @@ module JSON
|
|
242
256
|
@max_nesting.nonzero? && @current_nesting > @max_nesting
|
243
257
|
result = @array_class.new
|
244
258
|
delim = false
|
245
|
-
|
259
|
+
loop do
|
246
260
|
case
|
261
|
+
when eos?
|
262
|
+
raise ParserError, "unexpected end of string while parsing array"
|
247
263
|
when !UNPARSED.equal?(value = parse_value)
|
248
264
|
delim = false
|
249
265
|
result << value
|
@@ -274,8 +290,10 @@ module JSON
|
|
274
290
|
@max_nesting.nonzero? && @current_nesting > @max_nesting
|
275
291
|
result = @object_class.new
|
276
292
|
delim = false
|
277
|
-
|
293
|
+
loop do
|
278
294
|
case
|
295
|
+
when eos?
|
296
|
+
raise ParserError, "unexpected end of string while parsing object"
|
279
297
|
when !UNPARSED.equal?(string = parse_string)
|
280
298
|
skip(IGNORE)
|
281
299
|
unless scan(PAIR_DELIMITER)
|
data/lib/json/version.rb
CHANGED