summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--string.c5
-rw-r--r--test/ruby/test_m17n_comb.rb9
3 files changed, 17 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 129e53815..da07f5688 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Sep 18 21:57:32 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_comparable): make ascii8bit string to be
+ compatible with any other encoding.
+
+ * string.c (rb_str_cmp): use rb_str_comparable() instead of
+ rb_enc_compatible() since <=> is a comparison anyway.
+
Thu Sep 18 21:37:14 2008 Tanaka Akira <akr@fsij.org>
* grapheme cluster implementation reverted. [ruby-dev:36375]
diff --git a/string.c b/string.c
index 501320ae2..a56dbf66a 100644
--- a/string.c
+++ b/string.c
@@ -1926,6 +1926,7 @@ rb_str_comparable(VALUE str1, VALUE str2)
{
int idx1, idx2;
int rc1, rc2;
+ int a8;
if (RSTRING_LEN(str1) == 0) return Qtrue;
if (RSTRING_LEN(str2) == 0) return Qtrue;
@@ -1943,6 +1944,8 @@ rb_str_comparable(VALUE str1, VALUE str2)
if (rb_enc_asciicompat(rb_enc_from_index(idx1)))
return Qtrue;
}
+ a8 = rb_ascii8bit_encindex();
+ if (idx1 == a8 || idx2 == a8) return Qtrue;
return Qfalse;
}
@@ -1956,7 +1959,7 @@ rb_str_cmp(VALUE str1, VALUE str2)
retval = memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2), len);
if (retval == 0) {
if (RSTRING_LEN(str1) == RSTRING_LEN(str2)) {
- if (!rb_enc_compatible(str1, str2)) {
+ if (!rb_str_comparable(str1, str2)) {
if (ENCODING_GET(str1) - ENCODING_GET(str2) > 0)
return 1;
return -1;
diff --git a/test/ruby/test_m17n_comb.rb b/test/ruby/test_m17n_comb.rb
index 9de64f491..50fe8c223 100644
--- a/test/ruby/test_m17n_comb.rb
+++ b/test/ruby/test_m17n_comb.rb
@@ -318,10 +318,11 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_eq
combination(STRINGS, STRINGS) {|s1, s2|
desc_eq = "#{encdump s1} == #{encdump s2}"
- if s1.ascii_only? && s2.ascii_only? && a(s1) == a(s2)
- assert(s1 == s2, desc_eq)
- assert(s1.eql?(s2), desc_eq)
- elsif s1.encoding == s2.encoding && a(s1) == a(s2)
+ if a(s1) == a(s2) and
+ (s1.ascii_only? && s2.ascii_only? or
+ s1.encoding == s2.encoding or
+ s1.encoding == (enc = Encoding.find("ASCII-8BIT")) or
+ s2.encoding == enc) then
assert(s1 == s2, desc_eq)
assert(!(s1 != s2))
assert_equal(0, s1 <=> s2)