1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2008-09-18 13:17:41 +00:00
parent 081c802cb9
commit c3e2e0e53f
3 changed files with 17 additions and 5 deletions

View file

@ -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]

View file

@ -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;

View file

@ -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)