From c3e2e0e53f0e5bfd1277152fa7705c22a44bf573 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 18 Sep 2008 13:17:41 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'string.c') diff --git a/string.c b/string.c index 501320ae25..a56dbf66a3 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; -- cgit v1.2.3