Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #295 (closed defect: wontfix)

Opened 13 years ago

Last modified 12 years ago

Newlines under Windows are always just \n

Reported by: Deewiant Assigned to: kris
Priority: minor Milestone: 1.0
Component: IO Version: trunk
Keywords: Cc:

Description

Outputting newlines with the .newline, .println and .formatln methods or just with "\n" always results in just the \n character being printed. Example code:

import tango.io.Console;
import tango.io.Stdout;

void main() {
	Stdout.print("0");
	Cout.newline;
	Stdout.print("1");
	Cout("\n");
	Stdout.print("2");
	Cout("\r\n");
	Stdout.print("3");
	Stdout.println();
	Stdout.print("4");
	Stdout.print("\n");
	Stdout.print("5");
	Stdout.print("\r\n");
	Stdout.print("6");
	Stdout.print("
"); // depends on the format the file is saved in, I guess?
	Stdout.flush();
}

In Phobos, all of the above cases, using writef() instead of Stdout.print(), output the Windows line terminator, \r\n.

I can understand if printing "\n" should output just that, but I believe at least the standard .newline methods and ilk should print the correct line terminator for the system.

Whatever is intended behaviour, the docs should mention how this works somewhere. Without testing, one cannot know what one gets when outputting "\n", "\r\n", and when just calling .newline.

Change History

02/22/07 18:36:34 changed by kris

  • status changed from new to closed.
  • resolution set to fixed.
  • milestone set to 0.96 Beta 2.

Win32 newline() output is corrected to "\r\n", while an embedded "\n" is not translated.

Thanks for spotting this!

09/16/07 11:45:18 changed by kris

  • priority changed from major to minor.
  • status changed from closed to reopened.
  • version set to trunk.
  • resolution deleted.
  • milestone changed from 0.96 Beta 2 to 1.0.

see why \n is not being translated

09/29/07 20:13:47 changed by kris

  • status changed from reopened to closed.
  • resolution set to wontfix.

Translating the embedded \n would require scanning on a character by character basis, which Tango doesn't do (however, newline does platform specific output). We want to avoid the overhead of doing that scan.

One option would be to create an OutputStream? filter, which scan for such things?

I'll take a look to see if Derek's suggestion of {\n} can be mutated into something convenient :)

Closing for now.