www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4555] New: Double newlines with std.file.readText

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4555

           Summary: Double newlines with std.file.readText
           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



This is a D2 program:


import std.file: readText;
import std.stdio: write;
void main() {
    string s = readText("test.d");
    write(s);
}


With DMD 2.047 on a 32 bit Windows Vista Home this D2 program prints all
newlines doubled (assuming the program is named "test.d"):

import std.file: readText;

import std.stdio: write;

void main() {

    string s = readText("test.d");

    write(s);

}


Saving the same source code with in UNIX style the doubling of newlines doesn't
happen.
One or two testers have not found this problem on Windows XP.


This program:

import std.file: readText;
import std.stdio: write;
void main() {
    string s = readText("bug15.d");
    foreach (c; s[0 .. 35])
        write(cast(int)c, " ");
}


Prints:
105 109 112 111 114 116 32 115 116 100 46 102 105 108 101 58 32 114 101 97 100
84 101 120 116 59 13 10 105 109 112 111 114 116 32 

Note the normal sequence of the newline of the first line plus the "i" char at
the start of the second line:
13 10 105

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4555


Nick Sabalausky <cbkbbejeap mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cbkbbejeap mailinator.com



08:03:08 PDT ---
The 'write' function converts \n to \r\n on windows (And therefore also
converts \r\n to \r\r\n). Is it possible this problem is *just* write and not
readText at all?

Try converting all of the 'write' into 'stdout.rawWrite'. Also, since windows
command line displays *both* \n and \r\n as single newlines, your test should
redirect the output to a file, and then examine the result in either a hex
editor or a code editor that supports displaying line-ending characters (such
as Programmer's Notepad 2).


http://d.puremagic.com/issues/show_bug.cgi?id=9776

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






 Try converting all of the 'write' into 'stdout.rawWrite'.
If I use stdout.rawWrite then the duplication of newlines (in the first program) doesn't happen. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 23 2013