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_each_line): should swallow sequence of newlines

if rs (optional argument) is an empty string.  [ruby-dev:31652]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-08-27 14:32:15 +00:00
parent 9166bd2bc9
commit 51fb5511e0
2 changed files with 10 additions and 1 deletions

View file

@ -2,6 +2,9 @@ Mon Aug 27 23:14:02 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_rstrip_bang): wrong strip point. [ruby-dev:31652]
* string.c (rb_str_each_line): should swallow sequence of newlines
if rs (optional argument) is an empty string. [ruby-dev:31652]
Mon Aug 27 22:39:08 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* encoding.c (rb_enc_codelen): raises invalid sequence exception

View file

@ -3919,6 +3919,12 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str)
int c = rb_enc_codepoint(p, pend, enc);
int n = rb_enc_codelen(c, enc);
if (rslen == 0 && c == newline) {
while (rb_enc_codepoint(p, pend, enc) == newline) {
p += n;
}
p -= n;
}
if (c == newline &&
(rslen <= 1 || rb_memcmp(RSTRING_PTR(rs), p, rslen) == 0)) {
line = rb_str_new5(str, s, p - s + (rslen ? rslen : n));
@ -3989,7 +3995,7 @@ rb_str_each_byte(VALUE str)
* Returns an enumerator that gives each character in the string.
* If a block is given, it iterates over each character in the string.
*
* "foo".lines.to_a #=> ["f","o","o"]
* "foo".chars.to_a #=> ["f","o","o"]
*/
/*