summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-21 19:54:48 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-21 19:54:48 +0000
commitb62df564a6eff10ed741804c9a2415f6acac807f (patch)
treed0641664a76fcb1880f03e90f9138258474ff3fa /string.c
parent6d5ef97a32f74917efaa53049815873c4ae00aa1 (diff)
* string.c (rb_str_times): empty string's coderange is CODERANGE_7BIT.
* string.c (rb_str_substr): ditto. * encoding.c (rb_enc_compatible): empty string is compatible with not only nonasciicompatible strings. [ruby-dev:33895] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/string.c b/string.c
index 2efc5f69c0..34dccb27de 100644
--- a/string.c
+++ b/string.c
@@ -857,11 +857,14 @@ rb_str_times(VALUE str, VALUE times)
n *= 2;
}
memcpy(RSTRING_PTR(str2) + n, RSTRING_PTR(str2), len-n);
+ cr = ENC_CODERANGE(str);
+ if (cr == ENC_CODERANGE_BROKEN) cr = ENC_CODERANGE_UNKNOWN;
+ }
+ else {
+ cr = ENC_CODERANGE_7BIT;
}
RSTRING_PTR(str2)[RSTRING_LEN(str2)] = '\0';
OBJ_INFECT(str2, str);
- cr = ENC_CODERANGE(str);
- if (cr == ENC_CODERANGE_BROKEN) cr = ENC_CODERANGE_UNKNOWN;
ENCODING_CODERANGE_SET(str2, rb_enc_get_index(str), cr);
return str2;
@@ -1238,7 +1241,8 @@ rb_str_substr(VALUE str, long beg, long len)
}
else {
str2 = rb_str_new5(str, p, len);
- rb_enc_cr_str_copy(str2, str);
+ if (len) rb_enc_cr_str_copy(str2, str);
+ else ENC_CODERANGE_SET(str2, ENC_CODERANGE_7BIT);
OBJ_INFECT(str2, str);
}