From 5ca264948a28f13c1611a387fee9130fe0e815ed Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 12 Jul 2009 14:45:43 +0000 Subject: merges r23916 from trunk into ruby_1_9_1. -- * re.c (reg_match_pos): adjust offset based on characters, not bytes. [ruby-dev:38722] * string.c (rb_str_offset): new function. * string.c (rb_str_index_m): no call to rb_reg_adjust_startpos(). git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@24049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 5b73d1b96..5440e3738 100644 --- a/string.c +++ b/string.c @@ -1357,6 +1357,13 @@ str_offset(const char *p, const char *e, int nth, rb_encoding *enc, int singleby return pp - p; } +long +rb_str_offset(VALUE str, long pos) +{ + return str_offset(RSTRING_PTR(str), RSTRING_END(str), pos, + STR_ENC_GET(str), single_byte_optimizable(str)); +} + #ifdef NONASCII_MASK static char * str_utf8_nth(const char *p, const char *e, int nth) @@ -2372,9 +2379,8 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str) switch (TYPE(sub)) { case T_REGEXP: pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos, - rb_enc_check(str, sub), single_byte_optimizable(str)); + rb_enc_check(str, sub), single_byte_optimizable(str)); - pos = rb_reg_adjust_startpos(sub, str, pos, 0); pos = rb_reg_search(sub, str, pos, 0); pos = rb_str_sublen(str, pos); break; @@ -2489,7 +2495,6 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str) STR_ENC_GET(str), single_byte_optimizable(str)); if (!RREGEXP(sub)->ptr || RREGEXP_SRC_LEN(sub)) { - pos = rb_reg_adjust_startpos(sub, str, pos, 1); pos = rb_reg_search(sub, str, pos, 1); pos = rb_str_sublen(str, pos); } -- cgit