зеркало из https://github.com/github/ruby.git
* re.c (rb_reg_quote): return US-ASCII string consistently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
35cb0f807b
Коммит
0f4199fb56
|
@ -1,3 +1,7 @@
|
|||
Sun Feb 17 10:59:04 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* re.c (rb_reg_quote): return US-ASCII string consistently.
|
||||
|
||||
Sun Feb 17 09:17:08 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* string.c (rb_str_times): reduce loop overhead.
|
||||
|
|
7
re.c
7
re.c
|
@ -2654,7 +2654,7 @@ rb_reg_quote(VALUE str)
|
|||
}
|
||||
s += clen;
|
||||
}
|
||||
if (ascii_only && rb_enc_get_index(str) != 0) {
|
||||
if (ascii_only) {
|
||||
str = rb_str_new3(str);
|
||||
rb_enc_associate(str, rb_usascii_encoding());
|
||||
}
|
||||
|
@ -2662,7 +2662,10 @@ rb_reg_quote(VALUE str)
|
|||
|
||||
meta_found:
|
||||
tmp = rb_str_new(0, RSTRING_LEN(str)*2);
|
||||
if (!ascii_only) {
|
||||
if (ascii_only) {
|
||||
rb_enc_associate(tmp, rb_usascii_encoding());
|
||||
}
|
||||
else {
|
||||
rb_enc_copy(tmp, str);
|
||||
}
|
||||
t = RSTRING_PTR(tmp);
|
||||
|
|
|
@ -523,16 +523,14 @@ class TestM17N < Test::Unit::TestCase
|
|||
def test_quote
|
||||
assert_regexp_generic_ascii(/#{Regexp.quote(a("a"))}#{Regexp.quote(e("e"))}/)
|
||||
|
||||
# Regexp.quote returns ASCII-8BIT string for ASCII only string
|
||||
# to make generic regexp if possible.
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(a("")).encoding)
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(e("")).encoding)
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(s("")).encoding)
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(u("")).encoding)
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(a("a")).encoding)
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(e("a")).encoding)
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(s("a")).encoding)
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(u("a")).encoding)
|
||||
assert_encoding("US-ASCII", Regexp.quote(a("")).encoding)
|
||||
assert_encoding("US-ASCII", Regexp.quote(e("")).encoding)
|
||||
assert_encoding("US-ASCII", Regexp.quote(s("")).encoding)
|
||||
assert_encoding("US-ASCII", Regexp.quote(u("")).encoding)
|
||||
assert_encoding("US-ASCII", Regexp.quote(a("a")).encoding)
|
||||
assert_encoding("US-ASCII", Regexp.quote(e("a")).encoding)
|
||||
assert_encoding("US-ASCII", Regexp.quote(s("a")).encoding)
|
||||
assert_encoding("US-ASCII", Regexp.quote(u("a")).encoding)
|
||||
|
||||
assert_encoding("ASCII-8BIT", Regexp.quote(a("\xc2\xa1")).encoding)
|
||||
assert_encoding("EUC-JP", Regexp.quote(e("\xc2\xa1")).encoding)
|
||||
|
|
Загрузка…
Ссылка в новой задаче