mirror of
https://github.com/fmtlib/fmt.git
synced 2026-11-09 14:50:24 +08:00
Fixup range formatting to match stdlib (#5005)
* Fixup range formatting to match stdlib
fmt would format a range of characters with `{:s}`
spec with surrounding quotes, whereas stdlib omits the quotes.
This patch drops the quotes.
* update docs
This commit is contained in:
parent
9c19ea4664
commit
32777676cf
@ -667,7 +667,7 @@ fmt::print("{}", std::vector{'h', 'e', 'l', 'l', 'o'});
|
||||
fmt::print("{:n}", std::vector{'h', 'e', 'l', 'l', 'o'});
|
||||
// Output: 'h', 'e', 'l', 'l', 'o'
|
||||
fmt::print("{:s}", std::vector{'h', 'e', 'l', 'l', 'o'});
|
||||
// Output: "hello"
|
||||
// Output: hello
|
||||
fmt::print("{:?s}", std::vector{'h', 'e', 'l', 'l', 'o', '\n'});
|
||||
// Output: "hello\n"
|
||||
fmt::print("{::}", std::vector{'h', 'e', 'l', 'l', 'o'});
|
||||
|
||||
@ -467,7 +467,6 @@ struct range_formatter<
|
||||
break;
|
||||
case '?':
|
||||
is_debug = true;
|
||||
set_brackets({}, {});
|
||||
++it;
|
||||
if (it == end || *it != 's') report_error("invalid format specifier");
|
||||
FMT_FALLTHROUGH;
|
||||
@ -475,8 +474,7 @@ struct range_formatter<
|
||||
if (!std::is_same<T, Char>::value)
|
||||
report_error("invalid format specifier");
|
||||
if (!is_debug) {
|
||||
set_brackets(detail::string_literal<Char, '"'>{},
|
||||
detail::string_literal<Char, '"'>{});
|
||||
set_brackets({}, {});
|
||||
set_separator({});
|
||||
detail::maybe_set_debug_format(underlying_, false);
|
||||
}
|
||||
|
||||
@ -59,10 +59,10 @@ TEST(ranges_test, format_vector) {
|
||||
auto vec = std::vector<char>{'a', '\n', '\t'};
|
||||
auto vvc = std::vector<std::vector<char>>{vc, vc};
|
||||
EXPECT_EQ(fmt::format("{}", vc), "['a', 'b', 'c']");
|
||||
EXPECT_EQ(fmt::format("{:s}", vc), "\"abc\"");
|
||||
EXPECT_EQ(fmt::format("{:s}", vc), "abc");
|
||||
EXPECT_EQ(fmt::format("{:?s}", vec), "\"a\\n\\t\"");
|
||||
EXPECT_EQ(fmt::format("{:s}", vec), "\"a\n\t\"");
|
||||
EXPECT_EQ(fmt::format("{::s}", vvc), "[\"abc\", \"abc\"]");
|
||||
EXPECT_EQ(fmt::format("{:s}", vec), "a\n\t");
|
||||
EXPECT_EQ(fmt::format("{::s}", vvc), "[abc, abc]");
|
||||
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'");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user