@@ -412,66 +412,61 @@ struct range_formatter<
412
412
FMT_CONSTEXPR auto parse (ParseContext& ctx) -> decltype(ctx.begin()) {
413
413
auto it = ctx.begin ();
414
414
auto end = ctx.end ();
415
+ detail::maybe_set_debug_format (underlying_, true );
416
+ if (it == end) {
417
+ return underlying_.parse (ctx);
418
+ }
415
419
416
- if (it != end && *it == ' n' ) {
420
+ switch (detail::to_ascii (*it)) {
421
+ case ' n' :
417
422
set_brackets ({}, {});
418
423
++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) {
441
432
report_error (" invalid format specifier" );
442
433
}
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;
443
443
}
444
444
445
445
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 );
448
448
++it;
449
- } else {
450
- if (!is_string_format) detail::maybe_set_debug_format (underlying_, true );
451
449
}
452
450
453
451
ctx.advance_to (it);
454
452
return underlying_.parse (ctx);
455
453
}
456
454
457
455
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) >
459
457
auto write_debug_string (Output& out, Iter& it, IterEnd& end) const -> Output {
460
458
auto buf = basic_memory_buffer<Char>();
461
459
for (; it != end; ++it) {
462
- auto && item = *it;
463
- buf.push_back (item);
460
+ buf.push_back (*it);
464
461
}
465
- format_specs spec_str{} ;
462
+ format_specs spec_str;
466
463
spec_str.type = presentation_type::debug;
467
464
return detail::write <Char>(
468
465
out, basic_string_view<Char>(buf.data (), buf.size ()), spec_str);
469
466
}
470
467
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 {
475
470
return out;
476
471
}
477
472
@@ -481,14 +476,14 @@ struct range_formatter<
481
476
auto out = ctx.out ();
482
477
auto it = detail::range_begin (range);
483
478
auto end = detail::range_end (range);
484
- if (is_string_format && is_debug) {
479
+ if (is_debug) {
485
480
return write_debug_string (out, it, end);
486
481
}
487
482
488
483
out = detail::copy<Char>(opening_bracket_, out);
489
484
int i = 0 ;
490
485
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);
492
487
ctx.advance_to (out);
493
488
auto && item = *it;
494
489
out = underlying_.format (mapper.map (item), ctx);
0 commit comments