diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-10 09:17:59 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-10 09:17:59 +0000 |
commit | 9139a48f0e661cb6342f05102fa8afe53fbc0960 (patch) | |
tree | 8ad8272f342ed9643c4d16e3db4d4ebbc2b0f781 /string.c | |
parent | 332529d45ac100ffaa1e31ec4c498a70dc5bf143 (diff) |
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@16345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -5018,9 +5018,8 @@ rb_str_split(VALUE str, const char *sep0) * * Splits <i>str</i> using the supplied parameter as the record separator * (<code>$/</code> by default), passing each substring in turn to the supplied - * block. If a zero-length record separator is supplied, the string is split on - * <code>\n</code> 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; } |