www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9750] New: byLine(KeepTerminator.no) problem with Windows newlines in binary mode files

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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: -------
Mar 18 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9750


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



11:57:20 PDT ---

 import std.stdio;
 void main() {
     File("words.txt")
     .byLine(KeepTerminator.no)
     .writeln;
 }
I think std.stdio is badly designed w.r.t. newlines. A terminator can be set (in the call to byLine), however it can only be a character instead of a string. So '\n' or '\r' is fine, but you can't set "\r\n". -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9750


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow gmail.com



21:01:02 EET ---
Dupe of issue 5378?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9750


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



12:11:08 PDT ---
Yeah I think it's a dupe.

*** This issue has been marked as a duplicate of issue 5378 ***

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