summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-11 00:55:02 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-11 00:55:02 +0000
commit923a661a7ac19ce5e06f80bc6fd1f09172418b5f (patch)
tree8f5078984dd27b9b2dbdeef15d884dd9f3c07156 /string.c
parenteb1f89015e9c8de8e4f084aadb0f0811fd54371d (diff)
* string.c (rb_str_comparable): empty strings in any encoding are
compatible each other. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/string.c b/string.c
index 53c4027923..2d4b30aec2 100644
--- a/string.c
+++ b/string.c
@@ -1847,20 +1847,23 @@ rb_str_hash_m(VALUE str)
int
rb_str_comparable(VALUE str1, VALUE str2)
{
- int idx1 = ENCODING_GET(str1);
- int idx2 = ENCODING_GET(str2);
+ int idx1, idx2;
int rc1, rc2;
+ if (RSTRING_LEN(str1) == 0) return Qtrue;
+ if (RSTRING_LEN(str2) == 0) return Qtrue;
+ idx1 = ENCODING_GET(str1);
+ idx2 = ENCODING_GET(str2);
if (idx1 == idx2) return Qtrue;
rc1 = rb_enc_str_coderange(str1);
rc2 = rb_enc_str_coderange(str2);
if (rc1 == ENC_CODERANGE_7BIT) {
if (rc2 == ENC_CODERANGE_7BIT) return Qtrue;
- if (rb_enc_asciicompat(rb_enc_from_index(idx1)))
+ if (rb_enc_asciicompat(rb_enc_from_index(idx2)))
return Qtrue;
}
if (rc2 == ENC_CODERANGE_7BIT) {
- if (rb_enc_asciicompat(rb_enc_from_index(idx2)))
+ if (rb_enc_asciicompat(rb_enc_from_index(idx1)))
return Qtrue;
}
return Qfalse;