www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21846] New: std.format: provided format string for toString

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

          Issue ID: 21846
           Summary: std.format: provided format string for toString does
                    not work with grouping
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: bugzilla bernis-buecher.de

unittest
{
    struct S
    {
        int a;

        void toString(void delegate(const(char)[]) sink, string fmt)
        {
            auto spec = singleSpec(fmt);
            sink.formatValue(a, spec);
        }
    }

    S s = S(1);
    assert(format!"%5,3d"(s) == "    1");
}

The reason is, that fmt == "%,35d", which makes the width 5 part of the
grouping value.

--
Apr 21