1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

string.c: empty string is not invalid

* string.c (rb_enc_cr_str_copy_for_substr): empty string is always
  valid or 7bit.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-12-25 22:31:26 +00:00
parent 73982fa721
commit 6da33430de
2 changed files with 11 additions and 7 deletions

View file

@ -1,4 +1,7 @@
Wed Dec 26 07:31:19 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
Wed Dec 26 07:31:24 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_enc_cr_str_copy_for_substr): empty string is always
valid or 7bit.
* string.c (rb_str_enumerate_lines, rb_str_chop): reduce duplicated
code.

View file

@ -293,6 +293,13 @@ rb_enc_cr_str_copy_for_substr(VALUE dest, VALUE src)
* from src to new string "dest" which is made from the part of src.
*/
str_enc_copy(dest, src);
if (RSTRING_LEN(dest) == 0) {
if (!rb_enc_asciicompat(STR_ENC_GET(src)))
ENC_CODERANGE_SET(dest, ENC_CODERANGE_VALID);
else
ENC_CODERANGE_SET(dest, ENC_CODERANGE_7BIT);
return;
}
switch (ENC_CODERANGE(src)) {
case ENC_CODERANGE_7BIT:
ENC_CODERANGE_SET(dest, ENC_CODERANGE_7BIT);
@ -305,12 +312,6 @@ rb_enc_cr_str_copy_for_substr(VALUE dest, VALUE src)
ENC_CODERANGE_SET(dest, ENC_CODERANGE_7BIT);
break;
default:
if (RSTRING_LEN(dest) == 0) {
if (!rb_enc_asciicompat(STR_ENC_GET(src)))
ENC_CODERANGE_SET(dest, ENC_CODERANGE_VALID);
else
ENC_CODERANGE_SET(dest, ENC_CODERANGE_7BIT);
}
break;
}
}