AK: Allow calling format without arguments.

This commit is contained in:
asynts 2020-09-23 11:01:32 +02:00 committed by Andreas Kling
parent ed5407a3d7
commit 3224fb7d55
Notes: sideshowbarker 2024-07-19 02:15:52 +09:00
2 changed files with 7 additions and 2 deletions

View file

@ -96,13 +96,13 @@ struct Formatter<T, typename EnableIf<IsIntegral<T>::value>::Type> {
template<typename... Parameters>
String format(StringView fmtstr, const Parameters&... parameters)
{
Array formatters { Detail::Format::make_type_erased_formatter(parameters)... };
Array<Detail::Format::TypeErasedFormatter, sizeof...(parameters)> formatters { Detail::Format::make_type_erased_formatter(parameters)... };
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)... };
Array<Detail::Format::TypeErasedFormatter, sizeof...(parameters)> formatters { Detail::Format::make_type_erased_formatter(parameters)... };
Detail::Format::format(builder, fmtstr, formatters);
}

View file

@ -74,4 +74,9 @@ TEST_CASE(string_builder)
EXPECT_EQ(builder.to_string(), " 42 21 ");
}
TEST_CASE(format_without_arguments)
{
EXPECT_EQ(AK::format("foo"), "foo");
}
TEST_MAIN(Format)