зеркало из https://github.com/github/ruby.git
* string.c (rb_str_rindex_m): accept string-like object convertible
with #to_str method, as well as rb_str_index_m. [ruby-core:11692] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c2b34e34cb
Коммит
6c12b69fda
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Jul 16 18:29:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_rindex_m): accept string-like object convertible
|
||||||
|
with #to_str method, as well as rb_str_index_m. [ruby-core:11692]
|
||||||
|
|
||||||
Mon Jul 16 07:17:28 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Jul 16 07:17:28 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* insns.def (getspecial): lfp_svar_get() requires int for special
|
* insns.def (getspecial): lfp_svar_get() requires int for special
|
||||||
|
|
24
string.c
24
string.c
|
@ -1238,8 +1238,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
|
||||||
pos = rb_reg_search(sub, str, pos, 0);
|
pos = rb_reg_search(sub, str, pos, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_FIXNUM:
|
case T_FIXNUM: {
|
||||||
{
|
|
||||||
int c = FIX2INT(sub);
|
int c = FIX2INT(sub);
|
||||||
long len = RSTRING_LEN(str);
|
long len = RSTRING_LEN(str);
|
||||||
char *p = RSTRING_PTR(str);
|
char *p = RSTRING_PTR(str);
|
||||||
|
@ -1351,13 +1350,23 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
|
||||||
if (pos >= 0) return LONG2NUM(pos);
|
if (pos >= 0) return LONG2NUM(pos);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default: {
|
||||||
|
VALUE tmp;
|
||||||
|
|
||||||
|
tmp = rb_check_string_type(sub);
|
||||||
|
if (NIL_P(tmp)) {
|
||||||
|
rb_raise(rb_eTypeError, "type mismatch: %s given",
|
||||||
|
rb_obj_classname(sub));
|
||||||
|
}
|
||||||
|
sub = tmp;
|
||||||
|
}
|
||||||
|
/* fall through */
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
pos = rb_str_rindex(str, sub, pos);
|
pos = rb_str_rindex(str, sub, pos);
|
||||||
if (pos >= 0) return LONG2NUM(pos);
|
if (pos >= 0) return LONG2NUM(pos);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_FIXNUM:
|
case T_FIXNUM: {
|
||||||
{
|
|
||||||
int c = FIX2INT(sub);
|
int c = FIX2INT(sub);
|
||||||
char *p = RSTRING_PTR(str) + pos;
|
char *p = RSTRING_PTR(str) + pos;
|
||||||
char *pbeg = RSTRING_PTR(str);
|
char *pbeg = RSTRING_PTR(str);
|
||||||
|
@ -1373,10 +1382,6 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
|
||||||
rb_raise(rb_eTypeError, "type mismatch: %s given",
|
|
||||||
rb_obj_classname(sub));
|
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -4223,7 +4228,7 @@ rb_str_crypt(VALUE str, VALUE salt)
|
||||||
VALUE
|
VALUE
|
||||||
rb_str_intern(VALUE s)
|
rb_str_intern(VALUE s)
|
||||||
{
|
{
|
||||||
volatile VALUE str = s;
|
VALUE str = RB_GC_GUARD(s);
|
||||||
ID id;
|
ID id;
|
||||||
|
|
||||||
if (OBJ_TAINTED(str) && rb_safe_level() >= 1) {
|
if (OBJ_TAINTED(str) && rb_safe_level() >= 1) {
|
||||||
|
@ -4860,6 +4865,7 @@ rb_to_id(VALUE name)
|
||||||
RSTRING_PTR(rb_inspect(name)));
|
RSTRING_PTR(rb_inspect(name)));
|
||||||
}
|
}
|
||||||
name = tmp;
|
name = tmp;
|
||||||
|
/* fall through */
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
name = rb_str_intern(name);
|
name = rb_str_intern(name);
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче