[Issue 13480] Input range formatting should not format as "elements"

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Sep 16 02:42:56 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13480

--- Comment #3 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Jakob Ovrum from comment #2)
> Thanks, nice to know it's possible to work around.
> 
> However, I don't think this flag should need to exist.
> 
> If strings were simply not quoted, one could get quoting by doing the much
> more intuitive explicit quoting: `%("%s"%|, %)`. Using '-' is just a hack -
> it has nothing to do with left-justification and thus the reader has to look
> it up to know what it does. We should follow the principle of least surprise
> here, by formatting the string as-is unless quoting is added by the user.

Handmade quoting is not enough for strings which contain double-quote
character.
See:

import std.stdio;
void main() {
  string s = `Hello "D" world!`;
  writefln("[%(%s%)]", [s]);
}

will output:
["Hello \"D\" world!"]

By design, std.format.formatValue functions stringize values by using
unformattable representation with unformatValue functions by default.
That's the reason why automatic quoting is done by default.

--


More information about the Digitalmars-d-bugs mailing list