* ext/json: Update to JSON 1.1.9.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2009-09-01 16:17:56 +00:00
Родитель d2d0d733c1
Коммит c719ecb535
18 изменённых файлов: 144 добавлений и 2181 удалений

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

@ -1,3 +1,7 @@
Wed Sep 2 01:16:32 2009 NARUSE, Yui <naruse@ruby-lang.org>
* ext/json: Update to JSON 1.1.9.
Tue Sep 1 19:56:28 2009 Koichi Sasada <ko1@atdot.net>
* vm_eval.c (eval_string_with_cref): fix to check local_table_size.

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

@ -496,7 +496,7 @@ static VALUE cState_s_allocate(VALUE klass)
* Configure this State instance with the Hash _opts_, and return
* itself.
*/
static inline VALUE cState_configure(VALUE self, VALUE opts)
static VALUE cState_configure(VALUE self, VALUE opts)
{
VALUE tmp;
GET_STATE(self);

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

@ -144,8 +144,6 @@ void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags
rb_str_buf_cat2(buffer, "\\\"");
} else if (ch == '\\') {
rb_str_buf_cat2(buffer, "\\\\");
} else if (ch == '/') {
rb_str_buf_cat2(buffer, "\\/");
} else if (ch >= 0x20 && ch <= 0x7f) {
rb_str_buf_cat(buffer, (char *) source - 1, 1);
} else if (ch == '\n') {

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

@ -29,7 +29,7 @@ static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
static VALUE CNaN, CInfinity, CMinusInfinity;
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
i_chr, i_max_nesting, i_allow_nan;
i_chr, i_max_nesting, i_allow_nan, i_object_class, i_array_class;
#define MinusInfinity "-Infinity"
@ -42,6 +42,8 @@ typedef struct JSON_ParserStruct {
int max_nesting;
int current_nesting;
int allow_nan;
VALUE object_class;
VALUE array_class;
} JSON_Parser;
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
@ -56,11 +58,11 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
Data_Get_Struct(self, JSON_Parser, json);
#line 82 "parser.rl"
#line 84 "parser.rl"
#line 64 "parser.c"
#line 66 "parser.c"
static const int JSON_object_start = 1;
static const int JSON_object_first_final = 27;
static const int JSON_object_error = 0;
@ -68,29 +70,30 @@ static const int JSON_object_error = 0;
static const int JSON_object_en_main = 1;
#line 115 "parser.rl"
#line 117 "parser.rl"
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
{
int cs = EVIL;
VALUE last_name = Qnil;
VALUE object_class = json->object_class;
if (json->max_nesting && json->current_nesting > json->max_nesting) {
rb_raise(eNestingError, "nesting of %d is to deep", json->current_nesting);
rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
}
*result = rb_hash_new();
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
#line 87 "parser.c"
#line 90 "parser.c"
{
cs = JSON_object_start;
}
#line 129 "parser.rl"
#line 132 "parser.rl"
#line 94 "parser.c"
#line 97 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -118,7 +121,7 @@ case 2:
goto st2;
goto st0;
tr2:
#line 101 "parser.rl"
#line 103 "parser.rl"
{
char *np = JSON_parse_string(json, p, pe, &last_name);
if (np == NULL) { p--; {p++; cs = 3; goto _out;} } else {p = (( np))-1;}
@ -128,7 +131,7 @@ st3:
if ( ++p == pe )
goto _test_eof3;
case 3:
#line 132 "parser.c"
#line 135 "parser.c"
switch( (*p) ) {
case 13: goto st3;
case 32: goto st3;
@ -195,7 +198,7 @@ case 8:
goto st8;
goto st0;
tr11:
#line 90 "parser.rl"
#line 92 "parser.rl"
{
VALUE v = Qnil;
char *np = JSON_parse_value(json, p, pe, &v);
@ -211,7 +214,7 @@ st9:
if ( ++p == pe )
goto _test_eof9;
case 9:
#line 215 "parser.c"
#line 218 "parser.c"
switch( (*p) ) {
case 13: goto st9;
case 32: goto st9;
@ -300,14 +303,14 @@ case 18:
goto st9;
goto st18;
tr4:
#line 106 "parser.rl"
#line 108 "parser.rl"
{ p--; {p++; cs = 27; goto _out;} }
goto st27;
st27:
if ( ++p == pe )
goto _test_eof27;
case 27:
#line 311 "parser.c"
#line 314 "parser.c"
goto st0;
st19:
if ( ++p == pe )
@ -405,7 +408,7 @@ case 26:
_out: {}
}
#line 130 "parser.rl"
#line 133 "parser.rl"
if (cs >= JSON_object_first_final) {
if (RTEST(json->create_id)) {
@ -424,7 +427,7 @@ case 26:
}
#line 428 "parser.c"
#line 431 "parser.c"
static const int JSON_value_start = 1;
static const int JSON_value_first_final = 21;
static const int JSON_value_error = 0;
@ -432,7 +435,7 @@ static const int JSON_value_error = 0;
static const int JSON_value_en_main = 1;
#line 228 "parser.rl"
#line 231 "parser.rl"
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
@ -440,14 +443,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
int cs = EVIL;
#line 444 "parser.c"
#line 447 "parser.c"
{
cs = JSON_value_start;
}
#line 235 "parser.rl"
#line 238 "parser.rl"
#line 451 "parser.c"
#line 454 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -472,14 +475,14 @@ st0:
cs = 0;
goto _out;
tr0:
#line 176 "parser.rl"
#line 179 "parser.rl"
{
char *np = JSON_parse_string(json, p, pe, result);
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
}
goto st21;
tr2:
#line 181 "parser.rl"
#line 184 "parser.rl"
{
char *np;
if(pe > p + 9 && !strncmp(MinusInfinity, p, 9)) {
@ -499,7 +502,7 @@ tr2:
}
goto st21;
tr5:
#line 199 "parser.rl"
#line 202 "parser.rl"
{
char *np;
json->current_nesting++;
@ -509,7 +512,7 @@ tr5:
}
goto st21;
tr9:
#line 207 "parser.rl"
#line 210 "parser.rl"
{
char *np;
json->current_nesting++;
@ -519,7 +522,7 @@ tr9:
}
goto st21;
tr16:
#line 169 "parser.rl"
#line 172 "parser.rl"
{
if (json->allow_nan) {
*result = CInfinity;
@ -529,7 +532,7 @@ tr16:
}
goto st21;
tr18:
#line 162 "parser.rl"
#line 165 "parser.rl"
{
if (json->allow_nan) {
*result = CNaN;
@ -539,19 +542,19 @@ tr18:
}
goto st21;
tr22:
#line 156 "parser.rl"
#line 159 "parser.rl"
{
*result = Qfalse;
}
goto st21;
tr25:
#line 153 "parser.rl"
#line 156 "parser.rl"
{
*result = Qnil;
}
goto st21;
tr28:
#line 159 "parser.rl"
#line 162 "parser.rl"
{
*result = Qtrue;
}
@ -560,9 +563,9 @@ st21:
if ( ++p == pe )
goto _test_eof21;
case 21:
#line 215 "parser.rl"
#line 218 "parser.rl"
{ p--; {p++; cs = 21; goto _out;} }
#line 566 "parser.c"
#line 569 "parser.c"
goto st0;
st2:
if ( ++p == pe )
@ -723,7 +726,7 @@ case 20:
_out: {}
}
#line 236 "parser.rl"
#line 239 "parser.rl"
if (cs >= JSON_value_first_final) {
return p;
@ -733,7 +736,7 @@ case 20:
}
#line 737 "parser.c"
#line 740 "parser.c"
static const int JSON_integer_start = 1;
static const int JSON_integer_first_final = 5;
static const int JSON_integer_error = 0;
@ -741,7 +744,7 @@ static const int JSON_integer_error = 0;
static const int JSON_integer_en_main = 1;
#line 252 "parser.rl"
#line 255 "parser.rl"
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@ -749,15 +752,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
int cs = EVIL;
#line 753 "parser.c"
#line 756 "parser.c"
{
cs = JSON_integer_start;
}
#line 259 "parser.rl"
#line 262 "parser.rl"
json->memo = p;
#line 761 "parser.c"
#line 764 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -791,14 +794,14 @@ case 3:
goto st0;
goto tr4;
tr4:
#line 249 "parser.rl"
#line 252 "parser.rl"
{ p--; {p++; cs = 5; goto _out;} }
goto st5;
st5:
if ( ++p == pe )
goto _test_eof5;
case 5:
#line 802 "parser.c"
#line 805 "parser.c"
goto st0;
st4:
if ( ++p == pe )
@ -817,7 +820,7 @@ case 4:
_out: {}
}
#line 261 "parser.rl"
#line 264 "parser.rl"
if (cs >= JSON_integer_first_final) {
long len = p - json->memo;
@ -829,7 +832,7 @@ case 4:
}
#line 833 "parser.c"
#line 836 "parser.c"
static const int JSON_float_start = 1;
static const int JSON_float_first_final = 10;
static const int JSON_float_error = 0;
@ -837,7 +840,7 @@ static const int JSON_float_error = 0;
static const int JSON_float_en_main = 1;
#line 283 "parser.rl"
#line 286 "parser.rl"
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@ -845,15 +848,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
int cs = EVIL;
#line 849 "parser.c"
#line 852 "parser.c"
{
cs = JSON_float_start;
}
#line 290 "parser.rl"
#line 293 "parser.rl"
json->memo = p;
#line 857 "parser.c"
#line 860 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -911,14 +914,14 @@ case 5:
goto st0;
goto tr7;
tr7:
#line 277 "parser.rl"
#line 280 "parser.rl"
{ p--; {p++; cs = 10; goto _out;} }
goto st10;
st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
#line 922 "parser.c"
#line 925 "parser.c"
goto st0;
st6:
if ( ++p == pe )
@ -979,7 +982,7 @@ case 9:
_out: {}
}
#line 292 "parser.rl"
#line 295 "parser.rl"
if (cs >= JSON_float_first_final) {
long len = p - json->memo;
@ -992,7 +995,7 @@ case 9:
#line 996 "parser.c"
#line 999 "parser.c"
static const int JSON_array_start = 1;
static const int JSON_array_first_final = 17;
static const int JSON_array_error = 0;
@ -1000,27 +1003,28 @@ static const int JSON_array_error = 0;
static const int JSON_array_en_main = 1;
#line 328 "parser.rl"
#line 331 "parser.rl"
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
{
int cs = EVIL;
VALUE array_class = json->array_class;
if (json->max_nesting && json->current_nesting > json->max_nesting) {
rb_raise(eNestingError, "nesting of %d is to deep", json->current_nesting);
rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
}
*result = rb_ary_new();
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
#line 1017 "parser.c"
#line 1021 "parser.c"
{
cs = JSON_array_start;
}
#line 340 "parser.rl"
#line 344 "parser.rl"
#line 1024 "parser.c"
#line 1028 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -1059,7 +1063,7 @@ case 2:
goto st2;
goto st0;
tr2:
#line 309 "parser.rl"
#line 312 "parser.rl"
{
VALUE v = Qnil;
char *np = JSON_parse_value(json, p, pe, &v);
@ -1075,7 +1079,7 @@ st3:
if ( ++p == pe )
goto _test_eof3;
case 3:
#line 1079 "parser.c"
#line 1083 "parser.c"
switch( (*p) ) {
case 13: goto st3;
case 32: goto st3;
@ -1175,14 +1179,14 @@ case 12:
goto st3;
goto st12;
tr4:
#line 320 "parser.rl"
#line 323 "parser.rl"
{ p--; {p++; cs = 17; goto _out;} }
goto st17;
st17:
if ( ++p == pe )
goto _test_eof17;
case 17:
#line 1186 "parser.c"
#line 1190 "parser.c"
goto st0;
st13:
if ( ++p == pe )
@ -1238,7 +1242,7 @@ case 16:
_out: {}
}
#line 341 "parser.rl"
#line 345 "parser.rl"
if(cs >= JSON_array_first_final) {
return p + 1;
@ -1304,7 +1308,7 @@ static VALUE json_string_unescape(char *p, char *pe)
}
#line 1308 "parser.c"
#line 1312 "parser.c"
static const int JSON_string_start = 1;
static const int JSON_string_first_final = 8;
static const int JSON_string_error = 0;
@ -1312,7 +1316,7 @@ static const int JSON_string_error = 0;
static const int JSON_string_en_main = 1;
#line 425 "parser.rl"
#line 429 "parser.rl"
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
@ -1321,15 +1325,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
*result = rb_str_new("", 0);
#line 1325 "parser.c"
#line 1329 "parser.c"
{
cs = JSON_string_start;
}
#line 433 "parser.rl"
#line 437 "parser.rl"
json->memo = p;
#line 1333 "parser.c"
#line 1337 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -1354,7 +1358,7 @@ case 2:
goto st0;
goto st2;
tr2:
#line 411 "parser.rl"
#line 415 "parser.rl"
{
*result = json_string_unescape(json->memo + 1, p);
if (NIL_P(*result)) {
@ -1365,14 +1369,14 @@ tr2:
{p = (( p + 1))-1;}
}
}
#line 422 "parser.rl"
#line 426 "parser.rl"
{ p--; {p++; cs = 8; goto _out;} }
goto st8;
st8:
if ( ++p == pe )
goto _test_eof8;
case 8:
#line 1376 "parser.c"
#line 1380 "parser.c"
goto st0;
st3:
if ( ++p == pe )
@ -1448,7 +1452,7 @@ case 7:
_out: {}
}
#line 435 "parser.rl"
#line 439 "parser.rl"
if (cs >= JSON_string_first_final) {
return p + 1;
@ -1459,7 +1463,7 @@ case 7:
#line 1463 "parser.c"
#line 1467 "parser.c"
static const int JSON_start = 1;
static const int JSON_first_final = 10;
static const int JSON_error = 0;
@ -1467,7 +1471,7 @@ static const int JSON_error = 0;
static const int JSON_en_main = 1;
#line 469 "parser.rl"
#line 473 "parser.rl"
/*
@ -1502,6 +1506,8 @@ static const int JSON_en_main = 1;
* * *create_additions*: If set to false, the Parser doesn't create
* additions even if a matchin class and create_id was found. This option
* defaults to true.
* * *object_class*: Defaults to Hash
* * *array_class*: Defaults to Array
*/
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
{
@ -1551,11 +1557,25 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
} else {
json->create_id = rb_funcall(mJSON, i_create_id, 0);
}
tmp = ID2SYM(i_object_class);
if (st_lookup(RHASH_TBL(opts), tmp, 0)) {
json->object_class = rb_hash_aref(opts, tmp);
} else {
json->object_class = Qnil;
}
tmp = ID2SYM(i_array_class);
if (st_lookup(RHASH_TBL(opts), tmp, 0)) {
json->array_class = rb_hash_aref(opts, tmp);
} else {
json->array_class = Qnil;
}
}
} else {
json->max_nesting = 19;
json->allow_nan = 0;
json->create_id = rb_funcall(mJSON, i_create_id, 0);
json->object_class = Qnil;
json->array_class = Qnil;
}
json->current_nesting = 0;
/*
@ -1590,16 +1610,16 @@ static VALUE cParser_parse(VALUE self)
GET_STRUCT;
#line 1594 "parser.c"
#line 1614 "parser.c"
{
cs = JSON_start;
}
#line 591 "parser.rl"
#line 611 "parser.rl"
p = json->source;
pe = p + json->len;
#line 1603 "parser.c"
#line 1623 "parser.c"
{
if ( p == pe )
goto _test_eof;
@ -1655,7 +1675,7 @@ case 5:
goto st1;
goto st5;
tr3:
#line 458 "parser.rl"
#line 462 "parser.rl"
{
char *np;
json->current_nesting = 1;
@ -1664,7 +1684,7 @@ tr3:
}
goto st10;
tr4:
#line 451 "parser.rl"
#line 455 "parser.rl"
{
char *np;
json->current_nesting = 1;
@ -1676,7 +1696,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
#line 1680 "parser.c"
#line 1700 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@ -1733,7 +1753,7 @@ case 9:
_out: {}
}
#line 594 "parser.rl"
#line 614 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@ -1753,6 +1773,8 @@ static void JSON_mark(JSON_Parser *json)
{
rb_gc_mark_maybe(json->Vsource);
rb_gc_mark_maybe(json->create_id);
rb_gc_mark_maybe(json->object_class);
rb_gc_mark_maybe(json->array_class);
}
static void JSON_free(JSON_Parser *json)
@ -1802,4 +1824,6 @@ void Init_parser()
i_chr = rb_intern("chr");
i_max_nesting = rb_intern("max_nesting");
i_allow_nan = rb_intern("allow_nan");
i_object_class = rb_intern("object_class");
i_array_class = rb_intern("array_class");
}

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

@ -27,7 +27,7 @@ static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
static VALUE CNaN, CInfinity, CMinusInfinity;
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
i_chr, i_max_nesting, i_allow_nan;
i_chr, i_max_nesting, i_allow_nan, i_object_class, i_array_class;
#define MinusInfinity "-Infinity"
@ -40,6 +40,8 @@ typedef struct JSON_ParserStruct {
int max_nesting;
int current_nesting;
int allow_nan;
VALUE object_class;
VALUE array_class;
} JSON_Parser;
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
@ -118,12 +120,13 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
{
int cs = EVIL;
VALUE last_name = Qnil;
VALUE object_class = json->object_class;
if (json->max_nesting && json->current_nesting > json->max_nesting) {
rb_raise(eNestingError, "nesting of %d is to deep", json->current_nesting);
rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
}
*result = rb_hash_new();
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
%% write init;
%% write exec;
@ -330,11 +333,12 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
{
int cs = EVIL;
VALUE array_class = json->array_class;
if (json->max_nesting && json->current_nesting > json->max_nesting) {
rb_raise(eNestingError, "nesting of %d is to deep", json->current_nesting);
rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
}
*result = rb_ary_new();
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
%% write init;
%% write exec;
@ -500,6 +504,8 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
* * *create_additions*: If set to false, the Parser doesn't create
* additions even if a matchin class and create_id was found. This option
* defaults to true.
* * *object_class*: Defaults to Hash
* * *array_class*: Defaults to Array
*/
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
{
@ -549,11 +555,25 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
} else {
json->create_id = rb_funcall(mJSON, i_create_id, 0);
}
tmp = ID2SYM(i_object_class);
if (st_lookup(RHASH_TBL(opts), tmp, 0)) {
json->object_class = rb_hash_aref(opts, tmp);
} else {
json->object_class = Qnil;
}
tmp = ID2SYM(i_array_class);
if (st_lookup(RHASH_TBL(opts), tmp, 0)) {
json->array_class = rb_hash_aref(opts, tmp);
} else {
json->array_class = Qnil;
}
}
} else {
json->max_nesting = 19;
json->allow_nan = 0;
json->create_id = rb_funcall(mJSON, i_create_id, 0);
json->object_class = Qnil;
json->array_class = Qnil;
}
json->current_nesting = 0;
/*
@ -610,6 +630,8 @@ static void JSON_mark(JSON_Parser *json)
{
rb_gc_mark_maybe(json->Vsource);
rb_gc_mark_maybe(json->create_id);
rb_gc_mark_maybe(json->object_class);
rb_gc_mark_maybe(json->array_class);
}
static void JSON_free(JSON_Parser *json)
@ -659,4 +681,6 @@ void Init_parser()
i_chr = rb_intern("chr");
i_max_nesting = rb_intern("max_nesting");
i_allow_nan = rb_intern("allow_nan");
i_object_class = rb_intern("object_class");
i_array_class = rb_intern("array_class");
}

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

@ -81,7 +81,7 @@ char *JSON_convert_UTF16_to_UTF8 (
buf[1] = *p++;
buf[2] = *p++;
buf[3] = *p++;
tmpPtr[i] = strtol(buf, NULL, 16);
tmpPtr[i] = (UTF16)strtol(buf, NULL, 16);
p += 2;
}

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

@ -1,297 +1,10 @@
require 'json/common'
# = json - JSON for Ruby
#
# == Description
#
# This is a implementation of the JSON specification according to RFC 4627
# (http://www.ietf.org/rfc/rfc4627.txt). Starting from version 1.0.0 on there
# will be two variants available:
#
# * A pure ruby variant, that relies on the iconv and the stringscan
# extensions, which are both part of the ruby standard library.
# * The quite a bit faster C extension variant, which is in parts implemented
# in C and comes with its own unicode conversion functions and a parser
# generated by the ragel state machine compiler
# (http://www.cs.queensu.ca/~thurston/ragel).
#
# Both variants of the JSON generator escape all non-ASCII an control
# characters with \uXXXX escape sequences, and support UTF-16 surrogate pairs
# in order to be able to generate the whole range of unicode code points. This
# means that generated JSON text is encoded as UTF-8 (because ASCII is a subset
# of UTF-8) and at the same time avoids decoding problems for receiving
# endpoints, that don't expect UTF-8 encoded texts. On the negative side this
# may lead to a bit longer strings than necessarry.
#
# All strings, that are to be encoded as JSON strings, should be UTF-8 byte
# sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
# encoded, please use the to_json_raw_object method of String (which produces
# an object, that contains a byte array) and decode the result on the receiving
# endpoint.
#
# == Author
#
# Florian Frank <mailto:flori@ping.de>
#
# == License
#
# This software is distributed under the same license as Ruby itself, see
# http://www.ruby-lang.org/en/LICENSE.txt.
#
# == Download
#
# The latest version of this library can be downloaded at
#
# * http://rubyforge.org/frs?group_id=953
#
# Online Documentation should be located at
#
# * http://json.rubyforge.org
#
# == Usage
#
# To use JSON you can
# require 'json'
# to load the installed variant (either the extension 'json' or the pure
# variant 'json_pure'). If you have installed the extension variant, you can
# pick either the extension variant or the pure variant by typing
# require 'json/ext'
# or
# require 'json/pure'
#
# You can choose to load a set of common additions to ruby core's objects if
# you
# require 'json/add/core'
#
# After requiring this you can, e. g., serialise/deserialise Ruby ranges:
#
# JSON JSON(1..10) # => 1..10
#
# To find out how to add JSON support to other or your own classes, read the
# Examples section below.
#
# To get the best compatibility to rails' JSON implementation, you can
# require 'json/add/rails'
#
# Both of the additions attempt to require 'json' (like above) first, if it has
# not been required yet.
#
# == Speed Comparisons
#
# I have created some benchmark results (see the benchmarks/data-p4-3Ghz
# subdir of the package) for the JSON-parser to estimate the speed up in the C
# extension:
#
# Comparing times (call_time_mean):
# 1 ParserBenchmarkExt#parser 900 repeats:
# 553.922304770 ( real) -> 21.500x
# 0.001805307
# 2 ParserBenchmarkYAML#parser 1000 repeats:
# 224.513358139 ( real) -> 8.714x
# 0.004454078
# 3 ParserBenchmarkPure#parser 1000 repeats:
# 26.755020642 ( real) -> 1.038x
# 0.037376163
# 4 ParserBenchmarkRails#parser 1000 repeats:
# 25.763381731 ( real) -> 1.000x
# 0.038814780
# calls/sec ( time) -> speed covers
# secs/call
#
# In the table above 1 is JSON::Ext::Parser, 2 is YAML.load with YAML
# compatbile JSON document, 3 is is JSON::Pure::Parser, and 4 is
# ActiveSupport::JSON.decode. The ActiveSupport JSON-decoder converts the
# input first to YAML and then uses the YAML-parser, the conversion seems to
# slow it down so much that it is only as fast as the JSON::Pure::Parser!
#
# If you look at the benchmark data you can see that this is mostly caused by
# the frequent high outliers - the median of the Rails-parser runs is still
# overall smaller than the median of the JSON::Pure::Parser runs:
#
# Comparing times (call_time_median):
# 1 ParserBenchmarkExt#parser 900 repeats:
# 800.592479481 ( real) -> 26.936x
# 0.001249075
# 2 ParserBenchmarkYAML#parser 1000 repeats:
# 271.002390644 ( real) -> 9.118x
# 0.003690004
# 3 ParserBenchmarkRails#parser 1000 repeats:
# 30.227910865 ( real) -> 1.017x
# 0.033082008
# 4 ParserBenchmarkPure#parser 1000 repeats:
# 29.722384421 ( real) -> 1.000x
# 0.033644676
# calls/sec ( time) -> speed covers
# secs/call
#
# I have benchmarked the JSON-Generator as well. This generated a few more
# values, because there are different modes that also influence the achieved
# speed:
#
# Comparing times (call_time_mean):
# 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
# 547.354332608 ( real) -> 15.090x
# 0.001826970
# 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
# 443.968212317 ( real) -> 12.240x
# 0.002252414
# 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
# 375.104545883 ( real) -> 10.341x
# 0.002665923
# 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
# 49.978706968 ( real) -> 1.378x
# 0.020008521
# 5 GeneratorBenchmarkRails#generator 1000 repeats:
# 38.531868759 ( real) -> 1.062x
# 0.025952543
# 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
# 36.927649925 ( real) -> 1.018x 7 (>=3859)
# 0.027079979
# 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
# 36.272134441 ( real) -> 1.000x 6 (>=3859)
# 0.027569373
# calls/sec ( time) -> speed covers
# secs/call
#
# In the table above 1-3 are JSON::Ext::Generator methods. 4, 6, and 7 are
# JSON::Pure::Generator methods and 5 is the Rails JSON generator. It is now a
# bit faster than the generator_safe and generator_pretty methods of the pure
# variant but slower than the others.
#
# To achieve the fastest JSON text output, you can use the fast_generate
# method. Beware, that this will disable the checking for circular Ruby data
# structures, which may cause JSON to go into an infinite loop.
#
# Here are the median comparisons for completeness' sake:
#
# Comparing times (call_time_median):
# 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
# 708.258020939 ( real) -> 16.547x
# 0.001411915
# 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
# 569.105020353 ( real) -> 13.296x
# 0.001757145
# 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
# 482.825371244 ( real) -> 11.280x
# 0.002071142
# 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
# 62.717626652 ( real) -> 1.465x
# 0.015944481
# 5 GeneratorBenchmarkRails#generator 1000 repeats:
# 43.965681162 ( real) -> 1.027x
# 0.022745013
# 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
# 43.929073409 ( real) -> 1.026x 7 (>=3859)
# 0.022763968
# 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
# 42.802514491 ( real) -> 1.000x 6 (>=3859)
# 0.023363113
# calls/sec ( time) -> speed covers
# secs/call
#
# == Examples
#
# To create a JSON text from a ruby data structure, you can call JSON.generate
# like that:
#
# json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
# # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
#
# To create a valid JSON text you have to make sure, that the output is
# embedded in either a JSON array [] or a JSON object {}. The easiest way to do
# this, is by putting your values in a Ruby Array or Hash instance.
#
# To get back a ruby data structure from a JSON text, you have to call
# JSON.parse on it:
#
# JSON.parse json
# # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
#
# Note, that the range from the original data structure is a simple
# string now. The reason for this is, that JSON doesn't support ranges
# or arbitrary classes. In this case the json library falls back to call
# Object#to_json, which is the same as #to_s.to_json.
#
# It's possible to add JSON support serialization to arbitrary classes by
# simply implementing a more specialized version of the #to_json method, that
# should return a JSON object (a hash converted to JSON with #to_json) like
# this (don't forget the *a for all the arguments):
#
# class Range
# def to_json(*a)
# {
# 'json_class' => self.class.name, # = 'Range'
# 'data' => [ first, last, exclude_end? ]
# }.to_json(*a)
# end
# end
#
# The hash key 'json_class' is the class, that will be asked to deserialise the
# JSON representation later. In this case it's 'Range', but any namespace of
# the form 'A::B' or '::A::B' will do. All other keys are arbitrary and can be
# used to store the necessary data to configure the object to be deserialised.
#
# If a the key 'json_class' is found in a JSON object, the JSON parser checks
# if the given class responds to the json_create class method. If so, it is
# called with the JSON object converted to a Ruby hash. So a range can
# be deserialised by implementing Range.json_create like this:
#
# class Range
# def self.json_create(o)
# new(*o['data'])
# end
# end
#
# Now it possible to serialise/deserialise ranges as well:
#
# json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
# # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
# JSON.parse json
# # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
#
# JSON.generate always creates the shortest possible string representation of a
# ruby data structure in one line. This good for data storage or network
# protocols, but not so good for humans to read. Fortunately there's also
# JSON.pretty_generate (or JSON.pretty_generate) that creates a more
# readable output:
#
# puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
# [
# 1,
# 2,
# {
# "a": 3.141
# },
# false,
# true,
# null,
# {
# "json_class": "Range",
# "data": [
# 4,
# 10,
# false
# ]
# }
# ]
#
# There are also the methods Kernel#j for generate, and Kernel#jj for
# pretty_generate output to the console, that work analogous to Core Ruby's p
# and the pp library's pp methods.
#
# The script tools/server.rb contains a small example if you want to test, how
# receiving a JSON object from a webrick server in your browser with the
# javasript prototype library (http://www.prototypejs.org) works.
#
module JSON
require 'json/version'
if VARIANT_BINARY
require 'json/ext'
else
begin
require 'json/ext'
rescue LoadError
require 'json/pure'
end
end
end

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

@ -1,21 +0,0 @@
/* XPM */
static char * Array_xpm[] = {
"16 16 2 1",
" c None",
". c #000000",
" ",
" ",
" ",
" .......... ",
" . . ",
" . . ",
" . . ",
" . . ",
" . . ",
" . . ",
" . . ",
" . . ",
" .......... ",
" ",
" ",
" "};

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

@ -1,21 +0,0 @@
/* XPM */
static char * False_xpm[] = {
"16 16 2 1",
" c None",
". c #FF0000",
" ",
" ",
" ",
" ...... ",
" . ",
" . ",
" . ",
" ...... ",
" . ",
" . ",
" . ",
" . ",
" . ",
" ",
" ",
" "};

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

@ -1,21 +0,0 @@
/* XPM */
static char * Hash_xpm[] = {
"16 16 2 1",
" c None",
". c #000000",
" ",
" ",
" ",
" . . ",
" . . ",
" . . ",
" ......... ",
" . . ",
" . . ",
" ......... ",
" . . ",
" . . ",
" . . ",
" ",
" ",
" "};

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

@ -1,73 +0,0 @@
/* XPM */
static char * Key_xpm[] = {
"16 16 54 1",
" c None",
". c #110007",
"+ c #0E0900",
"@ c #000013",
"# c #070600",
"$ c #F6F006",
"% c #ECE711",
"& c #E5EE00",
"* c #16021E",
"= c #120900",
"- c #EDF12B",
"; c #000033",
"> c #0F0000",
", c #FFFE03",
"' c #E6E500",
") c #16021B",
"! c #F7F502",
"~ c #000E00",
"{ c #130000",
"] c #FFF000",
"^ c #FFE711",
"/ c #140005",
"( c #190025",
"_ c #E9DD27",
": c #E7DC04",
"< c #FFEC09",
"[ c #FFE707",
"} c #FFDE10",
"| c #150021",
"1 c #160700",
"2 c #FAF60E",
"3 c #EFE301",
"4 c #FEF300",
"5 c #E7E000",
"6 c #FFFF08",
"7 c #0E0206",
"8 c #040000",
"9 c #03052E",
"0 c #041212",
"a c #070300",
"b c #F2E713",
"c c #F9DE13",
"d c #36091E",
"e c #00001C",
"f c #1F0010",
"g c #FFF500",
"h c #DEDE00",
"i c #050A00",
"j c #FAF14A",
"k c #F5F200",
"l c #040404",
"m c #1A0D00",
"n c #EDE43D",
"o c #ECE007",
" ",
" ",
" .+@ ",
" #$%&* ",
" =-;>,') ",
" >!~{]^/ ",
" (_:<[}| ",
" 1234567 ",
" 890abcd ",
" efghi ",
" >jkl ",
" mnol ",
" >kl ",
" ll ",
" ",
" "};

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

@ -1,21 +0,0 @@
/* XPM */
static char * False_xpm[] = {
"16 16 2 1",
" c None",
". c #000000",
" ",
" ",
" ",
" ... ",
" . . ",
" . . ",
" . . ",
" . . ",
" . . ",
" . . ",
" . . ",
" . . ",
" ... ",
" ",
" ",
" "};

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

@ -1,28 +0,0 @@
/* XPM */
static char * Numeric_xpm[] = {
"16 16 9 1",
" c None",
". c #FF0000",
"+ c #0000FF",
"@ c #0023DB",
"# c #00EA14",
"$ c #00FF00",
"% c #004FAF",
"& c #0028D6",
"* c #00F20C",
" ",
" ",
" ",
" ... +++@#$$$$ ",
" .+ %& $$ ",
" . + $ ",
" . + $$ ",
" . ++$$$$ ",
" . + $$ ",
" . + $ ",
" . + $ ",
" . + $ $$ ",
" .....++++*$$ ",
" ",
" ",
" "};

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

@ -1,96 +0,0 @@
/* XPM */
static char * String_xpm[] = {
"16 16 77 1",
" c None",
". c #000000",
"+ c #040404",
"@ c #080806",
"# c #090606",
"$ c #EEEAE1",
"% c #E7E3DA",
"& c #E0DBD1",
"* c #D4B46F",
"= c #0C0906",
"- c #E3C072",
"; c #E4C072",
"> c #060505",
", c #0B0A08",
"' c #D5B264",
") c #D3AF5A",
"! c #080602",
"~ c #E1B863",
"{ c #DDB151",
"] c #DBAE4A",
"^ c #DDB152",
"/ c #DDB252",
"( c #070705",
"_ c #0C0A07",
": c #D3A33B",
"< c #020201",
"[ c #DAAA41",
"} c #040302",
"| c #E4D9BF",
"1 c #0B0907",
"2 c #030201",
"3 c #020200",
"4 c #C99115",
"5 c #080704",
"6 c #DBC8A2",
"7 c #E7D7B4",
"8 c #E0CD9E",
"9 c #080601",
"0 c #040400",
"a c #010100",
"b c #0B0B08",
"c c #DCBF83",
"d c #DCBC75",
"e c #DEB559",
"f c #040301",
"g c #BC8815",
"h c #120E07",
"i c #060402",
"j c #0A0804",
"k c #D4A747",
"l c #D6A12F",
"m c #0E0C05",
"n c #C8C1B0",
"o c #1D1B15",
"p c #D7AD51",
"q c #070502",
"r c #080804",
"s c #BC953B",
"t c #C4BDAD",
"u c #0B0807",
"v c #DBAC47",
"w c #1B150A",
"x c #B78A2C",
"y c #D8A83C",
"z c #D4A338",
"A c #0F0B03",
"B c #181105",
"C c #C59325",
"D c #C18E1F",
"E c #060600",
"F c #CC992D",
"G c #B98B25",
"H c #B3831F",
"I c #C08C1C",
"J c #060500",
"K c #0E0C03",
"L c #0D0A00",
" ",
" .+@# ",
" .$%&*= ",
" .-;>,')! ",
" .~. .{]. ",
" .^/. (_:< ",
" .[.}|$12 ",
" 345678}90 ",
" a2bcdefgh ",
" ijkl.mno ",
" <pq. rstu ",
" .]v. wx= ",
" .yzABCDE ",
" .FGHIJ ",
" 0KL0 ",
" "};

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

@ -1,21 +0,0 @@
/* XPM */
static char * TrueClass_xpm[] = {
"16 16 2 1",
" c None",
". c #0BF311",
" ",
" ",
" ",
" ......... ",
" . ",
" . ",
" . ",
" . ",
" . ",
" . ",
" . ",
" . ",
" . ",
" ",
" ",
" "};

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

@ -309,6 +309,8 @@ module JSON
end
module ::Kernel
private
# Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
# one line.
def j(*objs)

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,9 +1,8 @@
module JSON
# JSON version
VERSION = '1.1.4'
VERSION = '1.1.8'
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
VARIANT_BINARY = false
end