Bug 11830 – std.stdio.byLine reports extra line if you don't call .front

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-27T10:19:00Z
Last change time
2014-02-09T11:41:00Z
Assigned to
nobody
Creator
peter.alexander.au

Comments

Comment #0 by peter.alexander.au — 2013-12-27T10:19:03Z
If you don't call 'front' while iterating a ByLine range, you get a different number of elements. import std.stdio; import std.range; import std.algorithm; void main() { File("stuff", "w").write("line 1\nline 2\n"); writeln(File("stuff").byLine.walkLength); writeln(File("stuff").byLine.filter!"true".walkLength); } This prints: 3 2 This should print 2 in both cases.
Comment #1 by github-bugzilla — 2014-01-31T03:43:47Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/516d4e95ab2dcaf12d4786400c8e5c75310551ca Fix Issue 11830 - ByLine range length incorrect. If you don't call `front` on a `ByLine` range then an extra line is reported. This change ensures the extra line is consumed when only calling `empty` without `front`. https://d.puremagic.com/issues/show_bug.cgi?id=11830 https://github.com/D-Programming-Language/phobos/commit/64967c01e2752c6c6e4071d23ad025592e3ae83d Merge pull request #1883 from Poita/bug11830 Fix Issue 11830 - ByLine range length incorrect.