Skip to content

Commit ba61161

Browse files
committed
Add XChar support into nested_formatter
Signed-off-by: Vladislav Shchapov <[email protected]>
1 parent df6e7b2 commit ba61161

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

include/fmt/format.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,33 +4136,37 @@ template <typename T> struct formatter<group_digits_view<T>> : formatter<T> {
41364136
}
41374137
};
41384138

4139-
template <typename T> struct nested_view {
4140-
const formatter<T>* fmt;
4139+
template <typename T, typename Char> struct nested_view {
4140+
const formatter<T, Char>* fmt;
41414141
const T* value;
41424142
};
41434143

4144-
template <typename T> struct formatter<nested_view<T>> {
4145-
FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> const char* {
4144+
template <typename T, typename Char>
4145+
struct formatter<nested_view<T, Char>, Char> {
4146+
template <typename ParseContext>
4147+
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
41464148
return ctx.begin();
41474149
}
4148-
auto format(nested_view<T> view, format_context& ctx) const
4150+
template <typename FormatContext>
4151+
auto format(nested_view<T, Char> view, FormatContext& ctx) const
41494152
-> decltype(ctx.out()) {
41504153
return view.fmt->format(*view.value, ctx);
41514154
}
41524155
};
41534156

4154-
template <typename T> struct nested_formatter {
4157+
template <typename T, typename Char = char> struct nested_formatter {
41554158
private:
41564159
int width_;
41574160
detail::fill_t fill_;
41584161
align_t align_ : 4;
4159-
formatter<T> formatter_;
4162+
formatter<T, Char> formatter_;
41604163

41614164
public:
41624165
constexpr nested_formatter() : width_(0), align_(align_t::none) {}
41634166

4164-
FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> const char* {
4165-
auto specs = detail::dynamic_format_specs<char>();
4167+
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
4168+
-> decltype(ctx.begin()) {
4169+
auto specs = detail::dynamic_format_specs<Char>();
41664170
auto it = parse_format_specs(ctx.begin(), ctx.end(), specs, ctx,
41674171
detail::type::none_type);
41684172
width_ = specs.width;
@@ -4172,21 +4176,21 @@ template <typename T> struct nested_formatter {
41724176
return formatter_.parse(ctx);
41734177
}
41744178

4175-
template <typename F>
4176-
auto write_padded(format_context& ctx, F write) const -> decltype(ctx.out()) {
4179+
template <typename FormatContext, typename F>
4180+
auto write_padded(FormatContext& ctx, F write) const -> decltype(ctx.out()) {
41774181
if (width_ == 0) return write(ctx.out());
4178-
auto buf = memory_buffer();
4179-
write(appender(buf));
4182+
auto buf = basic_memory_buffer<Char>();
4183+
write(basic_appender<Char>(buf));
41804184
auto specs = format_specs();
41814185
specs.width = width_;
41824186
specs.fill = fill_;
41834187
specs.align = align_;
4184-
return detail::write<char>(ctx.out(), string_view(buf.data(), buf.size()),
4185-
specs);
4188+
return detail::write<Char>(
4189+
ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
41864190
}
41874191

4188-
auto nested(const T& value) const -> nested_view<T> {
4189-
return nested_view<T>{&formatter_, &value};
4192+
auto nested(const T& value) const -> nested_view<T, Char> {
4193+
return nested_view<T, Char>{&formatter_, &value};
41904194
}
41914195
};
41924196

0 commit comments

Comments
 (0)