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.
https://wiki.dlang.org/Defining_custom_print_format_specifiers
So, I'd like '+' flags to be allowed both for outermost and nested '(' specifier.
However, current implementation considers only "%-(" when looking for the matching "%)" of outer "%(".
https://github.com/dlang/phobos/blob/f75eeb596d44544e98a23ee1fd0b60f9ae8b0956/std/format.d#L918
Comment #1 by robert.schadek — 2024-12-01T16:27:38Z