зеркало из https://github.com/github/ruby.git
string.c: chomp rs at the end
* string.c (rb_str_enumerate_lines): should chomp record separator only, but not a newline, at the end of the receiver as well as middle, if the separator is given. [ruby-core:84552] [Bug #14257] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
18640bf9f0
Коммит
634a48c5c1
7
string.c
7
string.c
|
@ -8012,7 +8012,12 @@ rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, VALUE ary)
|
|||
|
||||
if (subptr != pend) {
|
||||
if (chomp) {
|
||||
pend = chomp_newline(subptr, pend, enc);
|
||||
if (rsnewline) {
|
||||
pend = chomp_newline(subptr, pend, enc);
|
||||
}
|
||||
else if (memcmp(pend - rslen, rsptr, rslen) == 0) {
|
||||
pend -= rslen;
|
||||
}
|
||||
}
|
||||
line = rb_str_subseq(str, subptr - ptr, pend - subptr);
|
||||
ENUM_ELEM(ary, line);
|
||||
|
|
|
@ -1119,6 +1119,10 @@ CODE
|
|||
res = []
|
||||
S("\r\n").each_line(chomp: true) {|x| res << x}
|
||||
assert_equal([S("")], res)
|
||||
|
||||
res = []
|
||||
S("a\n b\n").each_line(" ", chomp: true) {|x| res << x}
|
||||
assert_equal([S("a\n"), S("b\n")], res)
|
||||
end
|
||||
|
||||
def test_lines
|
||||
|
|
Загрузка…
Ссылка в новой задаче