ruby-changes:26566
From: nobu <ko1@a...>
Date: Wed, 26 Dec 2012 07:31:40 +0900 (JST)
Subject: [ruby-changes:26566] nobu:r38617 (trunk): string.c: empty string is not invalid
nobu 2012-12-26 07:31:26 +0900 (Wed, 26 Dec 2012) New Revision: 38617 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38617 Log: string.c: empty string is not invalid * string.c (rb_enc_cr_str_copy_for_substr): empty string is always valid or 7bit. Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 38616) +++ ChangeLog (revision 38617) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Wed Dec 26 07:31:19 2012 Nobuyoshi Nakada <nobu@r...> +Wed Dec 26 07:31:24 2012 Nobuyoshi Nakada <nobu@r...> + + * 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. Index: string.c =================================================================== --- string.c (revision 38616) +++ string.c (revision 38617) @@ -293,6 +293,13 @@ rb_enc_cr_str_copy_for_substr(VALUE dest https://github.com/ruby/ruby/blob/trunk/string.c#L293 * 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 https://github.com/ruby/ruby/blob/trunk/string.c#L312 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; } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/