Skip to content

Commit

Permalink
Fixing formatting of range of range of char. (#3158)
Browse files Browse the repository at this point in the history
  • Loading branch information
brevzin authored Nov 2, 2022
1 parent 80f8d34 commit 66d71a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ struct range_formatter<
auto end = ctx.end();
if (it == end || *it == '}') {
maybe_set_debug_format();
return it;
return underlying_.parse(ctx);
}

if (*it == 'n') {
Expand All @@ -485,7 +485,8 @@ struct range_formatter<

if (*it == '}') {
maybe_set_debug_format();
return it;
ctx.advance_to(it);
return underlying_.parse(ctx);
}

if (*it != ':')
Expand Down
8 changes: 8 additions & 0 deletions test/ranges-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ TEST(ranges_test, format_vector) {
EXPECT_EQ(fmt::format("{}", v), "[1, 2, 3, 5, 7, 11]");
EXPECT_EQ(fmt::format("{::#x}", v), "[0x1, 0x2, 0x3, 0x5, 0x7, 0xb]");
EXPECT_EQ(fmt::format("{:n:#x}", v), "0x1, 0x2, 0x3, 0x5, 0x7, 0xb");

auto vc = std::vector<char>{'a', 'b', 'c'};
auto vvc = std::vector<std::vector<char>>{vc, vc};
EXPECT_EQ(fmt::format("{}", vc), "['a', 'b', 'c']");
EXPECT_EQ(fmt::format("{}", vvc), "[['a', 'b', 'c'], ['a', 'b', 'c']]");
EXPECT_EQ(fmt::format("{:n}", vvc), "['a', 'b', 'c'], ['a', 'b', 'c']");
EXPECT_EQ(fmt::format("{:n:n}", vvc), "'a', 'b', 'c', 'a', 'b', 'c'");
EXPECT_EQ(fmt::format("{:n:n:}", vvc), "a, b, c, a, b, c");
}

TEST(ranges_test, format_vector2) {
Expand Down

0 comments on commit 66d71a1

Please sign in to comment.