mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
AK: Add missing overload to format.
I had this in #3580 but I must have lost it during rebasing.
This commit is contained in:
parent
3bd6142918
commit
675b482fe7
|
@ -99,6 +99,12 @@ String format(StringView fmtstr, const Parameters&... parameters)
|
||||||
Array formatters { Detail::Format::make_type_erased_formatter(parameters)... };
|
Array formatters { Detail::Format::make_type_erased_formatter(parameters)... };
|
||||||
return Detail::Format::format(fmtstr, formatters);
|
return Detail::Format::format(fmtstr, formatters);
|
||||||
}
|
}
|
||||||
|
template<typename... Parameters>
|
||||||
|
void format(StringBuilder& builder, StringView fmtstr, const Parameters&... parameters)
|
||||||
|
{
|
||||||
|
Array formatters { Detail::Format::make_type_erased_formatter(parameters)... };
|
||||||
|
Detail::Format::format(builder, fmtstr, formatters);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename... Parameters>
|
template<typename... Parameters>
|
||||||
void StringBuilder::appendff(StringView fmtstr, const Parameters&... parameters) { AK::format(*this, fmtstr, parameters...); }
|
void StringBuilder::appendff(StringView fmtstr, const Parameters&... parameters) { AK::format(*this, fmtstr, parameters...); }
|
||||||
|
|
|
@ -65,4 +65,13 @@ TEST_CASE(everything)
|
||||||
EXPECT_EQ(AK::format("{{{:04}/{}/{0:8}/{1}", 42u, "foo"), "{0042/foo/ 42/foo");
|
EXPECT_EQ(AK::format("{{{:04}/{}/{0:8}/{1}", 42u, "foo"), "{0042/foo/ 42/foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(string_builder)
|
||||||
|
{
|
||||||
|
StringBuilder builder;
|
||||||
|
builder.appendff(" {} ", 42);
|
||||||
|
builder.appendff("{1}{0} ", 1, 2);
|
||||||
|
|
||||||
|
EXPECT_EQ(builder.to_string(), " 42 21 ");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_MAIN(Format)
|
TEST_MAIN(Format)
|
||||||
|
|
Loading…
Reference in a new issue