[Issue 10098] New: byLine should return empty string instead of null when line is empty

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 16 17:15:27 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10098

           Summary: byLine should return empty string instead of null when
                    line is empty
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-05-16 17:15:26 PDT ---
The following code is well-intentioned, however it's currently broken:

-----
import std.stdio;
import std.range;

void main()
{
    auto file1 = File("text1.txt", "r");
    auto file2 = File("text2.txt", "r");

    foreach (char[] line1, char[] line2; zip(StoppingPolicy.longest,
file1.byLine, file2.byLine))
    {
        if (line1 is null)
        {
            // file 1 has less lines
            writefln("<!empty!> <%s>", line2);
        }

        if (line2 is null)
        {
            // file 2 has less lines
            writefln("<%s> <!empty!>", line1);
        }

        writefln("<%s> <%s>", line1, line2);
    }
}
-----

The problem is, line1 or line 2 will be null when an empty line is found. They
should really be a zero-length non-null array, otherwise you can't tell that
zip has actually ran out of lines for one of the files (note that we're using
StoppingPolicy.longest here).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list