mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +00:00
Allow mixing named and automatic arguments
This commit is contained in:
parent
7cea163809
commit
971fb584c3
@ -3001,12 +3001,10 @@ struct dynamic_formatter {
|
||||
template <typename Char>
|
||||
inline typename basic_context<Char>::format_arg
|
||||
basic_context<Char>::get_arg(basic_string_view<Char> name) {
|
||||
if (this->check_no_auto_index()) {
|
||||
map_.init(this->args());
|
||||
if (const format_arg *arg = map_.find(name))
|
||||
return *arg;
|
||||
this->on_error("argument not found");
|
||||
}
|
||||
map_.init(this->args());
|
||||
if (const format_arg *arg = map_.find(name))
|
||||
return *arg;
|
||||
this->on_error("argument not found");
|
||||
return format_arg();
|
||||
}
|
||||
|
||||
|
@ -488,6 +488,7 @@ TEST(FormatterTest, NamedArg) {
|
||||
EXPECT_THROW_MSG(format("{a}"), format_error, "argument not found");
|
||||
EXPECT_EQ(" -42", format("{0:{width}}", -42, fmt::arg("width", 4)));
|
||||
EXPECT_EQ("st", format("{0:.{precision}}", "str", fmt::arg("precision", 2)));
|
||||
EXPECT_EQ("1 2", format("{} {two}", 1, fmt::arg("two", 2)));
|
||||
}
|
||||
|
||||
TEST(FormatterTest, AutoArgIndex) {
|
||||
|
Loading…
Reference in New Issue
Block a user