diff options
Diffstat (limited to 'libphobos/src/std/format/write.d')
-rw-r--r-- | libphobos/src/std/format/write.d | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libphobos/src/std/format/write.d b/libphobos/src/std/format/write.d index 078fa78..d704c14 100644 --- a/libphobos/src/std/format/write.d +++ b/libphobos/src/std/format/write.d @@ -648,9 +648,16 @@ uint formattedWrite(Writer, Char, Args...)(auto ref Writer w, const scope Char[] break SWITCH; } default: - throw new FormatException( - text("Positional specifier %", spec.indexStart, '$', spec.spec, - " index exceeds ", Args.length)); + if (spec.indexEnd == spec.indexEnd.max) + break; + else if (spec.indexEnd == spec.indexStart) + throw new FormatException( + text("Positional specifier %", spec.indexStart, '$', spec.spec, + " index exceeds ", Args.length)); + else + throw new FormatException( + text("Positional specifier %", spec.indexStart, ":", spec.indexEnd, '$', spec.spec, + " index exceeds ", Args.length)); } } return currentArg; @@ -1199,6 +1206,16 @@ if (isSomeString!(typeof(fmt))) formattedWrite(stream, "%s", aa); } +// https://github.com/dlang/phobos/issues/10699 +@safe pure unittest +{ + import std.array : appender; + auto w = appender!(char[])(); + + formattedWrite(w, "%1:$d", 1, 2, 3); + assert(w.data == "123"); +} + /** Formats a value of any type according to a format specifier and writes the result to an output range. |