Bug 6735 – splitLines ignores trailing delimiter

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-09-27T03:50:00Z
Last change time
2011-09-27T08:14:52Z
Assigned to
nobody
Creator
bus_dbugzilla

Comments

Comment #0 by bus_dbugzilla — 2011-09-27T03:50:49Z
Both of these should pass, but they currently fail: assert("a\n".splitLines() == ["a", ""]); assert("a\n".splitLines() != ["a"]); This is inconsistent with both "\na".splitLines() and with split(str, delim), as demonstrated here: ---------------------------------- import std.stdio; import std.string; void main() { // assert("a\n".splitLines() == ["a", ""]); assert("a\n".splitLines() != ["a"]); foreach(str; ["a", "a\n", "\na"]) { writefln("\nstr: '%s'", str); foreach(i, line; str.splitLines()) writeln(i, ": ", line); } foreach(str; ["a", "a,", ",a"]) { writefln("\nstr: '%s'", str); foreach(i, line; str.splitLines()) writeln(i, ": ", line); } } ---------------------------------- str: 'a b' 0: a 1: b str: 'a b ' 0: a 1: b str: ' a b' 0: 1: a 2: b str: 'a,b' 0: a 1: b str: 'a,b,' 0: a 1: b 2: str: ',a,b' 0: 1: a 2: b ----------------------------------
Comment #1 by bus_dbugzilla — 2011-09-27T03:52:29Z
Disregard those two assert lines inside main() in the second code example.
Comment #2 by bus_dbugzilla — 2011-09-27T06:25:51Z
Comment #3 by andrei — 2011-09-27T08:14:52Z
This is by design. Refer to comment in https://github.com/D-Programming-Language/phobos/pull/277.