Can we get rid of non-raw write?

torhu no at spam.invalid
Thu Mar 21 15:37:06 PDT 2013


On 20.03.2013 15:34, Nick Sabalausky wrote:
> Since *at least* as far back as XP, Windows has handled "\n" newlines
> perfectly fine. The command line displays them properly, .BAT scripts
> handle them properly, every code editor in existence handles them
> properly. The *only* thing I've found that doesn't is Windows Notepad,
> but really, whoTF uses that anyway?
>
> So, why are silently and forcefully converting "\n" to "\r\n" on
> windows by default? All it does is cause bugs. For example:
> https://github.com/repeatedly/mustache-d/issues/3
>
> And that's definitely not the first time I've run into problems due
> using the "write*" functions instead of rawWrite.
>
> Consider this straightforward code:
>
> --------------------------------------
> import std.file;
> import std.stdio;
>
> void transform(string str)
> {
> 	/+ ...perform some modification of 'str'... +/
> 	return str;
> }
>
> void main()
> {
> 	auto str = cast(string) read(args[1]);
> 	str = transform(str);
> 	write(str);
> }
> --------------------------------------
>
> That simple code is *wrong*:
>
> It works correctly for all input on Unix: Output newlines match input
> newlines. Always. The code never asks for newlines to be messed with,
> and therefore they never are.

You're mixing binary and text mode functions.  read() is binary, 
stdout.write() is text mode.  And yes, you are asking for newlines to be 
messed with, as File.write is documented to write in text mode.

But I agree that the docs need improvement.  And maybe the API.


More information about the Digitalmars-d mailing list