Comment #0 by bearophile_hugs — 2013-11-07T02:55:32Z
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;", "}"]
Comment #1 by robert.schadek — 2024-12-01T16:19:05Z