www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13480] New: Input range formatting should not format as

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

          Issue ID: 13480
           Summary: Input range formatting should not format as "elements"
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: jakobovrum gmail.com

Consider the following (output in comments):

---
import std.algorithm;
import std.stdio;
import std.string;

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"
    writefln("%s", ror.joiner(", ")); // one, two, three
    writefln("%s", ror); // ["one", "two", "three"]
}
---


strings using the element markup style (`formatElement`), which forces single
and double quotes around the character or string respectively, defeats the
purpose of range-based formatting, which allows you to customize the fluff
around each element.

Not adding quotes is the more general solution; when quotes are desired, they
can be explicitly added like so: `%("%s"%|, %)`.

This behaviour neuters range-based formatting severely: std.format deals with
creating text, and strings and characters are the most basic units of text, yet
this behaviour renders range-based formatting unusable when quotes are not
desired (which is probably the vast majority of cases).

--
Sep 15 2014