* string.c (rb_str_match_m): String#match should also take
optional argument. [ruby-core:03205] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eabd490119
commit
83fa0928d7
@ -1,5 +1,8 @@
|
|||||||
Sat Jul 17 14:18:11 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Sat Jul 17 14:18:11 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_match_m): String#match should also take
|
||||||
|
optional argument. [ruby-core:03205]
|
||||||
|
|
||||||
* re.c (rb_reg_match_m): add optional second argugment "pos" to
|
* re.c (rb_reg_match_m): add optional second argugment "pos" to
|
||||||
specify match start point. [ruby-core:03203]
|
specify match start point. [ruby-core:03203]
|
||||||
|
|
||||||
|
4
re.c
4
re.c
@ -1496,6 +1496,10 @@ rb_reg_match_pos(re, str, pos)
|
|||||||
VALUE re, str;
|
VALUE re, str;
|
||||||
long pos;
|
long pos;
|
||||||
{
|
{
|
||||||
|
if (NIL_P(str)) {
|
||||||
|
rb_backref_set(Qnil);
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
StringValue(str);
|
StringValue(str);
|
||||||
if (pos != 0) {
|
if (pos != 0) {
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
|
19
string.c
19
string.c
@ -1266,7 +1266,9 @@ static VALUE get_pat _((VALUE, int));
|
|||||||
* str.match(pattern) => matchdata or nil
|
* str.match(pattern) => matchdata or nil
|
||||||
*
|
*
|
||||||
* Converts <i>pattern</i> to a <code>Regexp</code> (if it isn't already one),
|
* Converts <i>pattern</i> to a <code>Regexp</code> (if it isn't already one),
|
||||||
* then invokes its <code>match</code> method on <i>str</i>.
|
* then invokes its <code>match</code> method on <i>str</i>. If the second
|
||||||
|
* parameter is present, it specifies the position in the string to begin the
|
||||||
|
* search.
|
||||||
*
|
*
|
||||||
* 'hello'.match('(.)\1') #=> #<MatchData:0x401b3d30>
|
* 'hello'.match('(.)\1') #=> #<MatchData:0x401b3d30>
|
||||||
* 'hello'.match('(.)\1')[0] #=> "ll"
|
* 'hello'.match('(.)\1')[0] #=> "ll"
|
||||||
@ -1275,10 +1277,17 @@ static VALUE get_pat _((VALUE, int));
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_str_match_m(str, re)
|
rb_str_match_m(argc, argv, str)
|
||||||
VALUE str, re;
|
int argc;
|
||||||
|
VALUE *argv;
|
||||||
|
VALUE str;
|
||||||
{
|
{
|
||||||
return rb_funcall(get_pat(re, 0), rb_intern("match"), 1, str);
|
VALUE re;
|
||||||
|
if (argc < 1)
|
||||||
|
rb_raise(rb_eArgError, "wrong number of arguments(%d for 1)", argc);
|
||||||
|
re = argv[0];
|
||||||
|
argv[0] = str;
|
||||||
|
return rb_funcall2(get_pat(re, 0), rb_intern("match"), argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char
|
static char
|
||||||
@ -4573,7 +4582,7 @@ Init_String()
|
|||||||
rb_define_method(rb_cString, "size", rb_str_length, 0);
|
rb_define_method(rb_cString, "size", rb_str_length, 0);
|
||||||
rb_define_method(rb_cString, "empty?", rb_str_empty, 0);
|
rb_define_method(rb_cString, "empty?", rb_str_empty, 0);
|
||||||
rb_define_method(rb_cString, "=~", rb_str_match, 1);
|
rb_define_method(rb_cString, "=~", rb_str_match, 1);
|
||||||
rb_define_method(rb_cString, "match", rb_str_match_m, 1);
|
rb_define_method(rb_cString, "match", rb_str_match_m, -1);
|
||||||
rb_define_method(rb_cString, "succ", rb_str_succ, 0);
|
rb_define_method(rb_cString, "succ", rb_str_succ, 0);
|
||||||
rb_define_method(rb_cString, "succ!", rb_str_succ_bang, 0);
|
rb_define_method(rb_cString, "succ!", rb_str_succ_bang, 0);
|
||||||
rb_define_method(rb_cString, "next", rb_str_succ, 0);
|
rb_define_method(rb_cString, "next", rb_str_succ, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user