diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-23 16:07:09 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-23 16:07:09 +0000 |
commit | fa1e530063ca4a825fc1a0e75151bac57ea2e5ae (patch) | |
tree | b291c14454644a39ce9e34b205d5fa3ffe418b68 | |
parent | 61ea3fd50d50f2d7bc5f124cda2b6bd8239fcfc1 (diff) | |
download | ruby-fa1e530063ca4a825fc1a0e75151bac57ea2e5ae.tar.gz |
* string.c (rb_str_comparable): comparison including broken
coderange strings do not consider encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 14 |
2 files changed, 13 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Mon Dec 24 01:03:17 2007 Yukihiro Matsumoto <matz@ruby-lang.org> + + * string.c (rb_str_comparable): comparison including broken + coderange strings do not consider encoding. + Mon Dec 24 00:57:15 2007 Yukihiro Matsumoto <matz@ruby-lang.org> * io.c (open_key_args): IO direct methods (foreach, readlines, @@ -1269,11 +1269,16 @@ rb_str_comparable(VALUE str1, VALUE str2) { int idx1 = rb_enc_get_index(str1); int idx2 = rb_enc_get_index(str2); + int rc1, rc2; if (idx1 == idx2) return Qtrue; - if (!is_ascii_string(str1)) return Qfalse; - if (!is_ascii_string(str2)) return Qfalse; - return Qtrue; + rc1 = rb_enc_str_coderange(str1); + rc2 = rb_enc_str_coderange(str2); + if (rc1 == ENC_CODERANGE_7BIT && rc2 == ENC_CODERANGE_7BIT) + return Qtrue; + if (rc1 == ENC_CODERANGE_BROKEN) return Qtrue; + if (rc2 == ENC_CODERANGE_BROKEN) return Qtrue; + return Qfalse; } int @@ -1288,9 +1293,6 @@ 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 (!enc) { - return rb_enc_get_index(str1) - rb_enc_get_index(str2); - } return 0; } if (RSTRING_LEN(str1) > RSTRING_LEN(str2)) return 1; |