Repository: fmtlib/fmt
File: include/fmt/ranges.h (C/C++)

Code before:
  auto write_debug_string(Output& out, It, Sentinel) const -> Output {
    return out;
  }

 public:
  FMT_CONSTEXPR range_formatter() {}

  FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type<Char, T>& {
    return underlying_;
  }

  FMT_CONSTEXPR void set_separator(basic_string_view<Char> sep) {
    separator_ = sep;
  }

  FMT_CONSTEXPR void set_brackets(basic_string_view<Char> open,
                                  basic_string_view<Char> close) {
    opening_bracket_ = open;
    closing_bracket_ = close;
  }

  template <typename ParseContext>
  FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
    auto it = ctx.begin();
    auto end = ctx.end();
    //detail::maybe_set_debug_format(underlying_, true);
    if (it == end) return underlying_.parse(ctx);

    switch (detail::to_ascii(*it)) {
    case 'n':
      set_brackets({}, {});
      ++it;
      break;
    case '?':
      is_debug = true;
      set_brackets({}, {});
      ++it;
      if (it == end || *it != 's') report_error("invalid format specifier");
      FMT_FALLTHROUGH;
    case 's':
      if (!std::is_same<T, Char>::value)
        report_error("invalid format specifier");
      if (!is_debug) {
        set_brackets(detail::string_literal<Char, '"'>{},
                     detail::string_literal<Char, '"'>{});
        set_separator({});
        detail::maybe_set_debug_format(underlying_, false);
      }
      ++it;
      return it;
    }

Review comment (bug):
I end up with something like: '\'''A''\'''\'''s''\'''\'''s''\'''\'''e''\'''\'''r''\'''\'''t''\ etc. because of that unconditional debug format setting. If I comment that line, it works for me locally. I use `{}` as format specifier.

Code after:
        out, basic_string_view<Char>(buf.data(), buf.size()), specs);
  }

  template <typename Output, typename It, typename Sentinel, typename U = T,
            FMT_ENABLE_IF(!std::is_same<U, Char>::value)>
  auto write_debug_string(Output& out, It, Sentinel) const -> Output {
    return out;
  }

 public:
  FMT_CONSTEXPR range_formatter() {}

  FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type<Char, T>& {
    return underlying_;
  }

  FMT_CONSTEXPR void set_separator(basic_string_view<Char> sep) {
    separator_ = sep;
  }

  FMT_CONSTEXPR void set_brackets(basic_string_view<Char> open,
                                  basic_string_view<Char> close) {
    opening_bracket_ = open;
    closing_bracket_ = close;
  }

  template <typename ParseContext>
  FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
    auto it = ctx.begin();
    auto end = ctx.end();
    detail::maybe_set_debug_format(underlying_, true);
    if (it == end) return underlying_.parse(ctx);

    switch (detail::to_ascii(*it)) {
    case 'n':
      set_brackets({}, {});
      ++it;
      break;
    case '?':
      is_debug = true;
      set_brackets({}, {});
      ++it;
      if (it == end || *it != 's') report_error("invalid format specifier");
      FMT_FALLTHROUGH;
    case 's':
      if (!std::is_same<T, Char>::value)
        report_error("invalid format specifier");
      if (!is_debug) {
        set_brackets(detail::string_literal<Char, '"'>{},
                     detail::string_literal<Char, '"'>{});
        set_separator({});