From 66d71a1b351a29189aede96f5e12db826492413d Mon Sep 17 00:00:00 2001 From: Barry Revzin Date: Wed, 2 Nov 2022 13:04:54 -0500 Subject: [PATCH] Fixing formatting of range of range of char. (#3158) --- include/fmt/ranges.h | 5 +++-- test/ranges-test.cc | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 2105a668..2555b7e9 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -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') { @@ -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 != ':') diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 3221e2ed..650b0e85 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -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{'a', 'b', 'c'}; + auto vvc = std::vector>{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) {