* encoding.c (rb_enc_compatible): empty strings are always compatible.
* string.c (rb_enc_cr_str_buf_cat): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
de7c3793c0
commit
7eeba5f440
@ -1,3 +1,9 @@
|
||||
Sat Feb 16 18:00:13 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* encoding.c (rb_enc_compatible): empty strings are always compatible.
|
||||
|
||||
* string.c (rb_enc_cr_str_buf_cat): ditto.
|
||||
|
||||
Sat Feb 16 16:14:35 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* string.c (rb_enc_strlen): UTF-8 character count moved to str_strlen.
|
||||
|
@ -664,8 +664,15 @@ rb_enc_compatible(VALUE str1, VALUE str2)
|
||||
}
|
||||
enc1 = rb_enc_from_index(idx1);
|
||||
enc2 = rb_enc_from_index(idx2);
|
||||
if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2))
|
||||
|
||||
if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2)) {
|
||||
if (TYPE(str2) == T_STRING && RSTRING_LEN(str2) == 0)
|
||||
return enc1;
|
||||
if (TYPE(str1) == T_STRING && RSTRING_LEN(str1) == 0)
|
||||
return enc2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BUILTIN_TYPE(str1) != T_STRING) {
|
||||
VALUE tmp = str1;
|
||||
int idx0 = idx1;
|
||||
|
8
string.c
8
string.c
@ -597,7 +597,6 @@ rb_enc_strlen(const char *p, const char *e, rb_encoding *enc)
|
||||
if (rb_enc_mbmaxlen(enc) == rb_enc_mbminlen(enc)) {
|
||||
return (e - p) / rb_enc_mbminlen(enc);
|
||||
}
|
||||
|
||||
else if (rb_enc_asciicompat(enc)) {
|
||||
c = 0;
|
||||
while (p < e) {
|
||||
@ -1303,6 +1302,13 @@ rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len,
|
||||
rb_encoding *str_enc = rb_enc_from_index(str_encindex);
|
||||
rb_encoding *ptr_enc = rb_enc_from_index(ptr_encindex);
|
||||
if (!rb_enc_asciicompat(str_enc) || !rb_enc_asciicompat(ptr_enc)) {
|
||||
if (len == 0)
|
||||
return str;
|
||||
if (RSTRING_LEN(str) == 0) {
|
||||
rb_str_buf_cat(str, ptr, len);
|
||||
ENCODING_CODERANGE_SET(str, ptr_encindex, ptr_cr);
|
||||
return str;
|
||||
}
|
||||
goto incompatible;
|
||||
}
|
||||
if (ptr_cr == ENC_CODERANGE_UNKNOWN) {
|
||||
|
@ -169,9 +169,49 @@ EOT
|
||||
enccall("aa".force_encoding("UTF-16BE"), :slice!, -1)
|
||||
end
|
||||
|
||||
def test_concat
|
||||
def test_plus_empty1
|
||||
s1 = ""
|
||||
s2 = "aa".force_encoding("utf-16be")
|
||||
assert_nothing_raised("#{encdump s1} << #{encdump s2}") {
|
||||
s1 + s2
|
||||
}
|
||||
end
|
||||
|
||||
def test_plus_empty2
|
||||
s1 = "aa"
|
||||
s2 = "".force_encoding("utf-16be")
|
||||
assert_nothing_raised("#{encdump s1} << #{encdump s2}") {
|
||||
s1 + s2
|
||||
}
|
||||
end
|
||||
|
||||
def test_plus_nonempty
|
||||
s1 = "aa"
|
||||
s2 = "bb".force_encoding("utf-16be")
|
||||
assert_raise(ArgumentError, "#{encdump s1} << #{encdump s2}") {
|
||||
s1 + s2
|
||||
}
|
||||
end
|
||||
|
||||
def test_concat_empty1
|
||||
s1 = ""
|
||||
s2 = "aa".force_encoding("utf-16be")
|
||||
assert_nothing_raised("#{encdump s1} << #{encdump s2}") {
|
||||
s1 << s2
|
||||
}
|
||||
end
|
||||
|
||||
def test_concat_empty2
|
||||
s1 = "aa"
|
||||
s2 = "".force_encoding("utf-16be")
|
||||
assert_nothing_raised("#{encdump s1} << #{encdump s2}") {
|
||||
s1 << s2
|
||||
}
|
||||
end
|
||||
|
||||
def test_concat_nonempty
|
||||
s1 = "aa"
|
||||
s2 = "bb".force_encoding("utf-16be")
|
||||
assert_raise(ArgumentError, "#{encdump s1} << #{encdump s2}") {
|
||||
s1 << s2
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user