[Issue 13480] Input range formatting should not format as "elements"
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Sep 16 01:11:50 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13480
Jakob Ovrum <jakobovrum at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
--- Comment #2 from Jakob Ovrum <jakobovrum at gmail.com> ---
(In reply to Kenji Hara from comment #1)
> If you want to stop automatic element quoting, you can use "%-(".
>
> void main()
> {
> auto ror = ["one", "two", "three"];
> writefln("%-(%s%| %)", [1, 2, 3]); // 1 2 3
> writefln("%-(%s%| %)", "abc"); // a b c
> writefln("%-(%s%|, %)", ror); // one, two, three
> }
>
> It's documented in: http://dlang.org/phobos/std_format
>
> > Inside a compound format specifier, strings and characters are escaped
> > automatically. To avoid this behavior, add '-' flag to "%(".
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.
(changed severity to enhancement)
--
More information about the Digitalmars-d-bugs
mailing list