Skip to content

Commit

Permalink
added #names and #names_captures (atm returning empty collections)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@3913 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Apr 7, 2010
1 parent 808aec5 commit 18ef85a
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions re.cpp
Expand Up @@ -1082,6 +1082,58 @@ regexp_fixed_encoding(VALUE rcv, SEL sel)
return RREGEXP(rcv)->fixed_encoding ? Qtrue : Qfalse;
}

/*
* call-seq:
* rxp.names => [name1, name2, ...]
*
* Returns a list of names of captures as an array of strings.
*
* /(?<foo>.)(?<bar>.)(?<baz>.)/.names
* #=> ["foo", "bar", "baz"]
*
* /(?<foo>.)(?<foo>.)/.names
* #=> ["foo"]
*
* /(.)(.)/.names
* #=> []
*/

static VALUE
regexp_names(VALUE rcv, SEL sel)
{
// TODO
return rb_ary_new();
}

/*
* call-seq:
* rxp.named_captures => hash
*
* Returns a hash representing information about named captures of <i>rxp</i>.
*
* A key of the hash is a name of the named captures.
* A value of the hash is an array which is list of indexes of corresponding
* named captures.
*
* /(?<foo>.)(?<bar>.)/.named_captures
* #=> {"foo"=>[1], "bar"=>[2]}
*
* /(?<foo>.)(?<foo>.)/.named_captures
* #=> {"foo"=>[1, 2]}
*
* If there are no named captures, an empty hash is returned.
*
* /(.)(.)/.named_captures
* #=> {}
*/

static VALUE
regexp_named_captures(VALUE rcv, SEL sel)
{
// TODO
return rb_hash_new();
}

static VALUE
match_getter(void)
{
Expand Down Expand Up @@ -1218,10 +1270,10 @@ Init_Regexp(void)
(void *)regexp_fixed_encoding, 0);
#if 0
rb_objc_define_method(rb_cRegexp, "encoding", rb_reg_encoding, 0);
rb_objc_define_method(rb_cRegexp, "names", rb_reg_names, 0);
rb_objc_define_method(rb_cRegexp, "named_captures",
rb_reg_named_captures, 0);
#endif
rb_objc_define_method(rb_cRegexp, "names", (void *)regexp_names, 0);
rb_objc_define_method(rb_cRegexp, "named_captures",
(void *)regexp_named_captures, 0);
rb_objc_define_method(rb_cRegexp, "to_s", (void *)regexp_to_s, 0);
rb_objc_define_method(rb_cRegexp, "inspect", (void *)regexp_inspect, 0);

Expand Down

0 comments on commit 18ef85a

Please sign in to comment.