* string.c (tr_trans): should recalculate coderange.
[ruby-core:22326] (reopened at [ruby-core:22328]) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7b1bbd59e1
commit
624d07b0e4
@ -1,3 +1,8 @@
|
|||||||
|
Sun Feb 22 22:42:20 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (tr_trans): should recalculate coderange.
|
||||||
|
[ruby-core:22326] (reopened at [ruby-core:22328])
|
||||||
|
|
||||||
Sun Feb 22 20:09:29 2009 Tanaka Akira <akr@fsij.org>
|
Sun Feb 22 20:09:29 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/socket/option.c (inspect_linger): message refined.
|
* ext/socket/option.c (inspect_linger): message refined.
|
||||||
|
15
string.c
15
string.c
@ -4712,6 +4712,10 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||||||
int singlebyte = single_byte_optimizable(str);
|
int singlebyte = single_byte_optimizable(str);
|
||||||
int cr;
|
int cr;
|
||||||
|
|
||||||
|
#define CHECK_IF_ASCII(c) \
|
||||||
|
(void)((cr == ENC_CODERANGE_7BIT && !rb_isascii(c)) ? \
|
||||||
|
(cr = ENC_CODERANGE_VALID) : 0)
|
||||||
|
|
||||||
StringValue(src);
|
StringValue(src);
|
||||||
StringValue(repl);
|
StringValue(repl);
|
||||||
if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return Qnil;
|
if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return Qnil;
|
||||||
@ -4783,6 +4787,8 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cr == ENC_CODERANGE_VALID)
|
||||||
|
cr = ENC_CODERANGE_7BIT;
|
||||||
str_modify_keep_cr(str);
|
str_modify_keep_cr(str);
|
||||||
s = RSTRING_PTR(str); send = RSTRING_END(str);
|
s = RSTRING_PTR(str); send = RSTRING_END(str);
|
||||||
if (sflag) {
|
if (sflag) {
|
||||||
@ -4813,7 +4819,10 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||||||
c = errc;
|
c = errc;
|
||||||
}
|
}
|
||||||
if (c != -1) {
|
if (c != -1) {
|
||||||
if (save == c) continue;
|
if (save == c) {
|
||||||
|
CHECK_IF_ASCII(c);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
save = c;
|
save = c;
|
||||||
tlen = rb_enc_codelen(c, enc);
|
tlen = rb_enc_codelen(c, enc);
|
||||||
modify = 1;
|
modify = 1;
|
||||||
@ -4833,6 +4842,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||||||
if (may_modify && memcmp(s, t, tlen) != 0) {
|
if (may_modify && memcmp(s, t, tlen) != 0) {
|
||||||
modify = 1;
|
modify = 1;
|
||||||
}
|
}
|
||||||
|
CHECK_IF_ASCII(c);
|
||||||
t += tlen;
|
t += tlen;
|
||||||
}
|
}
|
||||||
*t = '\0';
|
*t = '\0';
|
||||||
@ -4855,6 +4865,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||||||
modify = 1;
|
modify = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CHECK_IF_ASCII(c);
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4904,6 +4915,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||||||
modify = 1;
|
modify = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CHECK_IF_ASCII(c);
|
||||||
s += clen;
|
s += clen;
|
||||||
t += tlen;
|
t += tlen;
|
||||||
}
|
}
|
||||||
@ -4918,7 +4930,6 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (modify) {
|
if (modify) {
|
||||||
cr = ENC_CODERANGE_AND(cr, ENC_CODERANGE(repl));
|
|
||||||
if (cr != ENC_CODERANGE_BROKEN)
|
if (cr != ENC_CODERANGE_BROKEN)
|
||||||
ENC_CODERANGE_SET(str, cr);
|
ENC_CODERANGE_SET(str, cr);
|
||||||
rb_enc_associate(str, enc);
|
rb_enc_associate(str, enc);
|
||||||
|
@ -1432,6 +1432,8 @@ class TestString < Test::Unit::TestCase
|
|||||||
def test_tr_s
|
def test_tr_s
|
||||||
assert_equal(S("hypo"), S("hello").tr_s(S("el"), S("yp")))
|
assert_equal(S("hypo"), S("hello").tr_s(S("el"), S("yp")))
|
||||||
assert_equal(S("h*o"), S("hello").tr_s(S("el"), S("*")))
|
assert_equal(S("h*o"), S("hello").tr_s(S("el"), S("*")))
|
||||||
|
assert_equal("a".hash, "\u0101\u0101".tr_s("\u0101", "a").hash)
|
||||||
|
assert_equal(true, "\u3041\u3041".tr("\u3041", "a").ascii_only?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tr_s!
|
def test_tr_s!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user