www.digitalmars.com         C & C++   DMDScript  

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


          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

    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 2021