mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Add XChar support into nested_formatter
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
committed by
Victor Zverovich
parent
c17816cb4a
commit
9f3fc6e38b
@ -4136,33 +4136,37 @@ template <typename T> struct formatter<group_digits_view<T>> : formatter<T> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> struct nested_view {
|
template <typename T, typename Char> struct nested_view {
|
||||||
const formatter<T>* fmt;
|
const formatter<T, Char>* fmt;
|
||||||
const T* value;
|
const T* value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> struct formatter<nested_view<T>> {
|
template <typename T, typename Char>
|
||||||
FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> const char* {
|
struct formatter<nested_view<T, Char>, Char> {
|
||||||
|
template <typename ParseContext>
|
||||||
|
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
auto format(nested_view<T> view, format_context& ctx) const
|
template <typename FormatContext>
|
||||||
|
auto format(nested_view<T, Char> view, FormatContext& ctx) const
|
||||||
-> decltype(ctx.out()) {
|
-> decltype(ctx.out()) {
|
||||||
return view.fmt->format(*view.value, ctx);
|
return view.fmt->format(*view.value, ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> struct nested_formatter {
|
template <typename T, typename Char = char> struct nested_formatter {
|
||||||
private:
|
private:
|
||||||
int width_;
|
int width_;
|
||||||
detail::fill_t fill_;
|
detail::fill_t fill_;
|
||||||
align_t align_ : 4;
|
align_t align_ : 4;
|
||||||
formatter<T> formatter_;
|
formatter<T, Char> formatter_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr nested_formatter() : width_(0), align_(align_t::none) {}
|
constexpr nested_formatter() : width_(0), align_(align_t::none) {}
|
||||||
|
|
||||||
FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> const char* {
|
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
|
||||||
auto specs = detail::dynamic_format_specs<char>();
|
-> decltype(ctx.begin()) {
|
||||||
|
auto specs = detail::dynamic_format_specs<Char>();
|
||||||
auto it = parse_format_specs(ctx.begin(), ctx.end(), specs, ctx,
|
auto it = parse_format_specs(ctx.begin(), ctx.end(), specs, ctx,
|
||||||
detail::type::none_type);
|
detail::type::none_type);
|
||||||
width_ = specs.width;
|
width_ = specs.width;
|
||||||
@ -4172,21 +4176,21 @@ template <typename T> struct nested_formatter {
|
|||||||
return formatter_.parse(ctx);
|
return formatter_.parse(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename FormatContext, typename F>
|
||||||
auto write_padded(format_context& ctx, F write) const -> decltype(ctx.out()) {
|
auto write_padded(FormatContext& ctx, F write) const -> decltype(ctx.out()) {
|
||||||
if (width_ == 0) return write(ctx.out());
|
if (width_ == 0) return write(ctx.out());
|
||||||
auto buf = memory_buffer();
|
auto buf = basic_memory_buffer<Char>();
|
||||||
write(appender(buf));
|
write(basic_appender<Char>(buf));
|
||||||
auto specs = format_specs();
|
auto specs = format_specs();
|
||||||
specs.width = width_;
|
specs.width = width_;
|
||||||
specs.fill = fill_;
|
specs.fill = fill_;
|
||||||
specs.align = align_;
|
specs.align = align_;
|
||||||
return detail::write<char>(ctx.out(), string_view(buf.data(), buf.size()),
|
return detail::write<Char>(
|
||||||
specs);
|
ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nested(const T& value) const -> nested_view<T> {
|
auto nested(const T& value) const -> nested_view<T, Char> {
|
||||||
return nested_view<T>{&formatter_, &value};
|
return nested_view<T, Char>{&formatter_, &value};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user