Skip to content

Commit

Permalink
renamed :match argument to :match_string
Browse files Browse the repository at this point in the history
  • Loading branch information
flori committed Jan 4, 2011
1 parent c87f6f3 commit 0b15820
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
19 changes: 10 additions & 9 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/json/ext/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
19 changes: 10 additions & 9 deletions ext/json/ext/parser/parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions java/src/json/ext/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
10 changes: 5 additions & 5 deletions java/src/json/ext/Parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/json/pure/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_json_string_matching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 comment on commit 0b15820

@parndt
Copy link

@parndt parndt commented on 0b15820 Jan 14, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Florian, for all the hard work you put in.

What is the requirement for a 1.4.7 (aka minor point) release? :-)
Some large libraries are using git source for your repository to fix a couple of issues in 1.4.6 e.g. loud constant warnings.

Thanks again.

Please sign in to comment.