mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* re.c (match_inspect): backported from 1.9.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3be6ebc5ce
commit
425bd14e23
2 changed files with 54 additions and 1 deletions
|
|
@ -1,3 +1,7 @@
|
|||
Tue Apr 15 20:32:03 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* re.c (match_inspect): backported from 1.9.
|
||||
|
||||
Tue Apr 15 19:03:28 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
||||
|
||||
* eval.c (method_receiver, method_name, method_owner): New
|
||||
|
|
|
|||
51
re.c
51
re.c
|
|
@ -1279,6 +1279,55 @@ match_string(match)
|
|||
return RMATCH(match)->str; /* str is frozen */
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* mtch.inspect => str
|
||||
*
|
||||
* Returns a printable version of <i>mtch</i>.
|
||||
*
|
||||
* puts /.$/.match("foo").inspect
|
||||
* #=> #<MatchData "o">
|
||||
*
|
||||
* puts /(.)(.)(.)/.match("foo").inspect
|
||||
* #=> #<MatchData "foo" 1:"f" 2:"o" 3:"o">
|
||||
*
|
||||
* puts /(.)(.)?(.)/.match("fo").inspect
|
||||
* #=> #<MatchData "fo" 1:"f" 2:nil 3:"o">
|
||||
*
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
match_inspect(VALUE match)
|
||||
{
|
||||
char *cname = rb_obj_classname(match);
|
||||
VALUE str;
|
||||
int i;
|
||||
struct re_registers *regs = RMATCH(match)->regs;
|
||||
int num_regs = regs->num_regs;
|
||||
|
||||
str = rb_str_buf_new2("#<");
|
||||
rb_str_buf_cat2(str, cname);
|
||||
|
||||
for (i = 0; i < num_regs; i++) {
|
||||
VALUE v;
|
||||
rb_str_buf_cat2(str, " ");
|
||||
if (0 < i) {
|
||||
char buf[sizeof(i)*3+1];
|
||||
snprintf(buf, sizeof(buf), "%d", i);
|
||||
rb_str_buf_cat2(str, buf);
|
||||
rb_str_buf_cat2(str, ":");
|
||||
}
|
||||
v = rb_reg_nth_match(i, match);
|
||||
if (v == Qnil)
|
||||
rb_str_buf_cat2(str, "nil");
|
||||
else
|
||||
rb_str_buf_append(str, rb_str_inspect(v));
|
||||
}
|
||||
rb_str_buf_cat2(str, ">");
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
VALUE rb_cRegexp;
|
||||
|
||||
static void
|
||||
|
|
@ -2280,6 +2329,6 @@ Init_Regexp()
|
|||
rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
|
||||
rb_define_method(rb_cMatch, "post_match", rb_reg_match_post, 0);
|
||||
rb_define_method(rb_cMatch, "to_s", match_to_s, 0);
|
||||
rb_define_method(rb_cMatch, "inspect", rb_any_to_s, 0); /* in object.c */
|
||||
rb_define_method(rb_cMatch, "inspect", match_inspect, 0);
|
||||
rb_define_method(rb_cMatch, "string", match_string, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue