diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index a16d068f..c125f82c 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -79,7 +79,7 @@ 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_object_class, - i_array_class, i_key_p, i_deep_const_get, i_match; + i_array_class, i_key_p, i_deep_const_get, i_match, i_match_string; #line 108 "parser.rl" @@ -1376,7 +1376,7 @@ match_i(VALUE regexp, VALUE klass, VALUE memo) static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; - VALUE match; + VALUE match_string; *result = rb_str_buf_new(0); @@ -1509,11 +1509,11 @@ case 7: #line 494 "parser.rl" - if (json->create_additions && RTEST(match = json->match)) { + if (json->create_additions && RTEST(match_string = json->match_string)) { VALUE klass; VALUE memo = rb_ary_new2(2); rb_ary_push(memo, *result); - rb_hash_foreach(match, match_i, memo); + rb_hash_foreach(match_string, match_i, memo); klass = rb_ary_entry(memo, 1); if (RTEST(klass)) { *result = rb_funcall(klass, i_json_create, 1, *result); @@ -1692,12 +1692,12 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } else { json->array_class = Qnil; } - tmp = ID2SYM(i_match); + tmp = ID2SYM(i_match_string); if (option_given_p(opts, tmp)) { - VALUE match = rb_hash_aref(opts, tmp); - json->match = RTEST(match) ? match : Qnil; + VALUE match_string = rb_hash_aref(opts, tmp); + json->match_string = RTEST(match_string) ? match_string : Qnil; } else { - json->match = Qnil; + json->match_string = Qnil; } } } else { @@ -1895,7 +1895,7 @@ static void JSON_mark(JSON_Parser *json) rb_gc_mark_maybe(json->create_id); rb_gc_mark_maybe(json->object_class); rb_gc_mark_maybe(json->array_class); - rb_gc_mark_maybe(json->match); + rb_gc_mark_maybe(json->match_string); } static void JSON_free(JSON_Parser *json) @@ -1949,6 +1949,7 @@ void Init_parser() i_object_class = rb_intern("object_class"); i_array_class = rb_intern("array_class"); i_match = rb_intern("match"); + i_match_string = rb_intern("match_string"); i_key_p = rb_intern("key?"); i_deep_const_get = rb_intern("deep_const_get"); #ifdef HAVE_RUBY_ENCODING_H diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h index 877ef670..ed48035d 100644 --- a/ext/json/ext/parser/parser.h +++ b/ext/json/ext/parser/parser.h @@ -47,7 +47,7 @@ typedef struct JSON_ParserStruct { VALUE object_class; VALUE array_class; int create_additions; - VALUE match; + VALUE match_string; } JSON_Parser; #define GET_PARSER \ diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index 53f1dbeb..58626987 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -77,7 +77,7 @@ 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_object_class, - i_array_class, i_key_p, i_deep_const_get, i_match; + i_array_class, i_key_p, i_deep_const_get, i_match, i_match_string; %%{ machine JSON_common; @@ -485,18 +485,18 @@ match_i(VALUE regexp, VALUE klass, VALUE memo) static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; - VALUE match; + VALUE match_string; *result = rb_str_buf_new(0); %% write init; json->memo = p; %% write exec; - if (json->create_additions && RTEST(match = json->match)) { + if (json->create_additions && RTEST(match_string = json->match_string)) { VALUE klass; VALUE memo = rb_ary_new2(2); rb_ary_push(memo, *result); - rb_hash_foreach(match, match_i, memo); + rb_hash_foreach(match_string, match_i, memo); klass = rb_ary_entry(memo, 1); if (RTEST(klass)) { *result = rb_funcall(klass, i_json_create, 1, *result); @@ -690,12 +690,12 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } else { json->array_class = Qnil; } - tmp = ID2SYM(i_match); + tmp = ID2SYM(i_match_string); if (option_given_p(opts, tmp)) { - VALUE match = rb_hash_aref(opts, tmp); - json->match = RTEST(match) ? match : Qnil; + VALUE match_string = rb_hash_aref(opts, tmp); + json->match_string = RTEST(match_string) ? match_string : Qnil; } else { - json->match = Qnil; + json->match_string = Qnil; } } } else { @@ -752,7 +752,7 @@ static void JSON_mark(JSON_Parser *json) rb_gc_mark_maybe(json->create_id); rb_gc_mark_maybe(json->object_class); rb_gc_mark_maybe(json->array_class); - rb_gc_mark_maybe(json->match); + rb_gc_mark_maybe(json->match_string); } static void JSON_free(JSON_Parser *json) @@ -806,6 +806,7 @@ void Init_parser() i_object_class = rb_intern("object_class"); i_array_class = rb_intern("array_class"); i_match = rb_intern("match"); + i_match_string = rb_intern("match_string"); i_key_p = rb_intern("key?"); i_deep_const_get = rb_intern("deep_const_get"); #ifdef HAVE_RUBY_ENCODING_H diff --git a/java/src/json/ext/Parser.java b/java/src/json/ext/Parser.java index f6e9c4ea..c92600e9 100644 --- a/java/src/json/ext/Parser.java +++ b/java/src/json/ext/Parser.java @@ -53,7 +53,7 @@ public class Parser extends RubyObject { private boolean symbolizeNames; private RubyClass objectClass; private RubyClass arrayClass; - private RubyHash match; + private RubyHash match_string; private static final int DEFAULT_MAX_NESTING = 19; @@ -155,7 +155,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) { this.createAdditions = opts.getBool("create_additions", true); this.objectClass = opts.getClass("object_class", runtime.getHash()); this.arrayClass = opts.getClass("array_class", runtime.getArray()); - this.match = opts.getHash("match"); + this.match_string = opts.getHash("match_string"); this.vSource = source; return this; @@ -1383,11 +1383,11 @@ else if ( data[p] > _JSON_string_trans_keys[_mid+1] ) // line 554 "Parser.rl" if (parser.createAdditions) { - RubyHash match = parser.match; - if (match != null) { + RubyHash match_string = parser.match_string; + if (match_string != null) { final IRubyObject[] memoArray = { result, null }; try { - match.visitAll(new RubyHash.Visitor() { + match_string.visitAll(new RubyHash.Visitor() { @Override public void visit(IRubyObject pattern, IRubyObject klass) { if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) { diff --git a/java/src/json/ext/Parser.rl b/java/src/json/ext/Parser.rl index a79ead55..e576b979 100644 --- a/java/src/json/ext/Parser.rl +++ b/java/src/json/ext/Parser.rl @@ -51,7 +51,7 @@ public class Parser extends RubyObject { private boolean symbolizeNames; private RubyClass objectClass; private RubyClass arrayClass; - private RubyHash match; + private RubyHash match_string; private static final int DEFAULT_MAX_NESTING = 19; @@ -153,7 +153,7 @@ public class Parser extends RubyObject { this.createAdditions = opts.getBool("create_additions", true); this.objectClass = opts.getClass("object_class", runtime.getHash()); this.arrayClass = opts.getClass("array_class", runtime.getArray()); - this.match = opts.getHash("match"); + this.match_string = opts.getHash("match_string"); this.vSource = source; return this; @@ -553,11 +553,11 @@ public class Parser extends RubyObject { %% write exec; if (parser.createAdditions) { - RubyHash match = parser.match; - if (match != null) { + RubyHash match_string = parser.match_string; + if (match_string != null) { final IRubyObject[] memoArray = { result, null }; try { - match.visitAll(new RubyHash.Visitor() { + match_string.visitAll(new RubyHash.Visitor() { @Override public void visit(IRubyObject pattern, IRubyObject klass) { if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) { diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index 6a0192c7..8043e675 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -119,7 +119,7 @@ def initialize(source, opts = {}) @create_id = opts[:create_id] || JSON.create_id @object_class = opts[:object_class] || Hash @array_class = opts[:array_class] || Array - @json_match = opts[:match] # @match is an ivar in rbx's strscan + @match_string = opts[:match_string] end alias source string @@ -189,8 +189,8 @@ def parse_string if string.respond_to?(:force_encoding) string.force_encoding(::Encoding::UTF_8) end - if @create_additions and @json_match - for (regexp, klass) in @json_match + if @create_additions and @match_string + for (regexp, klass) in @match_string klass.json_creatable? or next string =~ regexp and return klass.json_create(string) end diff --git a/tests/test_json_string_matching.rb b/tests/test_json_string_matching.rb index 6bd74e32..df26a68a 100644 --- a/tests/test_json_string_matching.rb +++ b/tests/test_json_string_matching.rb @@ -28,13 +28,13 @@ def test_match_date t_json = [ t ].to_json assert_equal [ t ], JSON.parse(t_json, - :match => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime }) + :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime }) assert_equal [ t.strftime('%FT%T%z') ], JSON.parse(t_json, - :match => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime }) + :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime }) assert_equal [ t.strftime('%FT%T%z') ], JSON.parse(t_json, - :match => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime }, + :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime }, :create_additions => false) end end