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_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
This commit is contained in:
naruse 2008-02-21 19:54:48 +00:00
parent 6d5ef97a32
commit b62df564a6
3 changed files with 20 additions and 7 deletions

View file

@ -1,3 +1,12 @@
Fri Feb 22 04:48:22 2008 NARUSE, Yui <naruse@ruby-lang.org>
* 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]
Thu Feb 21 17:15:15 2008 Martin Duerst <duerst@it.aoyama.ac.jp>
* transcode.c: Added basic support for passing options to String#encode

View file

@ -670,11 +670,11 @@ rb_enc_compatible(VALUE str1, VALUE str2)
enc1 = rb_enc_from_index(idx1);
enc2 = rb_enc_from_index(idx2);
if (TYPE(str2) == T_STRING && RSTRING_LEN(str2) == 0)
return enc1;
if (TYPE(str1) == T_STRING && RSTRING_LEN(str1) == 0)
return enc2;
if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2)) {
if (TYPE(str2) == T_STRING && RSTRING_LEN(str2) == 0)
return enc1;
if (TYPE(str1) == T_STRING && RSTRING_LEN(str1) == 0)
return enc2;
return 0;
}

View file

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