www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16336] New: Inconsistent flag handling of std.format.FormatSpec


          Issue ID: 16336
           Summary: Inconsistent flag handling of std.format.FormatSpec
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: r.97all gmail.com

import std.format;

struct FormatSpecPrinter
    void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt)
        sink.formattedWrite("%s", fmt);

void main()
    import std.stdio;
    "%(%(%s%)%)".writefln(FormatSpecPrinter()); // just fine.
    "%-(%-(%s%)%)".writefln(FormatSpecPrinter()); // dash is nicely handled.
    "%+(%(%s%)%)".writefln(FormatSpecPrinter()); // OK: plus flag for outer
    "%(%+(%s%)%)".writefln(FormatSpecPrinter()); // inner plus flag crashes:
first "%)" matches "%(" and the second "%)" left orphan.

Like in the example in the wiki article, I'd like to use '+' flag for another
meaning, in a nested way.

So, I'd like '+' flags to be allowed both for outermost and nested '('
However, current implementation considers only "%-(" when looking for the
matching "%)" of outer "%(".

Jul 29 2016