diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-27 14:32:15 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-27 14:32:15 +0000 |
commit | 51fb5511e0f4ac9eb96819648beaac173f054c0b (patch) | |
tree | 923bf3b928762eaea8c26786c1c6d6bee097554a | |
parent | 9166bd2bc9fa21a6cfa3c6390a7d165c0068895c (diff) | |
download | ruby-51fb5511e0f4ac9eb96819648beaac173f054c0b.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | string.c | 8 |
2 files changed, 10 insertions, 1 deletions
@@ -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 @@ -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"] */ /* |