diff --git a/ChangeLog b/ChangeLog index 3deca32152..cd33030e86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ Mon Aug 27 23:14:02 2007 Yukihiro Matsumoto * 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 * encoding.c (rb_enc_codelen): raises invalid sequence exception diff --git a/string.c b/string.c index 1a369828fc..4c6301f56b 100644 --- a/string.c +++ b/string.c @@ -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"] */ /*