[Issue 9750] New: byLine(KeepTerminator.no) problem with Windows newlines in binary mode files
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 18 11:20:33 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9750
Summary: byLine(KeepTerminator.no) problem with Windows
newlines in binary mode files
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2013-03-18 11:20:32 PDT ---
I have a text file "words.txt" with lines separated by Windows newlines:
word1
word2
word3
This code:
import std.stdio;
void main() {
File("words.txt")
.byLine(KeepTerminator.no)
.writeln;
}
Prints:
["word1\r", "word2\r", "word3"]
I think the problem comes from File() opening on default in binary mode, so
each line (but the last one) ends with "\r\n", and byLine(KeepTerminator.no) is
stripping away only '\n' leaving the '\r'.
I think a D user assumes KeepTerminator.no should remove both if present.
std.string.chomp() removes both if they are present.
--
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