From 7fc16c237724a5f4377cea47e3434f53d42af5f4 Mon Sep 17 00:00:00 2001 From: naruse Date: Fri, 29 Aug 2008 02:20:23 +0000 Subject: * encoding.c (rb_enc_compatible): ASCII compatible string and US-ASCII regexp is compatible. [ruby-dev:36033] * string.c (rb_str_index_m): second argument is position of character. by usa. [ruby-dev:36033] * string.c (rb_str_rindex_m): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18916 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ encoding.c | 6 +++++- string.c | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2e268b8d81..82f993bbc4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Aug 29 11:04:03 2008 NARUSE, Yui + + * encoding.c (rb_enc_compatible): ASCII compatible string and US-ASCII + regexp is compatible. [ruby-dev:36033] + + * string.c (rb_str_index_m): second argument is position of character. + by usa. [ruby-dev:36033] + + * string.c (rb_str_rindex_m): ditto. + Fri Aug 29 04:47:49 2008 NAKAMURA Usaku * win32/win32.c (rb_w32_read, rb_w32_write): more accurate handling diff --git a/encoding.c b/encoding.c index 5e8412a026..291070dd19 100644 --- a/encoding.c +++ b/encoding.c @@ -631,6 +631,10 @@ rb_enc_compatible(VALUE str1, VALUE str2) if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2)) { return 0; } + if (BUILTIN_TYPE(str2) == T_REGEXP && idx2 == ENCINDEX_US_ASCII) + return enc1; + if (BUILTIN_TYPE(str1) == T_REGEXP && idx1 == ENCINDEX_US_ASCII) + return enc2; if (BUILTIN_TYPE(str1) != T_STRING) { VALUE tmp = str1; @@ -652,7 +656,7 @@ rb_enc_compatible(VALUE str1, VALUE str2) if (cr2 == ENC_CODERANGE_7BIT) return enc1; } if (cr2 == ENC_CODERANGE_7BIT) { - if (idx1 == 0) return enc2; + if (idx1 == ENCINDEX_ASCII) return enc2; return enc1; } } diff --git a/string.c b/string.c index 26b57b5e3b..180d869acd 100644 --- a/string.c +++ b/string.c @@ -2167,6 +2167,9 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str) } } + pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos, + rb_enc_check(str, sub), single_byte_optimizable(str)); + switch (TYPE(sub)) { case T_REGEXP: pos = rb_reg_adjust_startpos(sub, str, pos, 0); @@ -2277,6 +2280,9 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str) pos = len; } + pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos, + rb_enc_check(str, sub), single_byte_optimizable(str)); + switch (TYPE(sub)) { case T_REGEXP: /* enc = rb_get_check(str, sub); */ -- cgit v1.2.3