From b526c4ab416cd752db1a080380f784c571df9db2 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 10 May 2008 09:17:59 +0000 Subject: * string.c (rb_str_each_line): zero length record separator should split a string into paragraphs. [ruby-dev:34586] * string.c (rb_str_each_line): RDoc updated. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 8d4910291..3c8cdd3f0 100644 --- a/string.c +++ b/string.c @@ -5018,9 +5018,8 @@ rb_str_split(VALUE str, const char *sep0) * * Splits str using the supplied parameter as the record separator * ($/ by default), passing each substring in turn to the supplied - * block. If a zero-length record separator is supplied, the string is split on - * \n characters, except that multiple successive newlines are - * appended together. + * block. If a zero-length record separator is supplied, the string is split + * into paragraphs delimited by multiple successive newlines. * * print "Example one\n" * "hello\nworld".each {|s| p s} @@ -5107,8 +5106,13 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str) while (p < pend) { int c = rb_enc_codepoint(p, pend, enc); + again: n = rb_enc_codelen(c, enc); if (rslen == 0 && c == newline) { + p += n; + if (p < pend && (c = rb_enc_codepoint(p, pend, enc)) != newline) { + goto again; + } while (p < pend && rb_enc_codepoint(p, pend, enc) == newline) { p += n; } -- cgit