ruby-changes:45111
From: nobu <ko1@a...>
Date: Mon, 26 Dec 2016 08:50:16 +0900 (JST)
Subject: [ruby-changes:45111] nobu:r57184 (trunk): string.c: consistent paragraph mode with IO
nobu 2016-12-26 08:50:09 +0900 (Mon, 26 Dec 2016) New Revision: 57184 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57184 Log: string.c: consistent paragraph mode with IO * string.c (rb_str_enumerate_lines): in paragraph mode, do not include newlines which separate paragraphs, so that it will be consistent with IO#each_line. Modified files: trunk/string.c trunk/test/ruby/test_string.rb Index: string.c =================================================================== --- string.c (revision 57183) +++ string.c (revision 57184) @@ -7511,18 +7511,17 @@ rb_str_enumerate_lines(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/string.c#L7511 subptr = adjusted; continue; } - subend = hit + rslen; + subend = hit += rslen; if (paragraph_mode) { - while (subend < pend) { + while (hit < pend) { int n; - if (rb_enc_ascget(subend, pend, &n, enc) != '\r') + if (rb_enc_ascget(hit, pend, &n, enc) != '\r') n = 0; - if (!rb_enc_is_newline(subend + n, pend, enc)) break; - subend += n; - subend += rb_enc_mbclen(subend, pend, enc); + if (!rb_enc_is_newline(hit + n, pend, enc)) break; + hit += n; + hit += rb_enc_mbclen(hit, pend, enc); } } - hit = subend; if (chomp) { if (rsnewline) { subend = chomp_newline(subptr, subend, enc); @@ -7591,7 +7590,7 @@ rb_str_enumerate_lines(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/string.c#L7590 * "o\nworl" * "d" * Example three - * "hello\n\n\n" + * "hello\n\n" * "world" */ Index: test/ruby/test_string.rb =================================================================== --- test/ruby/test_string.rb (revision 57183) +++ test/ruby/test_string.rb (revision 57184) @@ -661,8 +661,8 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L661 res=[] S("hello\n\n\nworld").lines(S('')).each {|x| res << x} - assert_equal(S("hello\n\n\n"), res[0]) - assert_equal(S("world"), res[1]) + assert_equal(S("hello\n\n"), res[0]) + assert_equal(S("world"), res[1]) $/ = "!" res=[] @@ -782,8 +782,8 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L782 res=[] S("hello\n\n\nworld").each_line(S('')) {|x| res << x} - assert_equal(S("hello\n\n\n"), res[0]) - assert_equal(S("world"), res[1]) + assert_equal(S("hello\n\n"), res[0]) + assert_equal(S("world"), res[1]) $/ = "!" @@ -824,8 +824,8 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L824 res = [] S("hello\n\n\nworld").each_line(S(''), chomp: true) {|x| res << x} - assert_equal(S("hello\n\n"), res[0]) - assert_equal(S("world"), res[1]) + assert_equal(S("hello\n"), res[0]) + assert_equal(S("world"), res[1]) res = [] S("hello!world").each_line(S('!'), chomp: true) {|x| res << x} -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/