mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 03:07:36 +02:00
Always call parse in range formatter
This commit is contained in:
@ -235,7 +235,7 @@ void for_each(index_sequence<Is...>, Tuple&& tup, F&& f) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
FMT_CONSTEXPR auto get_indexes(T const&)
|
FMT_CONSTEXPR auto get_indexes(const T&)
|
||||||
-> make_index_sequence<std::tuple_size<T>::value> {
|
-> make_index_sequence<std::tuple_size<T>::value> {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -361,7 +361,7 @@ struct formatter<Tuple, Char,
|
|||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FormatContext = format_context>
|
template <typename FormatContext>
|
||||||
auto format(const Tuple& value, FormatContext& ctx) const
|
auto format(const Tuple& value, FormatContext& ctx) const
|
||||||
-> decltype(ctx.out()) {
|
-> decltype(ctx.out()) {
|
||||||
auto out = detail::copy_str<Char>(opening_bracket_, ctx.out());
|
auto out = detail::copy_str<Char>(opening_bracket_, ctx.out());
|
||||||
@ -437,13 +437,13 @@ struct range_formatter<
|
|||||||
basic_string_view<Char> closing_bracket_ =
|
basic_string_view<Char> closing_bracket_ =
|
||||||
detail::string_literal<Char, ']'>{};
|
detail::string_literal<Char, ']'>{};
|
||||||
|
|
||||||
template <class U>
|
template <typename U>
|
||||||
FMT_CONSTEXPR static auto maybe_set_debug_format(U& u, bool set)
|
FMT_CONSTEXPR static auto maybe_set_debug_format(U& u, bool set)
|
||||||
-> decltype(u.set_debug_format(set)) {
|
-> decltype(u.set_debug_format(set)) {
|
||||||
u.set_debug_format(set);
|
u.set_debug_format(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class U>
|
template <typename U>
|
||||||
FMT_CONSTEXPR static void maybe_set_debug_format(U&, ...) {}
|
FMT_CONSTEXPR static void maybe_set_debug_format(U&, ...) {}
|
||||||
|
|
||||||
FMT_CONSTEXPR void maybe_set_debug_format(bool set) {
|
FMT_CONSTEXPR void maybe_set_debug_format(bool set) {
|
||||||
@ -451,7 +451,7 @@ struct range_formatter<
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FMT_CONSTEXPR range_formatter() { maybe_set_debug_format(true); }
|
FMT_CONSTEXPR range_formatter() {}
|
||||||
|
|
||||||
FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type<Char, T>& {
|
FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type<Char, T>& {
|
||||||
return underlying_;
|
return underlying_;
|
||||||
@ -477,14 +477,14 @@ struct range_formatter<
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it == end || *it == '}') return it;
|
if (it != end && *it != '}') {
|
||||||
|
if (*it != ':') FMT_THROW(format_error("invalid format specifier"));
|
||||||
|
custom_specs_ = true;
|
||||||
|
++it;
|
||||||
|
} else {
|
||||||
|
maybe_set_debug_format(true);
|
||||||
|
}
|
||||||
|
|
||||||
if (*it != ':')
|
|
||||||
FMT_THROW(format_error("no other top-level range formatters supported"));
|
|
||||||
|
|
||||||
maybe_set_debug_format(false);
|
|
||||||
custom_specs_ = true;
|
|
||||||
++it;
|
|
||||||
ctx.advance_to(it);
|
ctx.advance_to(it);
|
||||||
return underlying_.parse(ctx);
|
return underlying_.parse(ctx);
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ TEST(ranges_test, is_printable) {
|
|||||||
EXPECT_FALSE(is_printable(0x110000));
|
EXPECT_FALSE(is_printable(0x110000));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ranges_test, escape_string) {
|
TEST(ranges_test, escape) {
|
||||||
using vec = std::vector<std::string>;
|
using vec = std::vector<std::string>;
|
||||||
EXPECT_EQ(fmt::format("{}", vec{"\n\r\t\"\\"}), "[\"\\n\\r\\t\\\"\\\\\"]");
|
EXPECT_EQ(fmt::format("{}", vec{"\n\r\t\"\\"}), "[\"\\n\\r\\t\\\"\\\\\"]");
|
||||||
EXPECT_EQ(fmt::format("{}", vec{"\x07"}), "[\"\\x07\"]");
|
EXPECT_EQ(fmt::format("{}", vec{"\x07"}), "[\"\\x07\"]");
|
||||||
@ -386,8 +386,11 @@ TEST(ranges_test, escape_string) {
|
|||||||
"[\"\\xf0(\\x00\\x00anything\"]");
|
"[\"\\xf0(\\x00\\x00anything\"]");
|
||||||
|
|
||||||
// Correct utf-8.
|
// Correct utf-8.
|
||||||
EXPECT_EQ(fmt::format("{}", vec{"понедельник"}), "[\"понедельник\"]");
|
EXPECT_EQ(fmt::format("{}", vec{"🦄"}), "[\"🦄\"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXPECT_EQ(fmt::format("{}", std::vector<std::vector<char>>{{'x'}}),
|
||||||
|
"[['x']]");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename R> struct fmt_ref_view {
|
template <typename R> struct fmt_ref_view {
|
||||||
@ -420,7 +423,7 @@ TEST(ranges_test, container_adaptor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::stack<int> s;
|
auto s = std::stack<int>();
|
||||||
s.push(1);
|
s.push(1);
|
||||||
s.push(2);
|
s.push(2);
|
||||||
EXPECT_EQ(fmt::format("{}", s), "[1, 2]");
|
EXPECT_EQ(fmt::format("{}", s), "[1, 2]");
|
||||||
@ -428,14 +431,14 @@ TEST(ranges_test, container_adaptor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::queue<int> q;
|
auto q = std::queue<int>();
|
||||||
q.push(1);
|
q.push(1);
|
||||||
q.push(2);
|
q.push(2);
|
||||||
EXPECT_EQ(fmt::format("{}", q), "[1, 2]");
|
EXPECT_EQ(fmt::format("{}", q), "[1, 2]");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::priority_queue<int> q;
|
auto q = std::priority_queue<int>();
|
||||||
q.push(3);
|
q.push(3);
|
||||||
q.push(1);
|
q.push(1);
|
||||||
q.push(2);
|
q.push(2);
|
||||||
@ -444,7 +447,7 @@ TEST(ranges_test, container_adaptor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::stack<char, std::string> s;
|
auto s = std::stack<char, std::string>();
|
||||||
s.push('a');
|
s.push('a');
|
||||||
s.push('b');
|
s.push('b');
|
||||||
// See https://cplusplus.github.io/LWG/issue3881.
|
// See https://cplusplus.github.io/LWG/issue3881.
|
||||||
@ -461,7 +464,7 @@ TEST(ranges_test, container_adaptor) {
|
|||||||
container_type c;
|
container_type c;
|
||||||
};
|
};
|
||||||
|
|
||||||
my_container_adaptor m;
|
auto m = my_container_adaptor();
|
||||||
m.push(1);
|
m.push(1);
|
||||||
m.push(2);
|
m.push(2);
|
||||||
EXPECT_EQ(fmt::format("{}", m), "[1, 2]");
|
EXPECT_EQ(fmt::format("{}", m), "[1, 2]");
|
||||||
|
Reference in New Issue
Block a user