Skip to content

Commit 834618e

Browse files
committed
Merge pull request #174 from jamboree/feature/named-arg
Fix name parsing
2 parents a98583d + 3c99ed4 commit 834618e

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

format.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ inline Arg fmt::BasicFormatter<Char>::parse_arg_name(const Char *&s) {
764764
Char c;
765765
do {
766766
c = *++s;
767-
} while (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9'));
767+
} while (is_name_start(c) || ('0' <= c && c <= '9'));
768768
const char *error = 0;
769769
Arg arg = get_arg(fmt::BasicStringRef<Char>(start, s - start), error);
770770
if (error)

test/format-test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,9 @@ TEST(FormatterTest, ManyArgs) {
610610
#endif
611611

612612
TEST(FormatterTest, NamedArg) {
613+
EXPECT_EQ("1/a/A", format("{_1}/{a_}/{A_}", fmt::arg("a_", 'a'), fmt::arg("A_", "A"), fmt::arg("_1", 1)));
613614
char a = 'A', b = 'B', c = 'C';
614-
EXPECT_EQ("BBAACC", format("{1}{b}{0}{a}{2}{c}", FMT_CAPTURE(a, b, c)));
615+
EXPECT_EQ("BB/AA/CC", format("{1}{b}/{0}{a}/{2}{c}", FMT_CAPTURE(a, b, c)));
615616
EXPECT_EQ(" A", format("{a:>2}", FMT_CAPTURE(a)));
616617
EXPECT_THROW_MSG(format("{a+}", FMT_CAPTURE(a)), FormatError, "missing '}' in format string");
617618
EXPECT_THROW_MSG(format("{a}"), FormatError, "argument not found");

0 commit comments

Comments
 (0)