[Issue 21846] New: std.format: provided format string for toString does not work with grouping

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 21 15:41:04 UTC 2021


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 at puremagic.com
          Reporter: bugzilla at 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.

--


More information about the Digitalmars-d-bugs mailing list