summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-27 14:32:15 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-27 14:32:15 +0000
commit51fb5511e0f4ac9eb96819648beaac173f054c0b (patch)
tree923bf3b928762eaea8c26786c1c6d6bee097554a /string.c
parent9166bd2bc9fa21a6cfa3c6390a7d165c0068895c (diff)
* 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
Diffstat (limited to 'string.c')
-rw-r--r--string.c8
1 files changed, 7 insertions, 1 deletions
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"]
*/
/*