mirror of
https://github.com/fmtlib/fmt.git
synced 2024-10-06 06:50:00 +00:00
Optimize range formatter
This commit is contained in:
parent
a69e43c9d7
commit
fae6f7e081
@ -3121,8 +3121,8 @@ struct formatter<T, Char,
|
|||||||
U == detail::type::cstring_type ||
|
U == detail::type::cstring_type ||
|
||||||
U == detail::type::char_type),
|
U == detail::type::char_type),
|
||||||
int> = 0>
|
int> = 0>
|
||||||
FMT_CONSTEXPR void set_debug_format() {
|
FMT_CONSTEXPR void set_debug_format(bool set = true) {
|
||||||
specs_.type = presentation_type::debug;
|
specs_.type = set ? presentation_type::debug : presentation_type::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
|
@ -440,20 +440,20 @@ struct range_formatter<
|
|||||||
detail::string_literal<Char, ']'>{};
|
detail::string_literal<Char, ']'>{};
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
FMT_CONSTEXPR static auto maybe_set_debug_format(U& u, int)
|
FMT_CONSTEXPR static auto maybe_set_debug_format(U& u, bool set)
|
||||||
-> decltype(u.set_debug_format()) {
|
-> decltype(u.set_debug_format(set)) {
|
||||||
u.set_debug_format();
|
u.set_debug_format(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class U>
|
template <class 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() {
|
FMT_CONSTEXPR void maybe_set_debug_format(bool set) {
|
||||||
maybe_set_debug_format(underlying_, 0);
|
maybe_set_debug_format(underlying_, set);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FMT_CONSTEXPR range_formatter() {}
|
FMT_CONSTEXPR range_formatter() { maybe_set_debug_format(true); }
|
||||||
|
|
||||||
FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type<Char, T>& {
|
FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type<Char, T>& {
|
||||||
return underlying_;
|
return underlying_;
|
||||||
@ -473,25 +473,18 @@ struct range_formatter<
|
|||||||
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||||
auto it = ctx.begin();
|
auto it = ctx.begin();
|
||||||
auto end = ctx.end();
|
auto end = ctx.end();
|
||||||
if (it == end || *it == '}') {
|
|
||||||
maybe_set_debug_format();
|
|
||||||
return underlying_.parse(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*it == 'n') {
|
if (it != end && *it == 'n') {
|
||||||
set_brackets({}, {});
|
set_brackets({}, {});
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*it == '}') {
|
if (it == end || *it == '}') return it;
|
||||||
maybe_set_debug_format();
|
|
||||||
ctx.advance_to(it);
|
|
||||||
return underlying_.parse(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*it != ':')
|
if (*it != ':')
|
||||||
FMT_THROW(format_error("no other top-level range formatters supported"));
|
FMT_THROW(format_error("no other top-level range formatters supported"));
|
||||||
|
|
||||||
|
maybe_set_debug_format(false);
|
||||||
custom_specs_ = true;
|
custom_specs_ = true;
|
||||||
++it;
|
++it;
|
||||||
ctx.advance_to(it);
|
ctx.advance_to(it);
|
||||||
|
Loading…
Reference in New Issue
Block a user