Bug 3018 – linefeed ignored after positional parameter in std.format

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-05-22T19:11:00Z
Last change time
2015-06-09T01:27:58Z
Assigned to
andrei
Creator
ghaecker

Comments

Comment #0 by ghaecker — 2009-05-22T19:11:13Z
In std.format, a linefeed after a positional parameter is ignored. A format string ending with a positional parameter throws RangeError. -------------------------------------------------------------- // Demo code string line1 = "line 1"; string line2 = "line 2"; writefln("With %%s parameters... ok"); writefln(" %s\n %s\n %s", line1, line2, line1); writefln("\nWith positional parameters... ignores linefeed"); writefln(" %1$\n %2$\n %1$\n", line1, line2); writefln("\nWithout trailing linefeed... throws RangeError"); writefln(" %1$\n %2$\n %1$", line1, line2); -------------------------------------------------------------- Output: With %s parameters... ok line 1 line 2 line 1 With positional parameters... ignores linefeed line 1 line 2 line 1 Without trailing linefeed... throws RangeError [email protected](1578): Range violation line 1 line 2
Comment #1 by ghaecker — 2010-08-15T05:39:01Z
This issue still persists in 2.048, although the exception thrown now is FormatError, not RangeError.
Comment #2 by ghaecker — 2010-08-15T20:02:31Z
You'd think that sometime in the 15-month period since I first reported this "bug" someone would say, "No, you're an idiot. It works just fine when used correctly." Obviously, this is not a bug. My apologies. -------------------------------------------------------------- // Demo code string line1 = "line 1"; string line2 = "line 2"; string line3 = "line 3"; writeln("With explicit parameters... ok"); writefln(" %s\n %s\n %s\n %s\n %s", line1, line2, line3, line2, line1); writeln("(complete)"); writeln("\nWith positional parameters... works fine."); writefln(" %1$s\n %2$s\n %3$s\n %2$s\n %1$s", line1, line2, line3); writeln("(complete)"); -------------------------------------------------------------- Output: With explicit parameters... ok line 1 line 2 line 3 line 2 line 1 (complete) With positional parameters... works fine. line 1 line 2 line 3 line 2 line 1 (complete)