Merge json-2.2.0 from flori/json.

https://github.com/flori/json/releases/tag/v2.2.0

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2019-02-23 03:43:58 +00:00
Родитель f22ffd83e9
Коммит 6604e1b7cd
8 изменённых файлов: 115 добавлений и 80 удалений

Просмотреть файл

@ -1267,7 +1267,7 @@ static VALUE cState_allow_nan_p(VALUE self)
/*
* call-seq: ascii_only?
*
* Returns true, if NaN, Infinity, and -Infinity should be generated, otherwise
* Returns true, if only ASCII characters should be generated. Otherwise
* returns false.
*/
static VALUE cState_ascii_only_p(VALUE self)

Двоичные данные
ext/json/json.gemspec

Двоичный файл не отображается.

Просмотреть файл

@ -23,7 +23,7 @@ class OpenStruct
}
end
# Stores class name (OpenStruct) with this struct's values <tt>v</tt> as a
# Stores class name (OpenStruct) with this struct's values <tt>t</tt> as a
# JSON string.
def to_json(*args)
as_json.to_json(*args)

Просмотреть файл

@ -0,0 +1,29 @@
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
require 'json'
end
defined?(::Set) or require 'set'
class Set
# Import a JSON Marshalled object.
#
# method used for JSON marshalling support.
def self.json_create(object)
new object['a']
end
# Marshal the object to JSON.
#
# method used for JSON marshalling support.
def as_json(*)
{
JSON.create_id => self.class.name,
'a' => to_a,
}
end
# return the JSON value
def to_json(*args)
as_json.to_json(*args)
end
end

Просмотреть файл

@ -1,7 +1,7 @@
# frozen_string_literal: false
module JSON
# JSON version
VERSION = '2.1.0'
VERSION = '2.2.0'
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:

Просмотреть файл

@ -100,11 +100,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
i_leftshift, i_new, i_BigDecimal;
#line 125 "parser.rl"
#line 126 "parser.rl"
#line 107 "parser.c"
#line 108 "parser.c"
enum {JSON_object_start = 1};
enum {JSON_object_first_final = 27};
enum {JSON_object_error = 0};
@ -112,7 +112,7 @@ enum {JSON_object_error = 0};
enum {JSON_object_en_main = 1};
#line 166 "parser.rl"
#line 167 "parser.rl"
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
@ -128,14 +128,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
#line 131 "parser.c"
#line 132 "parser.c"
{
cs = JSON_object_start;
}
#line 181 "parser.rl"
#line 182 "parser.rl"
#line 138 "parser.c"
#line 139 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -163,7 +163,7 @@ case 2:
goto st2;
goto st0;
tr2:
#line 148 "parser.rl"
#line 149 "parser.rl"
{
char *np;
json->parsing_name = 1;
@ -176,7 +176,7 @@ st3:
if ( ++p == pe )
goto _test_eof3;
case 3:
#line 179 "parser.c"
#line 180 "parser.c"
switch( (*p) ) {
case 13: goto st3;
case 32: goto st3;
@ -243,7 +243,7 @@ case 8:
goto st8;
goto st0;
tr11:
#line 133 "parser.rl"
#line 134 "parser.rl"
{
VALUE v = Qnil;
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
@ -263,7 +263,7 @@ st9:
if ( ++p == pe )
goto _test_eof9;
case 9:
#line 266 "parser.c"
#line 267 "parser.c"
switch( (*p) ) {
case 13: goto st9;
case 32: goto st9;
@ -352,14 +352,14 @@ case 18:
goto st9;
goto st18;
tr4:
#line 156 "parser.rl"
#line 157 "parser.rl"
{ p--; {p++; cs = 27; goto _out;} }
goto st27;
st27:
if ( ++p == pe )
goto _test_eof27;
case 27:
#line 362 "parser.c"
#line 363 "parser.c"
goto st0;
st19:
if ( ++p == pe )
@ -457,7 +457,7 @@ case 26:
_out: {}
}
#line 182 "parser.rl"
#line 183 "parser.rl"
if (cs >= JSON_object_first_final) {
if (json->create_additions) {
@ -482,7 +482,7 @@ case 26:
#line 485 "parser.c"
#line 486 "parser.c"
enum {JSON_value_start = 1};
enum {JSON_value_first_final = 29};
enum {JSON_value_error = 0};
@ -490,7 +490,7 @@ enum {JSON_value_error = 0};
enum {JSON_value_en_main = 1};
#line 282 "parser.rl"
#line 283 "parser.rl"
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
@ -498,14 +498,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
int cs = EVIL;
#line 501 "parser.c"
#line 502 "parser.c"
{
cs = JSON_value_start;
}
#line 289 "parser.rl"
#line 290 "parser.rl"
#line 508 "parser.c"
#line 509 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -539,14 +539,14 @@ st0:
cs = 0;
goto _out;
tr2:
#line 234 "parser.rl"
#line 235 "parser.rl"
{
char *np = JSON_parse_string(json, p, pe, result);
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
}
goto st29;
tr3:
#line 239 "parser.rl"
#line 240 "parser.rl"
{
char *np;
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
@ -566,7 +566,7 @@ tr3:
}
goto st29;
tr7:
#line 257 "parser.rl"
#line 258 "parser.rl"
{
char *np;
np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
@ -574,7 +574,7 @@ tr7:
}
goto st29;
tr11:
#line 263 "parser.rl"
#line 264 "parser.rl"
{
char *np;
np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
@ -582,7 +582,7 @@ tr11:
}
goto st29;
tr25:
#line 227 "parser.rl"
#line 228 "parser.rl"
{
if (json->allow_nan) {
*result = CInfinity;
@ -592,7 +592,7 @@ tr25:
}
goto st29;
tr27:
#line 220 "parser.rl"
#line 221 "parser.rl"
{
if (json->allow_nan) {
*result = CNaN;
@ -602,19 +602,19 @@ tr27:
}
goto st29;
tr31:
#line 214 "parser.rl"
#line 215 "parser.rl"
{
*result = Qfalse;
}
goto st29;
tr34:
#line 211 "parser.rl"
#line 212 "parser.rl"
{
*result = Qnil;
}
goto st29;
tr37:
#line 217 "parser.rl"
#line 218 "parser.rl"
{
*result = Qtrue;
}
@ -623,9 +623,9 @@ st29:
if ( ++p == pe )
goto _test_eof29;
case 29:
#line 269 "parser.rl"
#line 270 "parser.rl"
{ p--; {p++; cs = 29; goto _out;} }
#line 628 "parser.c"
#line 629 "parser.c"
switch( (*p) ) {
case 13: goto st29;
case 32: goto st29;
@ -866,7 +866,7 @@ case 28:
_out: {}
}
#line 290 "parser.rl"
#line 291 "parser.rl"
if (cs >= JSON_value_first_final) {
return p;
@ -876,7 +876,7 @@ case 28:
}
#line 879 "parser.c"
#line 880 "parser.c"
enum {JSON_integer_start = 1};
enum {JSON_integer_first_final = 3};
enum {JSON_integer_error = 0};
@ -884,7 +884,7 @@ enum {JSON_integer_error = 0};
enum {JSON_integer_en_main = 1};
#line 306 "parser.rl"
#line 307 "parser.rl"
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@ -892,15 +892,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
int cs = EVIL;
#line 895 "parser.c"
#line 896 "parser.c"
{
cs = JSON_integer_start;
}
#line 313 "parser.rl"
#line 314 "parser.rl"
json->memo = p;
#line 903 "parser.c"
#line 904 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -934,14 +934,14 @@ case 3:
goto st0;
goto tr4;
tr4:
#line 303 "parser.rl"
#line 304 "parser.rl"
{ p--; {p++; cs = 4; goto _out;} }
goto st4;
st4:
if ( ++p == pe )
goto _test_eof4;
case 4:
#line 944 "parser.c"
#line 945 "parser.c"
goto st0;
st5:
if ( ++p == pe )
@ -960,7 +960,7 @@ case 5:
_out: {}
}
#line 315 "parser.rl"
#line 316 "parser.rl"
if (cs >= JSON_integer_first_final) {
long len = p - json->memo;
@ -975,7 +975,7 @@ case 5:
}
#line 978 "parser.c"
#line 979 "parser.c"
enum {JSON_float_start = 1};
enum {JSON_float_first_final = 8};
enum {JSON_float_error = 0};
@ -983,7 +983,7 @@ enum {JSON_float_error = 0};
enum {JSON_float_en_main = 1};
#line 340 "parser.rl"
#line 341 "parser.rl"
static int is_bigdecimal_class(VALUE obj)
@ -1004,15 +1004,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
int cs = EVIL;
#line 994 "parser.c"
#line 1008 "parser.c"
{
cs = JSON_float_start;
}
#line 347 "parser.rl"
#line 361 "parser.rl"
json->memo = p;
#line 1002 "parser.c"
#line 1016 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -1070,14 +1070,14 @@ case 8:
goto st0;
goto tr9;
tr9:
#line 334 "parser.rl"
#line 335 "parser.rl"
{ p--; {p++; cs = 9; goto _out;} }
goto st9;
st9:
if ( ++p == pe )
goto _test_eof9;
case 9:
#line 1067 "parser.c"
#line 1081 "parser.c"
goto st0;
st5:
if ( ++p == pe )
@ -1138,7 +1138,7 @@ case 7:
_out: {}
}
#line 349 "parser.rl"
#line 363 "parser.rl"
if (cs >= JSON_float_first_final) {
long len = p - json->memo;
@ -1164,7 +1164,7 @@ case 7:
#line 1150 "parser.c"
#line 1168 "parser.c"
enum {JSON_array_start = 1};
enum {JSON_array_first_final = 17};
enum {JSON_array_error = 0};
@ -1172,7 +1172,7 @@ enum {JSON_array_error = 0};
enum {JSON_array_en_main = 1};
#line 398 "parser.rl"
#line 416 "parser.rl"
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
@ -1186,14 +1186,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
#line 1172 "parser.c"
#line 1190 "parser.c"
{
cs = JSON_array_start;
}
#line 411 "parser.rl"
#line 429 "parser.rl"
#line 1179 "parser.c"
#line 1197 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -1232,7 +1232,7 @@ case 2:
goto st2;
goto st0;
tr2:
#line 375 "parser.rl"
#line 393 "parser.rl"
{
VALUE v = Qnil;
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
@ -1252,7 +1252,7 @@ st3:
if ( ++p == pe )
goto _test_eof3;
case 3:
#line 1238 "parser.c"
#line 1256 "parser.c"
switch( (*p) ) {
case 13: goto st3;
case 32: goto st3;
@ -1352,14 +1352,14 @@ case 12:
goto st3;
goto st12;
tr4:
#line 390 "parser.rl"
#line 408 "parser.rl"
{ p--; {p++; cs = 17; goto _out;} }
goto st17;
st17:
if ( ++p == pe )
goto _test_eof17;
case 17:
#line 1345 "parser.c"
#line 1363 "parser.c"
goto st0;
st13:
if ( ++p == pe )
@ -1415,7 +1415,7 @@ case 16:
_out: {}
}
#line 412 "parser.rl"
#line 430 "parser.rl"
if(cs >= JSON_array_first_final) {
return p + 1;
@ -1504,7 +1504,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
}
#line 1490 "parser.c"
#line 1508 "parser.c"
enum {JSON_string_start = 1};
enum {JSON_string_first_final = 8};
enum {JSON_string_error = 0};
@ -1512,7 +1512,7 @@ enum {JSON_string_error = 0};
enum {JSON_string_en_main = 1};
#line 519 "parser.rl"
#line 537 "parser.rl"
static int
@ -1534,15 +1534,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
*result = rb_str_buf_new(0);
#line 1520 "parser.c"
#line 1538 "parser.c"
{
cs = JSON_string_start;
}
#line 540 "parser.rl"
#line 558 "parser.rl"
json->memo = p;
#line 1528 "parser.c"
#line 1546 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -1567,7 +1567,7 @@ case 2:
goto st0;
goto st2;
tr2:
#line 505 "parser.rl"
#line 523 "parser.rl"
{
*result = json_string_unescape(*result, json->memo + 1, p);
if (NIL_P(*result)) {
@ -1578,14 +1578,14 @@ tr2:
{p = (( p + 1))-1;}
}
}
#line 516 "parser.rl"
#line 534 "parser.rl"
{ p--; {p++; cs = 8; goto _out;} }
goto st8;
st8:
if ( ++p == pe )
goto _test_eof8;
case 8:
#line 1571 "parser.c"
#line 1589 "parser.c"
goto st0;
st3:
if ( ++p == pe )
@ -1661,7 +1661,7 @@ case 7:
_out: {}
}
#line 542 "parser.rl"
#line 560 "parser.rl"
if (json->create_additions && RTEST(match_string = json->match_string)) {
VALUE klass;
@ -1850,7 +1850,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
}
#line 1836 "parser.c"
#line 1854 "parser.c"
enum {JSON_start = 1};
enum {JSON_first_final = 10};
enum {JSON_error = 0};
@ -1858,7 +1858,7 @@ enum {JSON_error = 0};
enum {JSON_en_main = 1};
#line 744 "parser.rl"
#line 762 "parser.rl"
/*
@ -1875,16 +1875,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
#line 1861 "parser.c"
#line 1879 "parser.c"
{
cs = JSON_start;
}
#line 760 "parser.rl"
#line 778 "parser.rl"
p = json->source;
pe = p + json->len;
#line 1870 "parser.c"
#line 1888 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -1918,7 +1918,7 @@ st0:
cs = 0;
goto _out;
tr2:
#line 736 "parser.rl"
#line 754 "parser.rl"
{
char *np = JSON_parse_value(json, p, pe, &result, 0);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@ -1928,7 +1928,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
#line 1914 "parser.c"
#line 1932 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@ -2017,7 +2017,7 @@ case 9:
_out: {}
}
#line 763 "parser.rl"
#line 781 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;

Просмотреть файл

@ -5,6 +5,7 @@ require 'json/add/complex'
require 'json/add/rational'
require 'json/add/bigdecimal'
require 'json/add/ostruct'
require 'json/add/set'
require 'date'
class JSONAdditionTest < Test::Unit::TestCase
@ -190,4 +191,13 @@ class JSONAdditionTest < Test::Unit::TestCase
o.foo = { 'bar' => true }
assert_equal o, parse(JSON(o), :create_additions => true)
end
def test_set
s = Set.new([:a, :b, :c, :a])
assert_equal s, JSON.parse(JSON(s), :create_additions => true)
ss = SortedSet.new([:d, :b, :a, :c])
ss_again = JSON.parse(JSON(ss), :create_additions => true)
assert_kind_of ss.class, ss_again
assert_equal ss, ss_again
end
end

Просмотреть файл

@ -15,7 +15,3 @@ begin
require 'byebug'
rescue LoadError
end
if ENV['START_SIMPLECOV'].to_i == 1
require 'simplecov'
SimpleCov.start
end