Skip to content

Commit 645fde4

Browse files
committed
implement changes
1 parent e36ec04 commit 645fde4

File tree

1 file changed

+32
-37
lines changed

1 file changed

+32
-37
lines changed

include/fmt/ranges.h

+32-37
Original file line numberDiff line numberDiff line change
@@ -412,66 +412,61 @@ struct range_formatter<
412412
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
413413
auto it = ctx.begin();
414414
auto end = ctx.end();
415+
detail::maybe_set_debug_format(underlying_, true);
416+
if (it == end) {
417+
return underlying_.parse(ctx);
418+
}
415419

416-
if (it != end && *it == 'n') {
420+
switch (detail::to_ascii(*it)) {
421+
case 'n':
417422
set_brackets({}, {});
418423
++it;
419-
} else {
420-
bool check_for_s = false;
421-
if (it != end && *it == '?') {
422-
++it;
423-
detail::maybe_set_debug_format(underlying_, true);
424-
set_brackets({}, {});
425-
check_for_s = true;
426-
is_debug = true;
427-
}
428-
if (it != end && *it == 's') {
429-
if (!std::is_same<T, Char>::value) {
430-
report_error("invalid format specifier");
431-
}
432-
if (!is_debug) {
433-
set_brackets(detail::string_literal<Char, '"'>{},
434-
detail::string_literal<Char, '"'>{});
435-
}
436-
check_for_s = false;
437-
is_string_format = true;
438-
++it;
439-
}
440-
if (check_for_s) {
424+
break;
425+
case '?':
426+
is_debug = true;
427+
set_brackets({}, {});
428+
++it;
429+
FMT_FALLTHROUGH;
430+
case 's':
431+
if (it == end || *it != 's' || !std::is_same<T, Char>::value) {
441432
report_error("invalid format specifier");
442433
}
434+
if (!is_debug) {
435+
set_brackets(detail::string_literal<Char, '"'>{},
436+
detail::string_literal<Char, '"'>{});
437+
set_separator({});
438+
detail::maybe_set_debug_format(underlying_, false);
439+
}
440+
is_string_format = true;
441+
++it;
442+
return it;
443443
}
444444

445445
if (it != end && *it != '}') {
446-
if (is_string_format || *it != ':')
447-
report_error("invalid format specifier");
446+
if (*it != ':') report_error("invalid format specifier");
447+
detail::maybe_set_debug_format(underlying_, false);
448448
++it;
449-
} else {
450-
if (!is_string_format) detail::maybe_set_debug_format(underlying_, true);
451449
}
452450

453451
ctx.advance_to(it);
454452
return underlying_.parse(ctx);
455453
}
456454

457455
template <typename Output, typename Iter, typename IterEnd, typename U = T,
458-
enable_if_t<std::is_same<U, Char>::value, bool> = true>
456+
FMT_ENABLE_IF(std::is_same<U, Char>::value)>
459457
auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
460458
auto buf = basic_memory_buffer<Char>();
461459
for (; it != end; ++it) {
462-
auto&& item = *it;
463-
buf.push_back(item);
460+
buf.push_back(*it);
464461
}
465-
format_specs spec_str{};
462+
format_specs spec_str;
466463
spec_str.type = presentation_type::debug;
467464
return detail::write<Char>(
468465
out, basic_string_view<Char>(buf.data(), buf.size()), spec_str);
469466
}
470467
template <typename Output, typename Iter, typename IterEnd, typename U = T,
471-
enable_if_t<!(std::is_same<U, Char>::value), bool> = true>
472-
auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
473-
detail::ignore_unused(it);
474-
detail::ignore_unused(end);
468+
FMT_ENABLE_IF(!std::is_same<U, Char>::value)>
469+
auto write_debug_string(Output& out, Iter&, IterEnd&) const -> Output {
475470
return out;
476471
}
477472

@@ -481,14 +476,14 @@ struct range_formatter<
481476
auto out = ctx.out();
482477
auto it = detail::range_begin(range);
483478
auto end = detail::range_end(range);
484-
if (is_string_format && is_debug) {
479+
if (is_debug) {
485480
return write_debug_string(out, it, end);
486481
}
487482

488483
out = detail::copy<Char>(opening_bracket_, out);
489484
int i = 0;
490485
for (; it != end; ++it) {
491-
if (i > 0 && !is_string_format) out = detail::copy<Char>(separator_, out);
486+
if (i > 0) out = detail::copy<Char>(separator_, out);
492487
ctx.advance_to(out);
493488
auto&& item = *it;
494489
out = underlying_.format(mapper.map(item), ctx);

0 commit comments

Comments
 (0)