Feature #12542 ยป json-2.0.1.patch
| ext/json/generator/generator.c | ||
|---|---|---|
|
static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
|
||
|
i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only,
|
||
|
i_quirks_mode, i_pack, i_unpack, i_create_id, i_extend, i_key_p,
|
||
|
i_pack, i_unpack, i_create_id, i_extend, i_key_p,
|
||
|
i_aref, i_send, i_respond_to_p, i_match, i_keys, i_depth,
|
||
|
i_buffer_initial_length, i_dup;
|
||
| ... | ... | |
|
unicode_escape_to_buffer(buffer, buf, (UTF16)((ch & halfMask) + UNI_SUR_LOW_START));
|
||
|
}
|
||
|
}
|
||
|
RB_GC_GUARD(string);
|
||
|
}
|
||
|
/* Converts string to a JSON string in FBuffer buffer, where only the
|
||
| ... | ... | |
|
state->allow_nan = RTEST(tmp);
|
||
|
tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only));
|
||
|
state->ascii_only = RTEST(tmp);
|
||
|
tmp = rb_hash_aref(opts, ID2SYM(i_quirks_mode));
|
||
|
state->quirks_mode = RTEST(tmp);
|
||
|
return self;
|
||
|
}
|
||
| ... | ... | |
|
rb_hash_aset(result, ID2SYM(i_array_nl), rb_str_new(state->array_nl, state->array_nl_len));
|
||
|
rb_hash_aset(result, ID2SYM(i_allow_nan), state->allow_nan ? Qtrue : Qfalse);
|
||
|
rb_hash_aset(result, ID2SYM(i_ascii_only), state->ascii_only ? Qtrue : Qfalse);
|
||
|
rb_hash_aset(result, ID2SYM(i_quirks_mode), state->quirks_mode ? Qtrue : Qfalse);
|
||
|
rb_hash_aset(result, ID2SYM(i_max_nesting), LONG2FIX(state->max_nesting));
|
||
|
rb_hash_aset(result, ID2SYM(i_depth), LONG2FIX(state->depth));
|
||
|
rb_hash_aset(result, ID2SYM(i_buffer_initial_length), LONG2FIX(state->buffer_initial_length));
|
||
| ... | ... | |
|
generate_json_bignum(buffer, Vstate, state, obj);
|
||
|
}
|
||
|
#endif
|
||
|
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
||
|
{
|
||
|
double value = RFLOAT_VALUE(obj);
|
||
| ... | ... | |
|
}
|
||
|
/*
|
||
|
* This function returns true if string is either a JSON array or JSON object.
|
||
|
* It might suffer from false positives, e. g. syntactically incorrect JSON in
|
||
|
* the string or certain UTF-8 characters on the right hand side.
|
||
|
*/
|
||
|
static int isArrayOrObject(VALUE string)
|
||
|
{
|
||
|
long string_len = RSTRING_LEN(string);
|
||
|
char *p = RSTRING_PTR(string), *q = p + string_len - 1;
|
||
|
if (string_len < 2) return 0;
|
||
|
for (; p < q && isspace((unsigned char)*p); p++);
|
||
|
for (; q > p && isspace((unsigned char)*q); q--);
|
||
|
return (*p == '[' && *q == ']') || (*p == '{' && *q == '}');
|
||
|
}
|
||
|
/*
|
||
|
* call-seq: generate(obj)
|
||
|
*
|
||
|
* Generates a valid JSON document from object +obj+ and returns the
|
||
| ... | ... | |
|
{
|
||
|
VALUE result = cState_partial_generate(self, obj);
|
||
|
GET_STATE(self);
|
||
|
if (!state->quirks_mode && !isArrayOrObject(result)) {
|
||
|
rb_raise(eGeneratorError, "only generation of JSON objects or arrays allowed");
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
| ... | ... | |
|
* * *allow_nan*: true if NaN, Infinity, and -Infinity should be
|
||
|
* generated, otherwise an exception is thrown, if these values are
|
||
|
* encountered. This options defaults to false.
|
||
|
* * *quirks_mode*: Enables quirks_mode for parser, that is for example
|
||
|
* generating single JSON values instead of documents is possible.
|
||
|
* * *buffer_initial_length*: sets the initial length of the generator's
|
||
|
* internal buffer.
|
||
|
*/
|
||
| ... | ... | |
|
}
|
||
|
/*
|
||
|
* call-seq: quirks_mode?
|
||
|
*
|
||
|
* Returns true, if quirks mode is enabled. Otherwise returns false.
|
||
|
*/
|
||
|
static VALUE cState_quirks_mode_p(VALUE self)
|
||
|
{
|
||
|
GET_STATE(self);
|
||
|
return state->quirks_mode ? Qtrue : Qfalse;
|
||
|
}
|
||
|
/*
|
||
|
* call-seq: quirks_mode=(enable)
|
||
|
*
|
||
|
* If set to true, enables the quirks_mode mode.
|
||
|
*/
|
||
|
static VALUE cState_quirks_mode_set(VALUE self, VALUE enable)
|
||
|
{
|
||
|
GET_STATE(self);
|
||
|
state->quirks_mode = RTEST(enable);
|
||
|
return Qnil;
|
||
|
}
|
||
|
/*
|
||
|
* call-seq: depth
|
||
|
*
|
||
|
* This integer returns the current depth of data structure nesting.
|
||
| ... | ... | |
|
rb_define_method(cState, "check_circular?", cState_check_circular_p, 0);
|
||
|
rb_define_method(cState, "allow_nan?", cState_allow_nan_p, 0);
|
||
|
rb_define_method(cState, "ascii_only?", cState_ascii_only_p, 0);
|
||
|
rb_define_method(cState, "quirks_mode?", cState_quirks_mode_p, 0);
|
||
|
rb_define_method(cState, "quirks_mode", cState_quirks_mode_p, 0);
|
||
|
rb_define_method(cState, "quirks_mode=", cState_quirks_mode_set, 1);
|
||
|
rb_define_method(cState, "depth", cState_depth, 0);
|
||
|
rb_define_method(cState, "depth=", cState_depth_set, 1);
|
||
|
rb_define_method(cState, "buffer_initial_length", cState_buffer_initial_length, 0);
|
||
| ... | ... | |
|
i_max_nesting = rb_intern("max_nesting");
|
||
|
i_allow_nan = rb_intern("allow_nan");
|
||
|
i_ascii_only = rb_intern("ascii_only");
|
||
|
i_quirks_mode = rb_intern("quirks_mode");
|
||
|
i_depth = rb_intern("depth");
|
||
|
i_buffer_initial_length = rb_intern("buffer_initial_length");
|
||
|
i_pack = rb_intern("pack");
|
||
| ext/json/generator/generator.h | ||
|---|---|---|
|
long max_nesting;
|
||
|
char allow_nan;
|
||
|
char ascii_only;
|
||
|
char quirks_mode;
|
||
|
long depth;
|
||
|
long buffer_initial_length;
|
||
|
} JSON_Generator_State;
|
||
| ext/json/lib/json/common.rb | ||
|---|---|---|
|
module JSON
|
||
|
class << self
|
||
|
# If _object_ is string-like, parse the string and return the parsed result
|
||
|
# as a Ruby data structure. Otherwise generate a JSON text from the Ruby
|
||
|
# data structure object and return it.
|
||
|
# If _object_ is string-like, parse the string and return the parsed
|
||
|
# result as a Ruby data structure. Otherwise generate a JSON text from the
|
||
|
# Ruby data structure object and return it.
|
||
|
#
|
||
|
# The _opts_ argument is passed through to generate/parse respectively. See
|
||
|
# generate and parse for their documentation.
|
||
|
# The _opts_ argument is passed through to generate/parse respectively.
|
||
|
# See generate and parse for their documentation.
|
||
|
def [](object, opts = {})
|
||
|
if object.respond_to? :to_str
|
||
|
JSON.parse(object.to_str, opts)
|
||
| ... | ... | |
|
# Set the JSON parser class _parser_ to be used by JSON.
|
||
|
def parser=(parser) # :nodoc:
|
||
|
@parser = parser
|
||
|
remove_const :Parser if JSON.const_defined_in?(self, :Parser)
|
||
|
remove_const :Parser if const_defined?(:Parser, false)
|
||
|
const_set :Parser, parser
|
||
|
end
|
||
| ... | ... | |
|
def deep_const_get(path) # :nodoc:
|
||
|
path.to_s.split(/::/).inject(Object) do |p, c|
|
||
|
case
|
||
|
when c.empty? then p
|
||
|
when JSON.const_defined_in?(p, c) then p.const_get(c)
|
||
|
when c.empty? then p
|
||
|
when p.const_defined?(c, true) then p.const_get(c)
|
||
|
else
|
||
|
begin
|
||
|
p.const_missing(c)
|
||
| ... | ... | |
|
# _opts_ can have the following
|
||
|
# keys:
|
||
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
||
|
# structures. Disable depth checking with :max_nesting => false. It defaults
|
||
|
# to 100.
|
||
|
# structures. Disable depth checking with :max_nesting => false. It
|
||
|
# defaults to 100.
|
||
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
||
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
||
|
# defiance of RFC 7159 to be parsed by the Parser. This option defaults
|
||
|
# to false.
|
||
|
# * *symbolize_names*: If set to true, returns symbols for the names
|
||
|
# (keys) in a JSON object. Otherwise strings are returned. Strings are
|
||
| ... | ... | |
|
#
|
||
|
# _opts_ can have the following keys:
|
||
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
||
|
# structures. Enable depth checking with :max_nesting => anInteger. The parse!
|
||
|
# methods defaults to not doing max depth checking: This can be dangerous
|
||
|
# if someone wants to fill up your stack.
|
||
|
# structures. Enable depth checking with :max_nesting => anInteger. The
|
||
|
# parse! methods defaults to not doing max depth checking: This can be
|
||
|
# dangerous if someone wants to fill up your stack.
|
||
|
# * *allow_nan*: If set to true, allow NaN, Infinity, and -Infinity in
|
||
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
||
|
# defiance of RFC 7159 to be parsed by the Parser. This option defaults
|
||
|
# to true.
|
||
|
# * *create_additions*: If set to false, the Parser doesn't create
|
||
|
# additions even if a matching class and create_id was found. This option
|
||
| ... | ... | |
|
opts = {
|
||
|
:max_nesting => false,
|
||
|
:allow_nan => true
|
||
|
}.update(opts)
|
||
|
}.merge(opts)
|
||
|
Parser.new(source, opts).parse
|
||
|
end
|
||
| ... | ... | |
|
# The global default options for the JSON.load method:
|
||
|
# :max_nesting: false
|
||
|
# :allow_nan: true
|
||
|
# :quirks_mode: true
|
||
|
# :allow_blank: true
|
||
|
attr_accessor :load_default_options
|
||
|
end
|
||
|
self.load_default_options = {
|
||
|
:max_nesting => false,
|
||
|
:allow_nan => true,
|
||
|
:quirks_mode => true,
|
||
|
:allow_blank => true,
|
||
|
:create_additions => true,
|
||
|
}
|
||
| ... | ... | |
|
elsif source.respond_to?(:read)
|
||
|
source = source.read
|
||
|
end
|
||
|
if opts[:quirks_mode] && (source.nil? || source.empty?)
|
||
|
if opts[:allow_blank] && (source.nil? || source.empty?)
|
||
|
source = 'null'
|
||
|
end
|
||
|
result = parse(source, opts)
|
||
| ... | ... | |
|
# The global default options for the JSON.dump method:
|
||
|
# :max_nesting: false
|
||
|
# :allow_nan: true
|
||
|
# :quirks_mode: true
|
||
|
# :allow_blank: true
|
||
|
attr_accessor :dump_default_options
|
||
|
end
|
||
|
self.dump_default_options = {
|
||
|
:max_nesting => false,
|
||
|
:allow_nan => true,
|
||
|
:quirks_mode => true,
|
||
|
}
|
||
|
# Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
|
||
| ... | ... | |
|
raise ArgumentError, "exceed depth limit"
|
||
|
end
|
||
|
# Swap consecutive bytes of _string_ in place.
|
||
|
def self.swap!(string) # :nodoc:
|
||
|
0.upto(string.size / 2) do |i|
|
||
|
break unless string[2 * i + 1]
|
||
|
string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
|
||
|
end
|
||
|
string
|
||
|
end
|
||
|
# Shortcut for iconv.
|
||
|
if ::String.method_defined?(:encode)
|
||
|
# Encodes string using Ruby's _String.encode_
|
||
|
def self.iconv(to, from, string)
|
||
|
string.encode(to, from)
|
||
|
end
|
||
|
else
|
||
|
require 'iconv'
|
||
|
# Encodes string using _iconv_ library
|
||
|
def self.iconv(to, from, string)
|
||
|
Iconv.conv(to, from, string)
|
||
|
end
|
||
|
end
|
||
|
if ::Object.method(:const_defined?).arity == 1
|
||
|
def self.const_defined_in?(modul, constant)
|
||
|
modul.const_defined?(constant)
|
||
|
end
|
||
|
else
|
||
|
def self.const_defined_in?(modul, constant)
|
||
|
modul.const_defined?(constant, false)
|
||
|
end
|
||
|
# Encodes string using Ruby's _String.encode_
|
||
|
def self.iconv(to, from, string)
|
||
|
string.encode(to, from)
|
||
|
end
|
||
|
end
|
||
| ext/json/lib/json/ext.rb | ||
|---|---|---|
|
# frozen_string_literal: false
|
||
|
if ENV['SIMPLECOV_COVERAGE'].to_i == 1
|
||
|
require 'simplecov'
|
||
|
SimpleCov.start do
|
||
|
add_filter "/tests/"
|
||
|
end
|
||
|
end
|
||
|
require 'json/common'
|
||
|
module JSON
|
||
| ext/json/lib/json/generic_object.rb | ||
|---|---|---|
|
table
|
||
|
end
|
||
|
def [](name)
|
||
|
__send__(name)
|
||
|
end unless method_defined?(:[])
|
||
|
def []=(name, value)
|
||
|
__send__("#{name}=", value)
|
||
|
end unless method_defined?(:[]=)
|
||
|
def |(other)
|
||
|
self.class[other.to_hash.merge(to_hash)]
|
||
|
end
|
||
| ext/json/lib/json/version.rb | ||
|---|---|---|
|
# frozen_string_literal: false
|
||
|
module JSON
|
||
|
# JSON version
|
||
|
VERSION = '1.8.3'
|
||
|
VERSION = '2.0.1'
|
||
|
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
|
||
|
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
||
|
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
||
| ext/json/parser/parser.c | ||
|---|---|---|
|
#include "parser.h"
|
||
|
#if defined HAVE_RUBY_ENCODING_H
|
||
|
# define EXC_ENCODING UTF_8,
|
||
|
# define EXC_ENCODING rb_utf8_encoding(),
|
||
|
# ifndef HAVE_RB_ENC_RAISE
|
||
|
static void
|
||
|
enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
||
| ... | ... | |
|
return len;
|
||
|
}
|
||
|
#ifdef HAVE_RUBY_ENCODING_H
|
||
|
static rb_encoding *UTF_8, *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
|
||
|
#else
|
||
|
static ID i_iconv;
|
||
|
#endif
|
||
|
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_symbolize_names, i_quirks_mode,
|
||
|
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
|
||
|
i_object_class, i_array_class, i_key_p, i_deep_const_get, i_match,
|
||
|
i_match_string, i_aset, i_aref, i_leftshift;
|
||
|
#line 130 "parser.rl"
|
||
|
#line 124 "parser.rl"
|
||
|
#line 112 "parser.c"
|
||
|
#line 106 "parser.c"
|
||
|
enum {JSON_object_start = 1};
|
||
|
enum {JSON_object_first_final = 27};
|
||
|
enum {JSON_object_error = 0};
|
||
| ... | ... | |
|
enum {JSON_object_en_main = 1};
|
||
|
#line 171 "parser.rl"
|
||
|
#line 165 "parser.rl"
|
||
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
||
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
||
|
{
|
||
|
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 too deep", json->current_nesting);
|
||
|
if (json->max_nesting && current_nesting > json->max_nesting) {
|
||
|
rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
|
||
|
}
|
||
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
||
|
#line 136 "parser.c"
|
||
|
#line 130 "parser.c"
|
||
|
{
|
||
|
cs = JSON_object_start;
|
||
|
}
|
||
|
#line 186 "parser.rl"
|
||
|
#line 180 "parser.rl"
|
||
|
#line 143 "parser.c"
|
||
|
#line 137 "parser.c"
|
||
|
{
|
||
|
if ( p == pe )
|
||
|
goto _test_eof;
|
||
| ... | ... | |
|
goto st2;
|
||
|
goto st0;
|
||
|
tr2:
|
||
|
#line 153 "parser.rl"
|
||
|
#line 147 "parser.rl"
|
||
|
{
|
||
|
char *np;
|
||
|
json->parsing_name = 1;
|
||
| ... | ... | |
|
if ( ++p == pe )
|
||
|
goto _test_eof3;
|
||
|
case 3:
|
||
|
#line 184 "parser.c"
|
||
|
#line 178 "parser.c"
|
||
|
switch( (*p) ) {
|
||
|
case 13: goto st3;
|
||
|
case 32: goto st3;
|
||
| ... | ... | |
|
goto st8;
|
||
|
goto st0;
|
||
|
tr11:
|
||
|
#line 138 "parser.rl"
|
||
|
#line 132 "parser.rl"
|
||
|
{
|
||
|
VALUE v = Qnil;
|
||
|
char *np = JSON_parse_value(json, p, pe, &v);
|
||
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
||
|
if (np == NULL) {
|
||
|
p--; {p++; cs = 9; goto _out;}
|
||
|
} else {
|
||
| ... | ... | |
|
if ( ++p == pe )
|
||
|
goto _test_eof9;
|
||
|
case 9:
|
||
|
#line 271 "parser.c"
|
||
|
#line 265 "parser.c"
|
||
|
switch( (*p) ) {
|
||
|
case 13: goto st9;
|
||
|
case 32: goto st9;
|
||
| ... | ... | |
|
goto st9;
|
||
|
goto st18;
|
||
|
tr4:
|
||
|
#line 161 "parser.rl"
|
||
|
#line 155 "parser.rl"
|
||
|
{ p--; {p++; cs = 27; goto _out;} }
|
||
|
goto st27;
|
||
|
st27:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof27;
|
||
|
case 27:
|
||
|
#line 367 "parser.c"
|
||
|
#line 361 "parser.c"
|
||
|
goto st0;
|
||
|
st19:
|
||
|
if ( ++p == pe )
|
||
| ... | ... | |
|
_out: {}
|
||
|
}
|
||
|
#line 187 "parser.rl"
|
||
|
#line 181 "parser.rl"
|
||
|
if (cs >= JSON_object_first_final) {
|
||
|
if (json->create_additions) {
|
||
| ... | ... | |
|
#line 490 "parser.c"
|
||
|
#line 484 "parser.c"
|
||
|
enum {JSON_value_start = 1};
|
||
|
enum {JSON_value_first_final = 21};
|
||
|
enum {JSON_value_first_final = 29};
|
||
|
enum {JSON_value_error = 0};
|
||
|
enum {JSON_value_en_main = 1};
|
||
|
#line 291 "parser.rl"
|
||
|
#line 281 "parser.rl"
|
||
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
||
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
||
|
{
|
||
|
int cs = EVIL;
|
||
|
#line 506 "parser.c"
|
||
|
#line 500 "parser.c"
|
||
|
{
|
||
|
cs = JSON_value_start;
|
||
|
}
|
||
|
#line 298 "parser.rl"
|
||
|
#line 288 "parser.rl"
|
||
|
#line 513 "parser.c"
|
||
|
#line 507 "parser.c"
|
||
|
{
|
||
|
if ( p == pe )
|
||
|
goto _test_eof;
|
||
|
switch ( cs )
|
||
|
{
|
||
|
st1:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof1;
|
||
|
case 1:
|
||
|
switch( (*p) ) {
|
||
|
case 34: goto tr0;
|
||
|
case 45: goto tr2;
|
||
|
case 73: goto st2;
|
||
|
case 78: goto st9;
|
||
|
case 91: goto tr5;
|
||
|
case 102: goto st11;
|
||
|
case 110: goto st15;
|
||
|
case 116: goto st18;
|
||
|
case 123: goto tr9;
|
||
|
case 13: goto st1;
|
||
|
case 32: goto st1;
|
||
|
case 34: goto tr2;
|
||
|
case 45: goto tr3;
|
||
|
case 47: goto st6;
|
||
|
case 73: goto st10;
|
||
|
case 78: goto st17;
|
||
|
case 91: goto tr7;
|
||
|
case 102: goto st19;
|
||
|
case 110: goto st23;
|
||
|
case 116: goto st26;
|
||
|
case 123: goto tr11;
|
||
|
}
|
||
|
if ( 48 <= (*p) && (*p) <= 57 )
|
||
|
goto tr2;
|
||
|
if ( (*p) > 10 ) {
|
||
|
if ( 48 <= (*p) && (*p) <= 57 )
|
||
|
goto tr3;
|
||
|
} else if ( (*p) >= 9 )
|
||
|
goto st1;
|
||
|
goto st0;
|
||
|
st0:
|
||
|
cs = 0;
|
||
|
goto _out;
|
||
|
tr0:
|
||
|
#line 239 "parser.rl"
|
||
|
tr2:
|
||
|
#line 233 "parser.rl"
|
||
|
{
|
||
|
char *np = JSON_parse_string(json, p, pe, result);
|
||
|
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
||
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
||
|
}
|
||
|
goto st21;
|
||
|
tr2:
|
||
|
#line 244 "parser.rl"
|
||
|
goto st29;
|
||
|
tr3:
|
||
|
#line 238 "parser.rl"
|
||
|
{
|
||
|
char *np;
|
||
|
if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
|
||
|
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
|
||
|
if (json->allow_nan) {
|
||
|
*result = CMinusInfinity;
|
||
|
{p = (( p + 10))-1;}
|
||
|
p--; {p++; cs = 21; goto _out;}
|
||
|
p--; {p++; cs = 29; goto _out;}
|
||
|
} else {
|
||
|
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
||
|
}
|
||
| ... | ... | |
|
if (np != NULL) {p = (( np))-1;}
|
||
|
np = JSON_parse_integer(json, p, pe, result);
|
||
|
if (np != NULL) {p = (( np))-1;}
|
||
|
p--; {p++; cs = 21; goto _out;}
|
||
|
p--; {p++; cs = 29; goto _out;}
|
||
|
}
|
||
|
goto st21;
|
||
|
tr5:
|
||
|
goto st29;
|
||
|
tr7:
|
||
|
#line 256 "parser.rl"
|
||
|
{
|
||
|
char *np;
|
||
|
np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
|
||
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
||
|
}
|
||
|
goto st29;
|
||
|
tr11:
|
||
|
#line 262 "parser.rl"
|
||
|
{
|
||
|
char *np;
|
||
|
json->current_nesting++;
|
||
|
np = JSON_parse_array(json, p, pe, result);
|
||
|
json->current_nesting--;
|
||
|
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
||
|
np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
|
||
|
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
|
||
|
}
|
||
|
goto st21;
|
||
|
tr9:
|
||
|
#line 270 "parser.rl"
|
||
|
{
|
||
|
char *np;
|
||
|
json->current_nesting++;
|
||
|
np = JSON_parse_object(json, p, pe, result);
|
||
|
json->current_nesting--;
|
||
|
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
||
|
}
|
||
|
goto st21;
|
||
|
tr16:
|
||
|
#line 232 "parser.rl"
|
||
|
goto st29;
|
||
|
tr25:
|
||
|
#line 226 "parser.rl"
|
||
|
{
|
||
|
if (json->allow_nan) {
|
||
|
*result = CInfinity;
|
||
| ... | ... | |
|
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
|
||
|
}
|
||
|
}
|
||
|
goto st21;
|
||
|
tr18:
|
||
|
#line 225 "parser.rl"
|
||
|
goto st29;
|
||
|
tr27:
|
||
|
#line 219 "parser.rl"
|
||
|
{
|
||
|
if (json->allow_nan) {
|
||
|
*result = CNaN;
|
||
| ... | ... | |
|
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
|
||
|
}
|
||
|
}
|
||
|
goto st21;
|
||
|
tr22:
|
||
|
#line 219 "parser.rl"
|
||
|
goto st29;
|
||
|
tr31:
|
||
|
#line 213 "parser.rl"
|
||
|
{
|
||
|
*result = Qfalse;
|
||
|
}
|
||
|
goto st21;
|
||
|
tr25:
|
||
|
#line 216 "parser.rl"
|
||
|
goto st29;
|
||
|
tr34:
|
||
|
#line 210 "parser.rl"
|
||
|
{
|
||
|
*result = Qnil;
|
||
|
}
|
||
|
goto st21;
|
||
|
tr28:
|
||
|
#line 222 "parser.rl"
|
||
|
goto st29;
|
||
|
tr37:
|
||
|
#line 216 "parser.rl"
|
||
|
{
|
||
|
*result = Qtrue;
|
||
|
}
|
||
|
goto st21;
|
||
|
st21:
|
||
|
goto st29;
|
||
|
st29:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof21;
|
||
|
case 21:
|
||
|
#line 278 "parser.rl"
|
||
|
{ p--; {p++; cs = 21; goto _out;} }
|
||
|
#line 628 "parser.c"
|
||
|
goto _test_eof29;
|
||
|
case 29:
|
||
|
#line 268 "parser.rl"
|
||
|
{ p--; {p++; cs = 29; goto _out;} }
|
||
|
#line 627 "parser.c"
|
||
|
switch( (*p) ) {
|
||
|
case 13: goto st29;
|
||
|
case 32: goto st29;
|
||
|
case 47: goto st2;
|
||
|
}
|
||
|
if ( 9 <= (*p) && (*p) <= 10 )
|
||
|
goto st29;
|
||
|
goto st0;
|
||
|
st2:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof2;
|
||
|
case 2:
|
||
|
if ( (*p) == 110 )
|
||
|
goto st3;
|
||
|
switch( (*p) ) {
|
||
|
case 42: goto st3;
|
||
|
case 47: goto st5;
|
||
|
}
|
||
|
goto st0;
|
||
|
st3:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof3;
|
||
|
case 3:
|
||
|
if ( (*p) == 42 )
|
||
|
goto st4;
|
||
|
goto st3;
|
||
|
st4:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof4;
|
||
|
case 4:
|
||
|
switch( (*p) ) {
|
||
|
case 42: goto st4;
|
||
|
case 47: goto st29;
|
||
|
}
|
||
|
goto st3;
|
||
|
st5:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof5;
|
||
|
case 5:
|
||
|
if ( (*p) == 10 )
|
||
|
goto st29;
|
||
|
goto st5;
|
||
|
st6:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof6;
|
||
|
case 6:
|
||
|
switch( (*p) ) {
|
||
|
case 42: goto st7;
|
||
|
case 47: goto st9;
|
||
|
}
|
||
|
goto st0;
|
||
|
st7:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof7;
|
||
|
case 7:
|
||
|
if ( (*p) == 42 )
|
||
|
goto st8;
|
||
|
goto st7;
|
||
|
st8:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof8;
|
||
|
case 8:
|
||
|
switch( (*p) ) {
|
||
|
case 42: goto st8;
|
||
|
case 47: goto st1;
|
||
|
}
|
||
|
goto st7;
|
||
|
st9:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof9;
|
||
|
case 9:
|
||
|
if ( (*p) == 10 )
|
||
|
goto st1;
|
||
|
goto st9;
|
||
|
st10:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof10;
|
||
|
case 10:
|
||
|
if ( (*p) == 110 )
|
||
|
goto st11;
|
||
|
goto st0;
|
||
|
st11:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof11;
|
||
|
case 11:
|
||
|
if ( (*p) == 102 )
|
||
|
goto st4;
|
||
|
goto st0;
|
||
|
st4:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof4;
|
||
|
case 4:
|
||
|
if ( (*p) == 105 )
|
||
|
goto st5;
|
||
|
goto st0;
|
||
|
st5:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof5;
|
||
|
case 5:
|
||
|
if ( (*p) == 110 )
|
||
|
goto st6;
|
||
|
goto st0;
|
||
|
st6:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof6;
|
||
|
case 6:
|
||
|
if ( (*p) == 105 )
|
||
|
goto st7;
|
||
|
goto st0;
|
||
|
st7:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof7;
|
||
|
case 7:
|
||
|
if ( (*p) == 116 )
|
||
|
goto st8;
|
||
|
goto st0;
|
||
|
st8:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof8;
|
||
|
case 8:
|
||
|
if ( (*p) == 121 )
|
||
|
goto tr16;
|
||
|
goto st0;
|
||
|
st9:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof9;
|
||
|
case 9:
|
||
|
if ( (*p) == 97 )
|
||
|
goto st10;
|
||
|
goto st0;
|
||
|
st10:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof10;
|
||
|
case 10:
|
||
|
if ( (*p) == 78 )
|
||
|
goto tr18;
|
||
|
goto st0;
|
||
|
st11:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof11;
|
||
|
case 11:
|
||
|
if ( (*p) == 97 )
|
||
|
goto st12;
|
||
|
goto st0;
|
||
|
st12:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof12;
|
||
|
case 12:
|
||
|
if ( (*p) == 108 )
|
||
|
if ( (*p) == 105 )
|
||
|
goto st13;
|
||
|
goto st0;
|
||
|
st13:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof13;
|
||
|
case 13:
|
||
|
if ( (*p) == 115 )
|
||
|
if ( (*p) == 110 )
|
||
|
goto st14;
|
||
|
goto st0;
|
||
|
st14:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof14;
|
||
|
case 14:
|
||
|
if ( (*p) == 101 )
|
||
|
goto tr22;
|
||
|
if ( (*p) == 105 )
|
||
|
goto st15;
|
||
|
goto st0;
|
||
|
st15:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof15;
|
||
|
case 15:
|
||
|
if ( (*p) == 117 )
|
||
|
if ( (*p) == 116 )
|
||
|
goto st16;
|
||
|
goto st0;
|
||
|
st16:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof16;
|
||
|
case 16:
|
||
|
if ( (*p) == 108 )
|
||
|
goto st17;
|
||
|
goto st0;
|
||
|
st17:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof17;
|
||
|
case 17:
|
||
|
if ( (*p) == 108 )
|
||
|
if ( (*p) == 121 )
|
||
|
goto tr25;
|
||
|
goto st0;
|
||
|
st17:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof17;
|
||
|
case 17:
|
||
|
if ( (*p) == 97 )
|
||
|
goto st18;
|
||
|
goto st0;
|
||
|
st18:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof18;
|
||
|
case 18:
|
||
|
if ( (*p) == 114 )
|
||
|
goto st19;
|
||
|
if ( (*p) == 78 )
|
||
|
goto tr27;
|
||
|
goto st0;
|
||
|
st19:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof19;
|
||
|
case 19:
|
||
|
if ( (*p) == 117 )
|
||
|
if ( (*p) == 97 )
|
||
|
goto st20;
|
||
|
goto st0;
|
||
|
st20:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof20;
|
||
|
case 20:
|
||
|
if ( (*p) == 108 )
|
||
|
goto st21;
|
||
|
goto st0;
|
||
|
st21:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof21;
|
||
|
case 21:
|
||
|
if ( (*p) == 115 )
|
||
|
goto st22;
|
||
|
goto st0;
|
||
|
st22:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof22;
|
||
|
case 22:
|
||
|
if ( (*p) == 101 )
|
||
|
goto tr28;
|
||
|
goto tr31;
|
||
|
goto st0;
|
||
|
st23:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof23;
|
||
|
case 23:
|
||
|
if ( (*p) == 117 )
|
||
|
goto st24;
|
||
|
goto st0;
|
||
|
st24:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof24;
|
||
|
case 24:
|
||
|
if ( (*p) == 108 )
|
||
|
goto st25;
|
||
|
goto st0;
|
||
|
st25:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof25;
|
||
|
case 25:
|
||
|
if ( (*p) == 108 )
|
||
|
goto tr34;
|
||
|
goto st0;
|
||
|
st26:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof26;
|
||
|
case 26:
|
||
|
if ( (*p) == 114 )
|
||
|
goto st27;
|
||
|
goto st0;
|
||
|
st27:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof27;
|
||
|
case 27:
|
||
|
if ( (*p) == 117 )
|
||
|
goto st28;
|
||
|
goto st0;
|
||
|
st28:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof28;
|
||
|
case 28:
|
||
|
if ( (*p) == 101 )
|
||
|
goto tr37;
|
||
|
goto st0;
|
||
|
}
|
||
|
_test_eof21: cs = 21; goto _test_eof;
|
||
|
_test_eof1: cs = 1; goto _test_eof;
|
||
|
_test_eof29: cs = 29; goto _test_eof;
|
||
|
_test_eof2: cs = 2; goto _test_eof;
|
||
|
_test_eof3: cs = 3; goto _test_eof;
|
||
|
_test_eof4: cs = 4; goto _test_eof;
|
||
| ... | ... | |
|
_test_eof18: cs = 18; goto _test_eof;
|
||
|
_test_eof19: cs = 19; goto _test_eof;
|
||
|
_test_eof20: cs = 20; goto _test_eof;
|
||
|
_test_eof21: cs = 21; goto _test_eof;
|
||
|
_test_eof22: cs = 22; goto _test_eof;
|
||
|
_test_eof23: cs = 23; goto _test_eof;
|
||
|
_test_eof24: cs = 24; goto _test_eof;
|
||
|
_test_eof25: cs = 25; goto _test_eof;
|
||
|
_test_eof26: cs = 26; goto _test_eof;
|
||
|
_test_eof27: cs = 27; goto _test_eof;
|
||
|
_test_eof28: cs = 28; goto _test_eof;
|
||
|
_test_eof: {}
|
||
|
_out: {}
|
||
|
}
|
||
|
#line 299 "parser.rl"
|
||
|
#line 289 "parser.rl"
|
||
|
if (cs >= JSON_value_first_final) {
|
||
|
return p;
|
||
| ... | ... | |
|
}
|
||
|
#line 799 "parser.c"
|
||
|
#line 878 "parser.c"
|
||
|
enum {JSON_integer_start = 1};
|
||
|
enum {JSON_integer_first_final = 3};
|
||
|
enum {JSON_integer_error = 0};
|
||
| ... | ... | |
|
enum {JSON_integer_en_main = 1};
|
||
|
#line 315 "parser.rl"
|
||
|
#line 305 "parser.rl"
|
||
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
||
| ... | ... | |
|
int cs = EVIL;
|
||
|
#line 815 "parser.c"
|
||
|
#line 894 "parser.c"
|
||
|
{
|
||
|
cs = JSON_integer_start;
|
||
|
}
|
||
|
#line 322 "parser.rl"
|
||
|
json->memo = p;
|
||
|
#line 823 "parser.c"
|
||
|
{
|
||
|
if ( p == pe )
|
||
|
goto _test_eof;
|
||
|
switch ( cs )
|
||
|
{
|
||
|
case 1:
|
||
|
switch( (*p) ) {
|
||
|
case 45: goto st2;
|
||
|
case 48: goto st3;
|
||
|
}
|
||
|
if ( 49 <= (*p) && (*p) <= 57 )
|
||
|
goto st5;
|
||
|
goto st0;
|
||
|
st0:
|
||
|
cs = 0;
|
||
|
goto _out;
|
||
|
st2:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof2;
|
||
|
case 2:
|
||
|
if ( (*p) == 48 )
|
||
|
goto st3;
|
||
|
if ( 49 <= (*p) && (*p) <= 57 )
|
||
|
goto st5;
|
||
|
goto st0;
|
||
|
st3:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof3;
|
||
|
case 3:
|
||
|
if ( 48 <= (*p) && (*p) <= 57 )
|
||
|
goto st0;
|
||
|
goto tr4;
|
||
|
tr4:
|
||
|
#line 312 "parser.rl"
|
||
|
json->memo = p;
|
||
|
#line 902 "parser.c"
|
||
|
{
|
||
|
if ( p == pe )
|
||
|
goto _test_eof;
|
||
|
switch ( cs )
|
||
|
{
|
||
|
case 1:
|
||
|
switch( (*p) ) {
|
||
|
case 45: goto st2;
|
||
|
case 48: goto st3;
|
||
|
}
|
||
|
if ( 49 <= (*p) && (*p) <= 57 )
|
||
|
goto st5;
|
||
|
goto st0;
|
||
|
st0:
|
||
|
cs = 0;
|
||
|
goto _out;
|
||
|
st2:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof2;
|
||
|
case 2:
|
||
|
if ( (*p) == 48 )
|
||
|
goto st3;
|
||
|
if ( 49 <= (*p) && (*p) <= 57 )
|
||
|
goto st5;
|
||
|
goto st0;
|
||
|
st3:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof3;
|
||
|
case 3:
|
||
|
if ( 48 <= (*p) && (*p) <= 57 )
|
||
|
goto st0;
|
||
|
goto tr4;
|
||
|
tr4:
|
||
|
#line 302 "parser.rl"
|
||
|
{ p--; {p++; cs = 4; goto _out;} }
|
||
|
goto st4;
|
||
|
st4:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof4;
|
||
|
case 4:
|
||
|
#line 864 "parser.c"
|
||
|
#line 943 "parser.c"
|
||
|
goto st0;
|
||
|
st5:
|
||
|
if ( ++p == pe )
|
||
| ... | ... | |
|
_out: {}
|
||
|
}
|
||
|
#line 324 "parser.rl"
|
||
|
#line 314 "parser.rl"
|
||
|
if (cs >= JSON_integer_first_final) {
|
||
|
long len = p - json->memo;
|
||
| ... | ... | |
|
}
|
||
|
#line 898 "parser.c"
|
||
|
#line 977 "parser.c"
|
||
|
enum {JSON_float_start = 1};
|
||
|
enum {JSON_float_first_final = 8};
|
||
|
enum {JSON_float_error = 0};
|
||
| ... | ... | |
|
enum {JSON_float_en_main = 1};
|
||
|
#line 349 "parser.rl"
|
||
|
#line 339 "parser.rl"
|
||
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
||
| ... | ... | |
|
int cs = EVIL;
|
||
|
#line 914 "parser.c"
|
||
|
#line 993 "parser.c"
|
||
|
{
|
||
|
cs = JSON_float_start;
|
||
|
}
|
||
|
#line 356 "parser.rl"
|
||
|
#line 346 "parser.rl"
|
||
|
json->memo = p;
|
||
|
#line 922 "parser.c"
|
||
|
#line 1001 "parser.c"
|
||
|
{
|
||
|
if ( p == pe )
|
||
|
goto _test_eof;
|
||
| ... | ... | |
|
goto st0;
|
||
|
goto tr9;
|
||
|
tr9:
|
||
|
#line 343 "parser.rl"
|
||
|
#line 333 "parser.rl"
|
||
|
{ p--; {p++; cs = 9; goto _out;} }
|
||
|
goto st9;
|
||
|
st9:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof9;
|
||
|
case 9:
|
||
|
#line 987 "parser.c"
|
||
|
#line 1066 "parser.c"
|
||
|
goto st0;
|
||
|
st5:
|
||
|
if ( ++p == pe )
|
||
| ... | ... | |
|
_out: {}
|
||
|
}
|
||
|
#line 358 "parser.rl"
|
||
|
#line 348 "parser.rl"
|
||
|
if (cs >= JSON_float_first_final) {
|
||
|
long len = p - json->memo;
|
||
| ... | ... | |
|
#line 1064 "parser.c"
|
||
|
#line 1143 "parser.c"
|
||
|
enum {JSON_array_start = 1};
|
||
|
enum {JSON_array_first_final = 17};
|
||
|
enum {JSON_array_error = 0};
|
||
| ... | ... | |
|
enum {JSON_array_en_main = 1};
|
||
|
#line 401 "parser.rl"
|
||
|
#line 391 "parser.rl"
|
||
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
||
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
|
||
|
{
|
||
|
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 too deep", json->current_nesting);
|
||
|
if (json->max_nesting && current_nesting > json->max_nesting) {
|
||
|
rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
|
||
|
}
|
||
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
||
|
#line 1086 "parser.c"
|
||
|
#line 1165 "parser.c"
|
||
|
{
|
||
|
cs = JSON_array_start;
|
||
|
}
|
||
|
#line 414 "parser.rl"
|
||
|
#line 404 "parser.rl"
|
||
|
#line 1093 "parser.c"
|
||
|
#line 1172 "parser.c"
|
||
|
{
|
||
|
if ( p == pe )
|
||
|
goto _test_eof;
|
||
| ... | ... | |
|
goto st2;
|
||
|
goto st0;
|
||
|
tr2:
|
||
|
#line 378 "parser.rl"
|
||
|
#line 368 "parser.rl"
|
||
|
{
|
||
|
VALUE v = Qnil;
|
||
|
char *np = JSON_parse_value(json, p, pe, &v);
|
||
|
char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
|
||
|
if (np == NULL) {
|
||
|
p--; {p++; cs = 3; goto _out;}
|
||
|
} else {
|
||
| ... | ... | |
|
if ( ++p == pe )
|
||
|
goto _test_eof3;
|
||
|
case 3:
|
||
|
#line 1152 "parser.c"
|
||
|
#line 1231 "parser.c"
|
||
|
switch( (*p) ) {
|
||
|
case 13: goto st3;
|
||
|
case 32: goto st3;
|
||
| ... | ... | |
|
goto st3;
|
||
|
goto st12;
|
||
|
tr4:
|
||
|
#line 393 "parser.rl"
|
||
|
#line 383 "parser.rl"
|
||
|
{ p--; {p++; cs = 17; goto _out;} }
|
||
|
goto st17;
|
||
|
st17:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof17;
|
||
|
case 17:
|
||
|
#line 1259 "parser.c"
|
||
|
#line 1338 "parser.c"
|
||
|
goto st0;
|
||
|
st13:
|
||
|
if ( ++p == pe )
|
||
| ... | ... | |
|
_out: {}
|
||
|
}
|
||
|
#line 415 "parser.rl"
|
||
|
#line 405 "parser.rl"
|
||
|
if(cs >= JSON_array_first_final) {
|
||
|
return p + 1;
|
||
| ... | ... | |
|
}
|
||
|
#line 1396 "parser.c"
|
||
|
#line 1475 "parser.c"
|
||
|
enum {JSON_string_start = 1};
|
||
|
enum {JSON_string_first_final = 8};
|
||
|
enum {JSON_string_error = 0};
|
||
| ... | ... | |
|
enum {JSON_string_en_main = 1};
|
||
|
#line 514 "parser.rl"
|
||
|
#line 504 "parser.rl"
|
||
|
static int
|
||
| ... | ... | |
|
*result = rb_str_buf_new(0);
|
||
|
#line 1426 "parser.c"
|
||
|
#line 1505 "parser.c"
|
||
|
{
|
||
|
cs = JSON_string_start;
|
||
|
}
|
||
|
#line 535 "parser.rl"
|
||
|
#line 525 "parser.rl"
|
||
|
json->memo = p;
|
||
|
#line 1434 "parser.c"
|
||
|
#line 1513 "parser.c"
|
||
|
{
|
||
|
if ( p == pe )
|
||
|
goto _test_eof;
|
||
| ... | ... | |
|
goto st0;
|
||
|
goto st2;
|
||
|
tr2:
|
||
|
#line 500 "parser.rl"
|
||
|
#line 490 "parser.rl"
|
||
|
{
|
||
|
*result = json_string_unescape(*result, json->memo + 1, p);
|
||
|
if (NIL_P(*result)) {
|
||
| ... | ... | |
|
{p = (( p + 1))-1;}
|
||
|
}
|
||
|
}
|
||
|
#line 511 "parser.rl"
|
||
|
#line 501 "parser.rl"
|
||
|
{ p--; {p++; cs = 8; goto _out;} }
|
||
|
goto st8;
|
||
|
st8:
|
||
|
if ( ++p == pe )
|
||
|
goto _test_eof8;
|
||
|
case 8:
|
||
|
#line 1477 "parser.c"
|
||
|
#line 1556 "parser.c"
|
||
|
goto st0;
|
||
|
st3:
|
||
|
if ( ++p == pe )
|
||
| ... | ... | |
|
_out: {}
|
||
|
}
|
||
|
#line 537 "parser.rl"
|
||
|
#line 527 "parser.rl"
|
||
|
if (json->create_additions && RTEST(match_string = json->match_string)) {
|
||
|
VALUE klass;
|
||
| ... | ... | |
|
if (json->symbolize_names && json->parsing_name) {
|
||
|
*result = rb_str_intern(*result);
|
||
|
} else {
|
||
|
rb_str_resize(*result, RSTRING_LEN(*result));
|
||
|
}
|
||
|
if (cs >= JSON_string_first_final) {
|
||
|
return p + 1;
|
||
| ... | ... | |
|
static VALUE convert_encoding(VALUE source)
|
||
|
{
|
||
|
const char *ptr = RSTRING_PTR(source);
|
||
|
long len = RSTRING_LEN(source);
|
||
|
if (len < 2) {
|
||
|
rb_raise(eParserError, "A JSON text must at least contain two octets!");
|
||
|
}
|
||
|
#ifdef HAVE_RUBY_ENCODING_H
|
||
|
{
|
||
|
rb_encoding *enc = rb_enc_get(source);
|
||
|
if (enc == rb_ascii8bit_encoding()) {
|
||
|
if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
|
||
|
source = rb_str_conv_enc(source, UTF_32BE, rb_utf8_encoding());
|
||
|
} else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
|
||
|
source = rb_str_conv_enc(source, UTF_16BE, rb_utf8_encoding());
|
||
|
} else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
|
||
|
source = rb_str_conv_enc(source, UTF_32LE, rb_utf8_encoding());
|
||
|
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
|
||
|
source = rb_str_conv_enc(source, UTF_16LE, rb_utf8_encoding());
|
||
|
} else {
|
||
|
source = rb_str_dup(source);
|
||
|
FORCE_UTF8(source);
|
||
|
}
|
||
|
} else {
|
||
|
source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
|
||
|
}
|
||
|
}
|
||
|
#else
|
||
|
if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
|
||
|
source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32be"), source);
|
||
|
} else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
|
||
|
source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16be"), source);
|
||
|
} else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
|
||
|
source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32le"), source);
|
||
|
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
|
||
|
source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16le"), source);
|
||
|
}
|
||
|
rb_encoding *enc = rb_enc_get(source);
|
||
|
if (enc == rb_ascii8bit_encoding()) {
|
||
|
FORCE_UTF8(source);
|
||
|
} else {
|
||
|
source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
|
||
|
}
|
||
|
#endif
|
||
|
return source;
|
||
|
}
|
||
| ... | ... | |
|
* defiance of RFC 4627 to be parsed by the Parser. This option defaults to
|
||
|
* false.
|
||
|
* * *symbolize_names*: If set to true, returns symbols for the names
|
||
|
* (keys) in a JSON object. Otherwise strings are returned, which is also
|
||
|
* the default.
|
||
|
* (keys) in a JSON object. Otherwise strings are returned, which is
|
||
|
* also the default. It's not possible to use this option in
|
||
|
* conjunction with the *create_additions* option.
|
||
|
* * *create_additions*: If set to false, the Parser doesn't create
|
||
|
* additions even if a matching class and create_id was found. This option
|
||
|
* defaults to false.
|
||
| ... | ... | |
|
} else {
|
||
|
json->symbolize_names = 0;
|
||
|
}
|
||
|
tmp = ID2SYM(i_quirks_mode);
|
||
|
if (option_given_p(opts, tmp)) {
|
||
|
VALUE quirks_mode = rb_hash_aref(opts, tmp);
|
||
|
json->quirks_mode = RTEST(quirks_mode) ? 1 : 0;
|
||
|
} else {
|
||
|
json->quirks_mode = 0;
|
||
|
}
|
||
|
tmp = ID2SYM(i_create_additions);
|
||
|
if (option_given_p(opts, tmp)) {
|
||
|
json->create_additions = RTEST(rb_hash_aref(opts, tmp));
|
||
|
} else {
|
||
|
json->create_additions = 0;
|
||
|
}
|
||
|
if (json->symbolize_names && json->create_additions) {
|
||
|
rb_raise(rb_eArgError,
|
||
|
"options :symbolize_names and :create_additions cannot be "
|
||
|
" used in conjunction");
|
||
|
}
|
||
|
tmp = ID2SYM(i_create_id);
|
||
|
if (option_given_p(opts, tmp)) {
|
||
|
json->create_id = rb_hash_aref(opts, tmp);
|
||
| ... | ... | |
|
json->object_class = Qnil;
|
||
|
json->array_class = Qnil;
|
||
|
}
|
||
|
source = convert_encoding(StringValue(source));
|
||
|
StringValue(source);
|
||
|
if (!json->quirks_mode) {
|
||
|
source = convert_encoding(source);
|
||
|
}
|
||
|
json->current_nesting = 0;
|
||
|
json->len = RSTRING_LEN(source);
|
||
|
json->source = RSTRING_PTR(source);;
|
||
|
json->Vsource = source;
|
||
| ... | ... | |
|
}
|
||
|
#line 1760 "parser.c"
|
||
|
#line 1809 "parser.c"
|
||
|
enum {JSON_start = 1};
|
||
|
enum {JSON_first_final = 10};
|
||
|
enum {JSON_error = 0};
|
||
| ... | ... | |
|
enum {JSON_en_main = 1};
|
||