1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:57:35 +00:00

AK: Use new Formatter for each element in Formatter<Vector<T>>

The state of the formatter for the previous element should be thrown
away for each iteration. This showed up when trying to format a
Vector<String>, since Formatter<StringView> was unhappy about some state
that gets set when it's called. Add a test for Formatter<Vector>.
This commit is contained in:
Andrew Kaster 2021-07-17 16:27:12 -06:00 committed by Ali Mohammad Pur
parent 4842c8c902
commit 64aac345d3
2 changed files with 20 additions and 1 deletions

View file

@ -354,8 +354,10 @@ requires(HasFormatter<T>) struct Formatter<Vector<T>> : StandardFormatter {
builder.put_literal("[ "sv);
bool first = true;
for (auto& content : value) {
if (!first)
if (!first) {
builder.put_literal(", "sv);
content_fmt = Formatter<T> {};
}
first = false;
content_fmt.format(builder, content);
}