ruby-changes:7897
From: matz <ko1@a...>
Date: Thu, 18 Sep 2008 22:21:15 +0900 (JST)
Subject: [ruby-changes:7897] Ruby:r19418 (trunk): * string.c (rb_str_comparable): make ascii8bit string to be
matz 2008-09-18 22:17:41 +0900 (Thu, 18 Sep 2008) New Revision: 19418 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19418 Log: * 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. Modified files: trunk/ChangeLog trunk/string.c trunk/test/ruby/test_m17n_comb.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 19417) +++ ChangeLog (revision 19418) @@ -1,3 +1,11 @@ +Thu Sep 18 21:57:32 2008 Yukihiro Matsumoto <matz@r...> + + * 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@f...> * grapheme cluster implementation reverted. [ruby-dev:36375] Index: string.c =================================================================== --- string.c (revision 19417) +++ string.c (revision 19418) @@ -1926,6 +1926,7 @@ { 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 @@ 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 @@ 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; Index: test/ruby/test_m17n_comb.rb =================================================================== --- test/ruby/test_m17n_comb.rb (revision 19417) +++ test/ruby/test_m17n_comb.rb (revision 19418) @@ -318,11 +318,12 @@ 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) + 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.eql?(s2), desc_eq) - elsif s1.encoding == s2.encoding && a(s1) == a(s2) - assert(s1 == s2, desc_eq) assert(!(s1 != s2)) assert_equal(0, s1 <=> s2) assert(s1.eql?(s2), desc_eq) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/