www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11465] New: std.stdio.byLine(KeepTerminator.no) troubles on Windows

https://d.puremagic.com/issues/show_bug.cgi?id=11465

           Summary: std.stdio.byLine(KeepTerminator.no) troubles on
                    Windows
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This is related to Issue 5378.


This is a little program named "test.d", it loads the lines of its source code:


void main() {
    import std.stdio;
    "test.d".File.byLine.writeln;
    writeln;
    "test.d".File.byLine(KeepTerminator.no).writeln;
    writeln;
    "test.d".File.byLine(KeepTerminator.no, "\r\n").writeln;
}



Its output dmd 2.064 ("test.d" was saved with Windows newlines):


["void main() {\r", "    import std.stdio;\r", "   
\"test.d\".File.byLine.writeln;\r", "    writeln;\r", "   
\"test.d\".File.byLine(KeepTerminator.no).writeln;\r", "    writeln;\r", "   
\"test.d\".File.byLine(KeepTerminator.no, \"\\r\\n\").writeln;\r", "}"]

["void main() {\r", "    import std.stdio;\r", "   
\"test.d\".File.byLine.writeln;\r", "    writeln;\r", "   
\"test.d\".File.byLine(KeepTerminator.no).writeln;\r", "    writeln;\r", "   
\"test.d\".File.byLine(KeepTerminator.no, \"\\r\\n\").writeln;\r", "}"]

["void main() {", "    import std.stdio;", "   
\"test.d\".File.byLine.writeln;", "    writeln;", "   
\"test.d\".File.byLine(KeepTerminator.no).writeln;", "    writeln;", "   
\"test.d\".File.byLine(KeepTerminator.no, \"\\r\\n\").writeln;", "}"]


Notes:
- The first part of the output is not fully expected. Why is it stripping '\n'
and leaving '\r'? I expect end the lines with "\r\n" instead of "\r" (or even
with '\n' as does Python).
- Regarding the second part of the output I think it's not what most Windows
programmers would expect.
- The third part of the output is correct.


So I suggest:
- the std.stdio.byLine overload that has a third argument to default it to the
OS it is compiled for;
- std.stdio.byLine to leave '\n' at the line ends.


So I'd like the output of the program to become:

["void main() {\n", "    import std.stdio;\n", "   
\"test.d\".File.byLine.writeln;\n", "    writeln;\n", "   
\"test.d\".File.byLine(KeepTerminator.no).writeln;\n", "    writeln;\n", "   
\"test.d\".File.byLine(KeepTerminator.no, \"\\r\\n\").writeln;\n", "}"]

["void main() {", "    import std.stdio;", "   
\"test.d\".File.byLine.writeln;", "    writeln;", "   
\"test.d\".File.byLine(KeepTerminator.no).writeln;", "    writeln;", "   
\"test.d\".File.byLine(KeepTerminator.no, \"\\r\\n\").writeln;", "}"]

["void main() {", "    import std.stdio;", "   
\"test.d\".File.byLine.writeln;", "    writeln;", "   
\"test.d\".File.byLine(KeepTerminator.no).writeln;", "    writeln;", "   
\"test.d\".File.byLine(KeepTerminator.no, \"\\r\\n\").writeln;", "}"]

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