Skip to content

Commit

Permalink
separate func for writing debug strings
Browse files Browse the repository at this point in the history
  • Loading branch information
js324 committed Feb 27, 2024
1 parent 556e412 commit 5ebe8c8
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,24 +454,36 @@ struct range_formatter<
return underlying_.parse(ctx);
}

template <typename Output, typename Iter, typename IterEnd, typename U = T,
enable_if_t<std::is_same<U, Char>::value, bool> = true>
auto write_debug_string(Output& out, Iter& it, IterEnd& end) const {
auto buf = basic_memory_buffer<Char>();
for (; it != end; ++it) {
auto&& item = *it;
buf.push_back(item);
}
format_specs spec_str{};
spec_str.type = presentation_type::debug;
detail::write<Char>(out, basic_string_view<Char>(buf.data(), buf.size()),
spec_str);
}
template <typename Output, typename Iter, typename IterEnd, typename U = T,
enable_if_t<!(std::is_same<U, Char>::value), bool> = true>
auto write_debug_string(Output& out, Iter& it, IterEnd& end) const {
detail::ignore_unused(out);
detail::ignore_unused(it);
detail::ignore_unused(end);
}

template <typename R, typename FormatContext>
auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) {
detail::range_mapper<buffered_context<Char>> mapper;
auto out = ctx.out();
auto it = detail::range_begin(range);
auto end = detail::range_end(range);
if constexpr (std::is_same<T, Char>::value) {
if (is_string_format && is_debug) {
auto buf = basic_memory_buffer<Char>();
for (; it != end; ++it) {
auto&& item = *it;
buf.push_back(item);
}
format_specs spec_str{};
spec_str.type = presentation_type::debug;
return detail::write<Char>(
out, basic_string_view<Char>(buf.data(), buf.size()), spec_str);
}
if (is_string_format && is_debug) {
write_debug_string(out, it, end);
return out;
}

out = detail::copy<Char>(opening_bracket_, out);
Expand Down

0 comments on commit 5ebe8c8

Please sign in to comment.