Fix #10713 - std.format string positions affect all further format specifiers (#10714)

This commit is contained in:
Richard (Rikki) Andrew Cattermole 2025-03-25 21:10:34 +13:00 committed by GitHub
parent b41bcd93df
commit c64232d813
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -296,6 +296,8 @@ if (is(Unqual!Char == Char))
}
width = 0;
indexStart = 0;
indexEnd = 0;
precision = UNSPECIFIED;
nested = null;
// Parse the spec (we assume we're past '%' already)
@ -834,6 +836,21 @@ if (is(Unqual!Char == Char))
== "$ expected after '*10' in format string");
}
// https://github.com/dlang/phobos/issues/10713
@safe pure unittest
{
import std.array : appender;
auto f = FormatSpec!char("%3$d%d");
auto w = appender!(char[])();
f.writeUpToNextSpec(w);
assert(f.indexStart == 3);
f.writeUpToNextSpec(w);
assert(w.data.length == 0);
assert(f.indexStart == 0);
}
/**
Helper function that returns a `FormatSpec` for a single format specifier.