Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
js324 committed Feb 27, 2024
1 parent d17e9c9 commit 556e412
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <tuple>
#include <type_traits>

#include "base.h"
#include "format.h"

FMT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -455,57 +454,30 @@ struct range_formatter<
return underlying_.parse(ctx);
}

template <typename R, typename FormatContext, typename U = T,
enable_if_t<std::is_same<U, Char>::value, bool> = true>
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();
out = detail::copy<Char>(opening_bracket_, out);
int i = 0;
auto it = detail::range_begin(range);
auto end = detail::range_end(range);
if (is_string_format) {
if (is_debug) {
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;
detail::write<Char>(
return detail::write<Char>(
out, basic_string_view<Char>(buf.data(), buf.size()), spec_str);
} else {
for (; it != end; ++it) {
ctx.advance_to(out);
auto&& item = *it;
out = underlying_.format(mapper.map(item), ctx);
}
}
} else {
for (; it != end; ++it) {
if (i > 0) out = detail::copy<Char>(separator_, out);
ctx.advance_to(out);
auto&& item = *it;
out = underlying_.format(mapper.map(item), ctx);
++i;
}
}
out = detail::copy<Char>(closing_bracket_, out);
return out;
}

template <typename R, typename FormatContext, typename U = T,
enable_if_t<!(std::is_same<U, Char>::value), bool> = true>
auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) {
detail::range_mapper<buffered_context<Char>> mapper;
auto out = ctx.out();
out = detail::copy<Char>(opening_bracket_, out);
int i = 0;
auto it = detail::range_begin(range);
auto end = detail::range_end(range);
for (; it != end; ++it) {
if (i > 0) out = detail::copy<Char>(separator_, out);
if (i > 0 && !is_string_format) out = detail::copy<Char>(separator_, out);
ctx.advance_to(out);
auto&& item = *it;
out = underlying_.format(mapper.map(item), ctx);
Expand Down

0 comments on commit 556e412

Please sign in to comment.