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


--- Comment #0 from bearophile_hugs 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: -------
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


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-18
11:57:20 PDT ---
(In reply to comment #0)
 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


--- Comment #2 from Vladimir Panteleev <thecybershadow gmail.com> 2013-03-18
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


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-18
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