git repos / blockattack-game

blame: source/misc/embedded_libs/fmt-8.1.1/include/fmt/ranges.h

normal view · raw

f8deb5b9 Poul Sander 2022-01-15 13:55 1
// Formatting library for C++ - experimental range support
f8deb5b9 Poul Sander 2022-01-15 13:55 2
//
f8deb5b9 Poul Sander 2022-01-15 13:55 3
// Copyright (c) 2012 - present, Victor Zverovich
f8deb5b9 Poul Sander 2022-01-15 13:55 4
// All rights reserved.
f8deb5b9 Poul Sander 2022-01-15 13:55 5
//
f8deb5b9 Poul Sander 2022-01-15 13:55 6
// For the license information refer to format.h.
f8deb5b9 Poul Sander 2022-01-15 13:55 7
//
f8deb5b9 Poul Sander 2022-01-15 13:55 8
// Copyright (c) 2018 - present, Remotion (Igor Schulz)
f8deb5b9 Poul Sander 2022-01-15 13:55 9
// All Rights Reserved
f8deb5b9 Poul Sander 2022-01-15 13:55 10
// {fmt} support for ranges, containers and types tuple interface.
f8deb5b9 Poul Sander 2022-01-15 13:55 11
f8deb5b9 Poul Sander 2022-01-15 13:55 12
#ifndef FMT_RANGES_H_
f8deb5b9 Poul Sander 2022-01-15 13:55 13
#define FMT_RANGES_H_
f8deb5b9 Poul Sander 2022-01-15 13:55 14
f8deb5b9 Poul Sander 2022-01-15 13:55 15
#include <initializer_list>
f8deb5b9 Poul Sander 2022-01-15 13:55 16
#include <tuple>
f8deb5b9 Poul Sander 2022-01-15 13:55 17
#include <type_traits>
f8deb5b9 Poul Sander 2022-01-15 13:55 18
f8deb5b9 Poul Sander 2022-01-15 13:55 19
#include "format.h"
f8deb5b9 Poul Sander 2022-01-15 13:55 20
f8deb5b9 Poul Sander 2022-01-15 13:55 21
FMT_BEGIN_NAMESPACE
f8deb5b9 Poul Sander 2022-01-15 13:55 22
f8deb5b9 Poul Sander 2022-01-15 13:55 23
namespace detail {
f8deb5b9 Poul Sander 2022-01-15 13:55 24
f8deb5b9 Poul Sander 2022-01-15 13:55 25
template <typename RangeT, typename OutputIterator>
f8deb5b9 Poul Sander 2022-01-15 13:55 26
OutputIterator copy(const RangeT& range, OutputIterator out) {
f8deb5b9 Poul Sander 2022-01-15 13:55 27
  for (auto it = range.begin(), end = range.end(); it != end; ++it)
f8deb5b9 Poul Sander 2022-01-15 13:55 28
    *out++ = *it;
f8deb5b9 Poul Sander 2022-01-15 13:55 29
  return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 30
}
f8deb5b9 Poul Sander 2022-01-15 13:55 31
f8deb5b9 Poul Sander 2022-01-15 13:55 32
template <typename OutputIterator>
f8deb5b9 Poul Sander 2022-01-15 13:55 33
OutputIterator copy(const char* str, OutputIterator out) {
f8deb5b9 Poul Sander 2022-01-15 13:55 34
  while (*str) *out++ = *str++;
f8deb5b9 Poul Sander 2022-01-15 13:55 35
  return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 36
}
f8deb5b9 Poul Sander 2022-01-15 13:55 37
f8deb5b9 Poul Sander 2022-01-15 13:55 38
template <typename OutputIterator>
f8deb5b9 Poul Sander 2022-01-15 13:55 39
OutputIterator copy(char ch, OutputIterator out) {
f8deb5b9 Poul Sander 2022-01-15 13:55 40
  *out++ = ch;
f8deb5b9 Poul Sander 2022-01-15 13:55 41
  return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 42
}
f8deb5b9 Poul Sander 2022-01-15 13:55 43
f8deb5b9 Poul Sander 2022-01-15 13:55 44
template <typename OutputIterator>
f8deb5b9 Poul Sander 2022-01-15 13:55 45
OutputIterator copy(wchar_t ch, OutputIterator out) {
f8deb5b9 Poul Sander 2022-01-15 13:55 46
  *out++ = ch;
f8deb5b9 Poul Sander 2022-01-15 13:55 47
  return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 48
}
f8deb5b9 Poul Sander 2022-01-15 13:55 49
f8deb5b9 Poul Sander 2022-01-15 13:55 50
// Returns true if T has a std::string-like interface, like std::string_view.
f8deb5b9 Poul Sander 2022-01-15 13:55 51
template <typename T> class is_std_string_like {
f8deb5b9 Poul Sander 2022-01-15 13:55 52
  template <typename U>
f8deb5b9 Poul Sander 2022-01-15 13:55 53
  static auto check(U* p)
f8deb5b9 Poul Sander 2022-01-15 13:55 54
      -> decltype((void)p->find('a'), p->length(), (void)p->data(), int());
f8deb5b9 Poul Sander 2022-01-15 13:55 55
  template <typename> static void check(...);
f8deb5b9 Poul Sander 2022-01-15 13:55 56
f8deb5b9 Poul Sander 2022-01-15 13:55 57
 public:
f8deb5b9 Poul Sander 2022-01-15 13:55 58
  static FMT_CONSTEXPR_DECL const bool value =
f8deb5b9 Poul Sander 2022-01-15 13:55 59
      is_string<T>::value ||
f8deb5b9 Poul Sander 2022-01-15 13:55 60
      std::is_convertible<T, std_string_view<char>>::value ||
f8deb5b9 Poul Sander 2022-01-15 13:55 61
      !std::is_void<decltype(check<T>(nullptr))>::value;
f8deb5b9 Poul Sander 2022-01-15 13:55 62
};
f8deb5b9 Poul Sander 2022-01-15 13:55 63
f8deb5b9 Poul Sander 2022-01-15 13:55 64
template <typename Char>
f8deb5b9 Poul Sander 2022-01-15 13:55 65
struct is_std_string_like<fmt::basic_string_view<Char>> : std::true_type {};
f8deb5b9 Poul Sander 2022-01-15 13:55 66
f8deb5b9 Poul Sander 2022-01-15 13:55 67
template <typename T> class is_map {
f8deb5b9 Poul Sander 2022-01-15 13:55 68
  template <typename U> static auto check(U*) -> typename U::mapped_type;
f8deb5b9 Poul Sander 2022-01-15 13:55 69
  template <typename> static void check(...);
f8deb5b9 Poul Sander 2022-01-15 13:55 70
f8deb5b9 Poul Sander 2022-01-15 13:55 71
 public:
f8deb5b9 Poul Sander 2022-01-15 13:55 72
#ifdef FMT_FORMAT_MAP_AS_LIST
f8deb5b9 Poul Sander 2022-01-15 13:55 73
  static FMT_CONSTEXPR_DECL const bool value = false;
f8deb5b9 Poul Sander 2022-01-15 13:55 74
#else
f8deb5b9 Poul Sander 2022-01-15 13:55 75
  static FMT_CONSTEXPR_DECL const bool value =
f8deb5b9 Poul Sander 2022-01-15 13:55 76
      !std::is_void<decltype(check<T>(nullptr))>::value;
f8deb5b9 Poul Sander 2022-01-15 13:55 77
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 78
};
f8deb5b9 Poul Sander 2022-01-15 13:55 79
f8deb5b9 Poul Sander 2022-01-15 13:55 80
template <typename T> class is_set {
f8deb5b9 Poul Sander 2022-01-15 13:55 81
  template <typename U> static auto check(U*) -> typename U::key_type;
f8deb5b9 Poul Sander 2022-01-15 13:55 82
  template <typename> static void check(...);
f8deb5b9 Poul Sander 2022-01-15 13:55 83
f8deb5b9 Poul Sander 2022-01-15 13:55 84
 public:
f8deb5b9 Poul Sander 2022-01-15 13:55 85
#ifdef FMT_FORMAT_SET_AS_LIST
f8deb5b9 Poul Sander 2022-01-15 13:55 86
  static FMT_CONSTEXPR_DECL const bool value = false;
f8deb5b9 Poul Sander 2022-01-15 13:55 87
#else
f8deb5b9 Poul Sander 2022-01-15 13:55 88
  static FMT_CONSTEXPR_DECL const bool value =
f8deb5b9 Poul Sander 2022-01-15 13:55 89
      !std::is_void<decltype(check<T>(nullptr))>::value && !is_map<T>::value;
f8deb5b9 Poul Sander 2022-01-15 13:55 90
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 91
};
f8deb5b9 Poul Sander 2022-01-15 13:55 92
f8deb5b9 Poul Sander 2022-01-15 13:55 93
template <typename... Ts> struct conditional_helper {};
f8deb5b9 Poul Sander 2022-01-15 13:55 94
f8deb5b9 Poul Sander 2022-01-15 13:55 95
template <typename T, typename _ = void> struct is_range_ : std::false_type {};
f8deb5b9 Poul Sander 2022-01-15 13:55 96
f8deb5b9 Poul Sander 2022-01-15 13:55 97
#if !FMT_MSC_VER || FMT_MSC_VER > 1800
f8deb5b9 Poul Sander 2022-01-15 13:55 98
f8deb5b9 Poul Sander 2022-01-15 13:55 99
#  define FMT_DECLTYPE_RETURN(val)  \
f8deb5b9 Poul Sander 2022-01-15 13:55 100
    ->decltype(val) { return val; } \
f8deb5b9 Poul Sander 2022-01-15 13:55 101
    static_assert(                  \
f8deb5b9 Poul Sander 2022-01-15 13:55 102
        true, "")  // This makes it so that a semicolon is required after the
f8deb5b9 Poul Sander 2022-01-15 13:55 103
                   // macro, which helps clang-format handle the formatting.
f8deb5b9 Poul Sander 2022-01-15 13:55 104
f8deb5b9 Poul Sander 2022-01-15 13:55 105
// C array overload
f8deb5b9 Poul Sander 2022-01-15 13:55 106
template <typename T, std::size_t N>
f8deb5b9 Poul Sander 2022-01-15 13:55 107
auto range_begin(const T (&arr)[N]) -> const T* {
f8deb5b9 Poul Sander 2022-01-15 13:55 108
  return arr;
f8deb5b9 Poul Sander 2022-01-15 13:55 109
}
f8deb5b9 Poul Sander 2022-01-15 13:55 110
template <typename T, std::size_t N>
f8deb5b9 Poul Sander 2022-01-15 13:55 111
auto range_end(const T (&arr)[N]) -> const T* {
f8deb5b9 Poul Sander 2022-01-15 13:55 112
  return arr + N;
f8deb5b9 Poul Sander 2022-01-15 13:55 113
}
f8deb5b9 Poul Sander 2022-01-15 13:55 114
f8deb5b9 Poul Sander 2022-01-15 13:55 115
template <typename T, typename Enable = void>
f8deb5b9 Poul Sander 2022-01-15 13:55 116
struct has_member_fn_begin_end_t : std::false_type {};
f8deb5b9 Poul Sander 2022-01-15 13:55 117
f8deb5b9 Poul Sander 2022-01-15 13:55 118
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 119
struct has_member_fn_begin_end_t<T, void_t<decltype(std::declval<T>().begin()),
f8deb5b9 Poul Sander 2022-01-15 13:55 120
                                           decltype(std::declval<T>().end())>>
f8deb5b9 Poul Sander 2022-01-15 13:55 121
    : std::true_type {};
f8deb5b9 Poul Sander 2022-01-15 13:55 122
f8deb5b9 Poul Sander 2022-01-15 13:55 123
// Member function overload
f8deb5b9 Poul Sander 2022-01-15 13:55 124
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 125
auto range_begin(T&& rng) FMT_DECLTYPE_RETURN(static_cast<T&&>(rng).begin());
f8deb5b9 Poul Sander 2022-01-15 13:55 126
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 127
auto range_end(T&& rng) FMT_DECLTYPE_RETURN(static_cast<T&&>(rng).end());
f8deb5b9 Poul Sander 2022-01-15 13:55 128
f8deb5b9 Poul Sander 2022-01-15 13:55 129
// ADL overload. Only participates in overload resolution if member functions
f8deb5b9 Poul Sander 2022-01-15 13:55 130
// are not found.
f8deb5b9 Poul Sander 2022-01-15 13:55 131
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 132
auto range_begin(T&& rng)
f8deb5b9 Poul Sander 2022-01-15 13:55 133
    -> enable_if_t<!has_member_fn_begin_end_t<T&&>::value,
f8deb5b9 Poul Sander 2022-01-15 13:55 134
                   decltype(begin(static_cast<T&&>(rng)))> {
f8deb5b9 Poul Sander 2022-01-15 13:55 135
  return begin(static_cast<T&&>(rng));
f8deb5b9 Poul Sander 2022-01-15 13:55 136
}
f8deb5b9 Poul Sander 2022-01-15 13:55 137
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 138
auto range_end(T&& rng) -> enable_if_t<!has_member_fn_begin_end_t<T&&>::value,
f8deb5b9 Poul Sander 2022-01-15 13:55 139
                                       decltype(end(static_cast<T&&>(rng)))> {
f8deb5b9 Poul Sander 2022-01-15 13:55 140
  return end(static_cast<T&&>(rng));
f8deb5b9 Poul Sander 2022-01-15 13:55 141
}
f8deb5b9 Poul Sander 2022-01-15 13:55 142
f8deb5b9 Poul Sander 2022-01-15 13:55 143
template <typename T, typename Enable = void>
f8deb5b9 Poul Sander 2022-01-15 13:55 144
struct has_const_begin_end : std::false_type {};
f8deb5b9 Poul Sander 2022-01-15 13:55 145
template <typename T, typename Enable = void>
f8deb5b9 Poul Sander 2022-01-15 13:55 146
struct has_mutable_begin_end : std::false_type {};
f8deb5b9 Poul Sander 2022-01-15 13:55 147
f8deb5b9 Poul Sander 2022-01-15 13:55 148
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 149
struct has_const_begin_end<
f8deb5b9 Poul Sander 2022-01-15 13:55 150
    T,
f8deb5b9 Poul Sander 2022-01-15 13:55 151
    void_t<
f8deb5b9 Poul Sander 2022-01-15 13:55 152
        decltype(detail::range_begin(std::declval<const remove_cvref_t<T>&>())),
f8deb5b9 Poul Sander 2022-01-15 13:55 153
        decltype(detail::range_end(std::declval<const remove_cvref_t<T>&>()))>>
f8deb5b9 Poul Sander 2022-01-15 13:55 154
    : std::true_type {};
f8deb5b9 Poul Sander 2022-01-15 13:55 155
f8deb5b9 Poul Sander 2022-01-15 13:55 156
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 157
struct has_mutable_begin_end<
f8deb5b9 Poul Sander 2022-01-15 13:55 158
    T, void_t<decltype(detail::range_begin(std::declval<T>())),
f8deb5b9 Poul Sander 2022-01-15 13:55 159
              decltype(detail::range_end(std::declval<T>())),
f8deb5b9 Poul Sander 2022-01-15 13:55 160
              enable_if_t<std::is_copy_constructible<T>::value>>>
f8deb5b9 Poul Sander 2022-01-15 13:55 161
    : std::true_type {};
f8deb5b9 Poul Sander 2022-01-15 13:55 162
f8deb5b9 Poul Sander 2022-01-15 13:55 163
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 164
struct is_range_<T, void>
f8deb5b9 Poul Sander 2022-01-15 13:55 165
    : std::integral_constant<bool, (has_const_begin_end<T>::value ||
f8deb5b9 Poul Sander 2022-01-15 13:55 166
                                    has_mutable_begin_end<T>::value)> {};
f8deb5b9 Poul Sander 2022-01-15 13:55 167
#  undef FMT_DECLTYPE_RETURN
f8deb5b9 Poul Sander 2022-01-15 13:55 168
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 169
f8deb5b9 Poul Sander 2022-01-15 13:55 170
// tuple_size and tuple_element check.
f8deb5b9 Poul Sander 2022-01-15 13:55 171
template <typename T> class is_tuple_like_ {
f8deb5b9 Poul Sander 2022-01-15 13:55 172
  template <typename U>
f8deb5b9 Poul Sander 2022-01-15 13:55 173
  static auto check(U* p) -> decltype(std::tuple_size<U>::value, int());
f8deb5b9 Poul Sander 2022-01-15 13:55 174
  template <typename> static void check(...);
f8deb5b9 Poul Sander 2022-01-15 13:55 175
f8deb5b9 Poul Sander 2022-01-15 13:55 176
 public:
f8deb5b9 Poul Sander 2022-01-15 13:55 177
  static FMT_CONSTEXPR_DECL const bool value =
f8deb5b9 Poul Sander 2022-01-15 13:55 178
      !std::is_void<decltype(check<T>(nullptr))>::value;
f8deb5b9 Poul Sander 2022-01-15 13:55 179
};
f8deb5b9 Poul Sander 2022-01-15 13:55 180
f8deb5b9 Poul Sander 2022-01-15 13:55 181
// Check for integer_sequence
f8deb5b9 Poul Sander 2022-01-15 13:55 182
#if defined(__cpp_lib_integer_sequence) || FMT_MSC_VER >= 1900
f8deb5b9 Poul Sander 2022-01-15 13:55 183
template <typename T, T... N>
f8deb5b9 Poul Sander 2022-01-15 13:55 184
using integer_sequence = std::integer_sequence<T, N...>;
f8deb5b9 Poul Sander 2022-01-15 13:55 185
template <size_t... N> using index_sequence = std::index_sequence<N...>;
f8deb5b9 Poul Sander 2022-01-15 13:55 186
template <size_t N> using make_index_sequence = std::make_index_sequence<N>;
f8deb5b9 Poul Sander 2022-01-15 13:55 187
#else
f8deb5b9 Poul Sander 2022-01-15 13:55 188
template <typename T, T... N> struct integer_sequence {
f8deb5b9 Poul Sander 2022-01-15 13:55 189
  using value_type = T;
f8deb5b9 Poul Sander 2022-01-15 13:55 190
f8deb5b9 Poul Sander 2022-01-15 13:55 191
  static FMT_CONSTEXPR size_t size() { return sizeof...(N); }
f8deb5b9 Poul Sander 2022-01-15 13:55 192
};
f8deb5b9 Poul Sander 2022-01-15 13:55 193
f8deb5b9 Poul Sander 2022-01-15 13:55 194
template <size_t... N> using index_sequence = integer_sequence<size_t, N...>;
f8deb5b9 Poul Sander 2022-01-15 13:55 195
f8deb5b9 Poul Sander 2022-01-15 13:55 196
template <typename T, size_t N, T... Ns>
f8deb5b9 Poul Sander 2022-01-15 13:55 197
struct make_integer_sequence : make_integer_sequence<T, N - 1, N - 1, Ns...> {};
f8deb5b9 Poul Sander 2022-01-15 13:55 198
template <typename T, T... Ns>
f8deb5b9 Poul Sander 2022-01-15 13:55 199
struct make_integer_sequence<T, 0, Ns...> : integer_sequence<T, Ns...> {};
f8deb5b9 Poul Sander 2022-01-15 13:55 200
f8deb5b9 Poul Sander 2022-01-15 13:55 201
template <size_t N>
f8deb5b9 Poul Sander 2022-01-15 13:55 202
using make_index_sequence = make_integer_sequence<size_t, N>;
f8deb5b9 Poul Sander 2022-01-15 13:55 203
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 204
f8deb5b9 Poul Sander 2022-01-15 13:55 205
template <class Tuple, class F, size_t... Is>
f8deb5b9 Poul Sander 2022-01-15 13:55 206
void for_each(index_sequence<Is...>, Tuple&& tup, F&& f) FMT_NOEXCEPT {
f8deb5b9 Poul Sander 2022-01-15 13:55 207
  using std::get;
f8deb5b9 Poul Sander 2022-01-15 13:55 208
  // using free function get<I>(T) now.
f8deb5b9 Poul Sander 2022-01-15 13:55 209
  const int _[] = {0, ((void)f(get<Is>(tup)), 0)...};
f8deb5b9 Poul Sander 2022-01-15 13:55 210
  (void)_;  // blocks warnings
f8deb5b9 Poul Sander 2022-01-15 13:55 211
}
f8deb5b9 Poul Sander 2022-01-15 13:55 212
f8deb5b9 Poul Sander 2022-01-15 13:55 213
template <class T>
f8deb5b9 Poul Sander 2022-01-15 13:55 214
FMT_CONSTEXPR make_index_sequence<std::tuple_size<T>::value> get_indexes(
f8deb5b9 Poul Sander 2022-01-15 13:55 215
    T const&) {
f8deb5b9 Poul Sander 2022-01-15 13:55 216
  return {};
f8deb5b9 Poul Sander 2022-01-15 13:55 217
}
f8deb5b9 Poul Sander 2022-01-15 13:55 218
f8deb5b9 Poul Sander 2022-01-15 13:55 219
template <class Tuple, class F> void for_each(Tuple&& tup, F&& f) {
f8deb5b9 Poul Sander 2022-01-15 13:55 220
  const auto indexes = get_indexes(tup);
f8deb5b9 Poul Sander 2022-01-15 13:55 221
  for_each(indexes, std::forward<Tuple>(tup), std::forward<F>(f));
f8deb5b9 Poul Sander 2022-01-15 13:55 222
}
f8deb5b9 Poul Sander 2022-01-15 13:55 223
f8deb5b9 Poul Sander 2022-01-15 13:55 224
template <typename Range>
f8deb5b9 Poul Sander 2022-01-15 13:55 225
using value_type =
f8deb5b9 Poul Sander 2022-01-15 13:55 226
    remove_cvref_t<decltype(*detail::range_begin(std::declval<Range>()))>;
f8deb5b9 Poul Sander 2022-01-15 13:55 227
f8deb5b9 Poul Sander 2022-01-15 13:55 228
template <typename OutputIt> OutputIt write_delimiter(OutputIt out) {
f8deb5b9 Poul Sander 2022-01-15 13:55 229
  *out++ = ',';
f8deb5b9 Poul Sander 2022-01-15 13:55 230
  *out++ = ' ';
f8deb5b9 Poul Sander 2022-01-15 13:55 231
  return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 232
}
f8deb5b9 Poul Sander 2022-01-15 13:55 233
f8deb5b9 Poul Sander 2022-01-15 13:55 234
struct singleton {
f8deb5b9 Poul Sander 2022-01-15 13:55 235
  unsigned char upper;
f8deb5b9 Poul Sander 2022-01-15 13:55 236
  unsigned char lower_count;
f8deb5b9 Poul Sander 2022-01-15 13:55 237
};
f8deb5b9 Poul Sander 2022-01-15 13:55 238
f8deb5b9 Poul Sander 2022-01-15 13:55 239
inline auto is_printable(uint16_t x, const singleton* singletons,
f8deb5b9 Poul Sander 2022-01-15 13:55 240
                         size_t singletons_size,
f8deb5b9 Poul Sander 2022-01-15 13:55 241
                         const unsigned char* singleton_lowers,
f8deb5b9 Poul Sander 2022-01-15 13:55 242
                         const unsigned char* normal, size_t normal_size)
f8deb5b9 Poul Sander 2022-01-15 13:55 243
    -> bool {
f8deb5b9 Poul Sander 2022-01-15 13:55 244
  auto upper = x >> 8;
f8deb5b9 Poul Sander 2022-01-15 13:55 245
  auto lower_start = 0;
f8deb5b9 Poul Sander 2022-01-15 13:55 246
  for (size_t i = 0; i < singletons_size; ++i) {
f8deb5b9 Poul Sander 2022-01-15 13:55 247
    auto s = singletons[i];
f8deb5b9 Poul Sander 2022-01-15 13:55 248
    auto lower_end = lower_start + s.lower_count;
f8deb5b9 Poul Sander 2022-01-15 13:55 249
    if (upper < s.upper) break;
f8deb5b9 Poul Sander 2022-01-15 13:55 250
    if (upper == s.upper) {
f8deb5b9 Poul Sander 2022-01-15 13:55 251
      for (auto j = lower_start; j < lower_end; ++j) {
f8deb5b9 Poul Sander 2022-01-15 13:55 252
        if (singleton_lowers[j] == (x & 0xff)) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 253
      }
f8deb5b9 Poul Sander 2022-01-15 13:55 254
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 255
    lower_start = lower_end;
f8deb5b9 Poul Sander 2022-01-15 13:55 256
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 257
f8deb5b9 Poul Sander 2022-01-15 13:55 258
  auto xsigned = static_cast<int>(x);
f8deb5b9 Poul Sander 2022-01-15 13:55 259
  auto current = true;
f8deb5b9 Poul Sander 2022-01-15 13:55 260
  for (size_t i = 0; i < normal_size; ++i) {
f8deb5b9 Poul Sander 2022-01-15 13:55 261
    auto v = static_cast<int>(normal[i]);
f8deb5b9 Poul Sander 2022-01-15 13:55 262
    auto len = (v & 0x80) != 0 ? (v & 0x7f) << 8 | normal[++i] : v;
f8deb5b9 Poul Sander 2022-01-15 13:55 263
    xsigned -= len;
f8deb5b9 Poul Sander 2022-01-15 13:55 264
    if (xsigned < 0) break;
f8deb5b9 Poul Sander 2022-01-15 13:55 265
    current = !current;
f8deb5b9 Poul Sander 2022-01-15 13:55 266
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 267
  return current;
f8deb5b9 Poul Sander 2022-01-15 13:55 268
}
f8deb5b9 Poul Sander 2022-01-15 13:55 269
f8deb5b9 Poul Sander 2022-01-15 13:55 270
// Returns true iff the code point cp is printable.
f8deb5b9 Poul Sander 2022-01-15 13:55 271
// This code is generated by support/printable.py.
f8deb5b9 Poul Sander 2022-01-15 13:55 272
inline auto is_printable(uint32_t cp) -> bool {
f8deb5b9 Poul Sander 2022-01-15 13:55 273
  static constexpr singleton singletons0[] = {
f8deb5b9 Poul Sander 2022-01-15 13:55 274
      {0x00, 1},  {0x03, 5},  {0x05, 6},  {0x06, 3},  {0x07, 6},  {0x08, 8},
f8deb5b9 Poul Sander 2022-01-15 13:55 275
      {0x09, 17}, {0x0a, 28}, {0x0b, 25}, {0x0c, 20}, {0x0d, 16}, {0x0e, 13},
f8deb5b9 Poul Sander 2022-01-15 13:55 276
      {0x0f, 4},  {0x10, 3},  {0x12, 18}, {0x13, 9},  {0x16, 1},  {0x17, 5},
f8deb5b9 Poul Sander 2022-01-15 13:55 277
      {0x18, 2},  {0x19, 3},  {0x1a, 7},  {0x1c, 2},  {0x1d, 1},  {0x1f, 22},
f8deb5b9 Poul Sander 2022-01-15 13:55 278
      {0x20, 3},  {0x2b, 3},  {0x2c, 2},  {0x2d, 11}, {0x2e, 1},  {0x30, 3},
f8deb5b9 Poul Sander 2022-01-15 13:55 279
      {0x31, 2},  {0x32, 1},  {0xa7, 2},  {0xa9, 2},  {0xaa, 4},  {0xab, 8},
f8deb5b9 Poul Sander 2022-01-15 13:55 280
      {0xfa, 2},  {0xfb, 5},  {0xfd, 4},  {0xfe, 3},  {0xff, 9},
f8deb5b9 Poul Sander 2022-01-15 13:55 281
  };
f8deb5b9 Poul Sander 2022-01-15 13:55 282
  static constexpr unsigned char singletons0_lower[] = {
f8deb5b9 Poul Sander 2022-01-15 13:55 283
      0xad, 0x78, 0x79, 0x8b, 0x8d, 0xa2, 0x30, 0x57, 0x58, 0x8b, 0x8c, 0x90,
f8deb5b9 Poul Sander 2022-01-15 13:55 284
      0x1c, 0x1d, 0xdd, 0x0e, 0x0f, 0x4b, 0x4c, 0xfb, 0xfc, 0x2e, 0x2f, 0x3f,
f8deb5b9 Poul Sander 2022-01-15 13:55 285
      0x5c, 0x5d, 0x5f, 0xb5, 0xe2, 0x84, 0x8d, 0x8e, 0x91, 0x92, 0xa9, 0xb1,
f8deb5b9 Poul Sander 2022-01-15 13:55 286
      0xba, 0xbb, 0xc5, 0xc6, 0xc9, 0xca, 0xde, 0xe4, 0xe5, 0xff, 0x00, 0x04,
f8deb5b9 Poul Sander 2022-01-15 13:55 287
      0x11, 0x12, 0x29, 0x31, 0x34, 0x37, 0x3a, 0x3b, 0x3d, 0x49, 0x4a, 0x5d,
f8deb5b9 Poul Sander 2022-01-15 13:55 288
      0x84, 0x8e, 0x92, 0xa9, 0xb1, 0xb4, 0xba, 0xbb, 0xc6, 0xca, 0xce, 0xcf,
f8deb5b9 Poul Sander 2022-01-15 13:55 289
      0xe4, 0xe5, 0x00, 0x04, 0x0d, 0x0e, 0x11, 0x12, 0x29, 0x31, 0x34, 0x3a,
f8deb5b9 Poul Sander 2022-01-15 13:55 290
      0x3b, 0x45, 0x46, 0x49, 0x4a, 0x5e, 0x64, 0x65, 0x84, 0x91, 0x9b, 0x9d,
f8deb5b9 Poul Sander 2022-01-15 13:55 291
      0xc9, 0xce, 0xcf, 0x0d, 0x11, 0x29, 0x45, 0x49, 0x57, 0x64, 0x65, 0x8d,
f8deb5b9 Poul Sander 2022-01-15 13:55 292
      0x91, 0xa9, 0xb4, 0xba, 0xbb, 0xc5, 0xc9, 0xdf, 0xe4, 0xe5, 0xf0, 0x0d,
f8deb5b9 Poul Sander 2022-01-15 13:55 293
      0x11, 0x45, 0x49, 0x64, 0x65, 0x80, 0x84, 0xb2, 0xbc, 0xbe, 0xbf, 0xd5,
f8deb5b9 Poul Sander 2022-01-15 13:55 294
      0xd7, 0xf0, 0xf1, 0x83, 0x85, 0x8b, 0xa4, 0xa6, 0xbe, 0xbf, 0xc5, 0xc7,
f8deb5b9 Poul Sander 2022-01-15 13:55 295
      0xce, 0xcf, 0xda, 0xdb, 0x48, 0x98, 0xbd, 0xcd, 0xc6, 0xce, 0xcf, 0x49,
f8deb5b9 Poul Sander 2022-01-15 13:55 296
      0x4e, 0x4f, 0x57, 0x59, 0x5e, 0x5f, 0x89, 0x8e, 0x8f, 0xb1, 0xb6, 0xb7,
f8deb5b9 Poul Sander 2022-01-15 13:55 297
      0xbf, 0xc1, 0xc6, 0xc7, 0xd7, 0x11, 0x16, 0x17, 0x5b, 0x5c, 0xf6, 0xf7,
f8deb5b9 Poul Sander 2022-01-15 13:55 298
      0xfe, 0xff, 0x80, 0x0d, 0x6d, 0x71, 0xde, 0xdf, 0x0e, 0x0f, 0x1f, 0x6e,
f8deb5b9 Poul Sander 2022-01-15 13:55 299
      0x6f, 0x1c, 0x1d, 0x5f, 0x7d, 0x7e, 0xae, 0xaf, 0xbb, 0xbc, 0xfa, 0x16,
f8deb5b9 Poul Sander 2022-01-15 13:55 300
      0x17, 0x1e, 0x1f, 0x46, 0x47, 0x4e, 0x4f, 0x58, 0x5a, 0x5c, 0x5e, 0x7e,
f8deb5b9 Poul Sander 2022-01-15 13:55 301
      0x7f, 0xb5, 0xc5, 0xd4, 0xd5, 0xdc, 0xf0, 0xf1, 0xf5, 0x72, 0x73, 0x8f,
f8deb5b9 Poul Sander 2022-01-15 13:55 302
      0x74, 0x75, 0x96, 0x2f, 0x5f, 0x26, 0x2e, 0x2f, 0xa7, 0xaf, 0xb7, 0xbf,
f8deb5b9 Poul Sander 2022-01-15 13:55 303
      0xc7, 0xcf, 0xd7, 0xdf, 0x9a, 0x40, 0x97, 0x98, 0x30, 0x8f, 0x1f, 0xc0,
f8deb5b9 Poul Sander 2022-01-15 13:55 304
      0xc1, 0xce, 0xff, 0x4e, 0x4f, 0x5a, 0x5b, 0x07, 0x08, 0x0f, 0x10, 0x27,
f8deb5b9 Poul Sander 2022-01-15 13:55 305
      0x2f, 0xee, 0xef, 0x6e, 0x6f, 0x37, 0x3d, 0x3f, 0x42, 0x45, 0x90, 0x91,
f8deb5b9 Poul Sander 2022-01-15 13:55 306
      0xfe, 0xff, 0x53, 0x67, 0x75, 0xc8, 0xc9, 0xd0, 0xd1, 0xd8, 0xd9, 0xe7,
f8deb5b9 Poul Sander 2022-01-15 13:55 307
      0xfe, 0xff,
f8deb5b9 Poul Sander 2022-01-15 13:55 308
  };
f8deb5b9 Poul Sander 2022-01-15 13:55 309
  static constexpr singleton singletons1[] = {
f8deb5b9 Poul Sander 2022-01-15 13:55 310
      {0x00, 6},  {0x01, 1}, {0x03, 1},  {0x04, 2}, {0x08, 8},  {0x09, 2},
f8deb5b9 Poul Sander 2022-01-15 13:55 311
      {0x0a, 5},  {0x0b, 2}, {0x0e, 4},  {0x10, 1}, {0x11, 2},  {0x12, 5},
f8deb5b9 Poul Sander 2022-01-15 13:55 312
      {0x13, 17}, {0x14, 1}, {0x15, 2},  {0x17, 2}, {0x19, 13}, {0x1c, 5},
f8deb5b9 Poul Sander 2022-01-15 13:55 313
      {0x1d, 8},  {0x24, 1}, {0x6a, 3},  {0x6b, 2}, {0xbc, 2},  {0xd1, 2},
f8deb5b9 Poul Sander 2022-01-15 13:55 314
      {0xd4, 12}, {0xd5, 9}, {0xd6, 2},  {0xd7, 2}, {0xda, 1},  {0xe0, 5},
f8deb5b9 Poul Sander 2022-01-15 13:55 315
      {0xe1, 2},  {0xe8, 2}, {0xee, 32}, {0xf0, 4}, {0xf8, 2},  {0xf9, 2},
f8deb5b9 Poul Sander 2022-01-15 13:55 316
      {0xfa, 2},  {0xfb, 1},
f8deb5b9 Poul Sander 2022-01-15 13:55 317
  };
f8deb5b9 Poul Sander 2022-01-15 13:55 318
  static constexpr unsigned char singletons1_lower[] = {
f8deb5b9 Poul Sander 2022-01-15 13:55 319
      0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e, 0x9e, 0x9f, 0x06, 0x07,
f8deb5b9 Poul Sander 2022-01-15 13:55 320
      0x09, 0x36, 0x3d, 0x3e, 0x56, 0xf3, 0xd0, 0xd1, 0x04, 0x14, 0x18, 0x36,
f8deb5b9 Poul Sander 2022-01-15 13:55 321
      0x37, 0x56, 0x57, 0x7f, 0xaa, 0xae, 0xaf, 0xbd, 0x35, 0xe0, 0x12, 0x87,
f8deb5b9 Poul Sander 2022-01-15 13:55 322
      0x89, 0x8e, 0x9e, 0x04, 0x0d, 0x0e, 0x11, 0x12, 0x29, 0x31, 0x34, 0x3a,
f8deb5b9 Poul Sander 2022-01-15 13:55 323
      0x45, 0x46, 0x49, 0x4a, 0x4e, 0x4f, 0x64, 0x65, 0x5c, 0xb6, 0xb7, 0x1b,
f8deb5b9 Poul Sander 2022-01-15 13:55 324
      0x1c, 0x07, 0x08, 0x0a, 0x0b, 0x14, 0x17, 0x36, 0x39, 0x3a, 0xa8, 0xa9,
f8deb5b9 Poul Sander 2022-01-15 13:55 325
      0xd8, 0xd9, 0x09, 0x37, 0x90, 0x91, 0xa8, 0x07, 0x0a, 0x3b, 0x3e, 0x66,
f8deb5b9 Poul Sander 2022-01-15 13:55 326
      0x69, 0x8f, 0x92, 0x6f, 0x5f, 0xee, 0xef, 0x5a, 0x62, 0x9a, 0x9b, 0x27,
f8deb5b9 Poul Sander 2022-01-15 13:55 327
      0x28, 0x55, 0x9d, 0xa0, 0xa1, 0xa3, 0xa4, 0xa7, 0xa8, 0xad, 0xba, 0xbc,
f8deb5b9 Poul Sander 2022-01-15 13:55 328
      0xc4, 0x06, 0x0b, 0x0c, 0x15, 0x1d, 0x3a, 0x3f, 0x45, 0x51, 0xa6, 0xa7,
f8deb5b9 Poul Sander 2022-01-15 13:55 329
      0xcc, 0xcd, 0xa0, 0x07, 0x19, 0x1a, 0x22, 0x25, 0x3e, 0x3f, 0xc5, 0xc6,
f8deb5b9 Poul Sander 2022-01-15 13:55 330
      0x04, 0x20, 0x23, 0x25, 0x26, 0x28, 0x33, 0x38, 0x3a, 0x48, 0x4a, 0x4c,
f8deb5b9 Poul Sander 2022-01-15 13:55 331
      0x50, 0x53, 0x55, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x63, 0x65, 0x66,
f8deb5b9 Poul Sander 2022-01-15 13:55 332
      0x6b, 0x73, 0x78, 0x7d, 0x7f, 0x8a, 0xa4, 0xaa, 0xaf, 0xb0, 0xc0, 0xd0,
f8deb5b9 Poul Sander 2022-01-15 13:55 333
      0xae, 0xaf, 0x79, 0xcc, 0x6e, 0x6f, 0x93,
f8deb5b9 Poul Sander 2022-01-15 13:55 334
  };
f8deb5b9 Poul Sander 2022-01-15 13:55 335
  static constexpr unsigned char normal0[] = {
f8deb5b9 Poul Sander 2022-01-15 13:55 336
      0x00, 0x20, 0x5f, 0x22, 0x82, 0xdf, 0x04, 0x82, 0x44, 0x08, 0x1b, 0x04,
f8deb5b9 Poul Sander 2022-01-15 13:55 337
      0x06, 0x11, 0x81, 0xac, 0x0e, 0x80, 0xab, 0x35, 0x28, 0x0b, 0x80, 0xe0,
f8deb5b9 Poul Sander 2022-01-15 13:55 338
      0x03, 0x19, 0x08, 0x01, 0x04, 0x2f, 0x04, 0x34, 0x04, 0x07, 0x03, 0x01,
f8deb5b9 Poul Sander 2022-01-15 13:55 339
      0x07, 0x06, 0x07, 0x11, 0x0a, 0x50, 0x0f, 0x12, 0x07, 0x55, 0x07, 0x03,
f8deb5b9 Poul Sander 2022-01-15 13:55 340
      0x04, 0x1c, 0x0a, 0x09, 0x03, 0x08, 0x03, 0x07, 0x03, 0x02, 0x03, 0x03,
f8deb5b9 Poul Sander 2022-01-15 13:55 341
      0x03, 0x0c, 0x04, 0x05, 0x03, 0x0b, 0x06, 0x01, 0x0e, 0x15, 0x05, 0x3a,
f8deb5b9 Poul Sander 2022-01-15 13:55 342
      0x03, 0x11, 0x07, 0x06, 0x05, 0x10, 0x07, 0x57, 0x07, 0x02, 0x07, 0x15,
f8deb5b9 Poul Sander 2022-01-15 13:55 343
      0x0d, 0x50, 0x04, 0x43, 0x03, 0x2d, 0x03, 0x01, 0x04, 0x11, 0x06, 0x0f,
f8deb5b9 Poul Sander 2022-01-15 13:55 344
      0x0c, 0x3a, 0x04, 0x1d, 0x25, 0x5f, 0x20, 0x6d, 0x04, 0x6a, 0x25, 0x80,
f8deb5b9 Poul Sander 2022-01-15 13:55 345
      0xc8, 0x05, 0x82, 0xb0, 0x03, 0x1a, 0x06, 0x82, 0xfd, 0x03, 0x59, 0x07,
f8deb5b9 Poul Sander 2022-01-15 13:55 346
      0x15, 0x0b, 0x17, 0x09, 0x14, 0x0c, 0x14, 0x0c, 0x6a, 0x06, 0x0a, 0x06,
f8deb5b9 Poul Sander 2022-01-15 13:55 347
      0x1a, 0x06, 0x59, 0x07, 0x2b, 0x05, 0x46, 0x0a, 0x2c, 0x04, 0x0c, 0x04,
f8deb5b9 Poul Sander 2022-01-15 13:55 348
      0x01, 0x03, 0x31, 0x0b, 0x2c, 0x04, 0x1a, 0x06, 0x0b, 0x03, 0x80, 0xac,
f8deb5b9 Poul Sander 2022-01-15 13:55 349
      0x06, 0x0a, 0x06, 0x21, 0x3f, 0x4c, 0x04, 0x2d, 0x03, 0x74, 0x08, 0x3c,
f8deb5b9 Poul Sander 2022-01-15 13:55 350
      0x03, 0x0f, 0x03, 0x3c, 0x07, 0x38, 0x08, 0x2b, 0x05, 0x82, 0xff, 0x11,
f8deb5b9 Poul Sander 2022-01-15 13:55 351
      0x18, 0x08, 0x2f, 0x11, 0x2d, 0x03, 0x20, 0x10, 0x21, 0x0f, 0x80, 0x8c,
f8deb5b9 Poul Sander 2022-01-15 13:55 352
      0x04, 0x82, 0x97, 0x19, 0x0b, 0x15, 0x88, 0x94, 0x05, 0x2f, 0x05, 0x3b,
f8deb5b9 Poul Sander 2022-01-15 13:55 353
      0x07, 0x02, 0x0e, 0x18, 0x09, 0x80, 0xb3, 0x2d, 0x74, 0x0c, 0x80, 0xd6,
f8deb5b9 Poul Sander 2022-01-15 13:55 354
      0x1a, 0x0c, 0x05, 0x80, 0xff, 0x05, 0x80, 0xdf, 0x0c, 0xee, 0x0d, 0x03,
f8deb5b9 Poul Sander 2022-01-15 13:55 355
      0x84, 0x8d, 0x03, 0x37, 0x09, 0x81, 0x5c, 0x14, 0x80, 0xb8, 0x08, 0x80,
f8deb5b9 Poul Sander 2022-01-15 13:55 356
      0xcb, 0x2a, 0x38, 0x03, 0x0a, 0x06, 0x38, 0x08, 0x46, 0x08, 0x0c, 0x06,
f8deb5b9 Poul Sander 2022-01-15 13:55 357
      0x74, 0x0b, 0x1e, 0x03, 0x5a, 0x04, 0x59, 0x09, 0x80, 0x83, 0x18, 0x1c,
f8deb5b9 Poul Sander 2022-01-15 13:55 358
      0x0a, 0x16, 0x09, 0x4c, 0x04, 0x80, 0x8a, 0x06, 0xab, 0xa4, 0x0c, 0x17,
f8deb5b9 Poul Sander 2022-01-15 13:55 359
      0x04, 0x31, 0xa1, 0x04, 0x81, 0xda, 0x26, 0x07, 0x0c, 0x05, 0x05, 0x80,
f8deb5b9 Poul Sander 2022-01-15 13:55 360
      0xa5, 0x11, 0x81, 0x6d, 0x10, 0x78, 0x28, 0x2a, 0x06, 0x4c, 0x04, 0x80,
f8deb5b9 Poul Sander 2022-01-15 13:55 361
      0x8d, 0x04, 0x80, 0xbe, 0x03, 0x1b, 0x03, 0x0f, 0x0d,
f8deb5b9 Poul Sander 2022-01-15 13:55 362
  };
f8deb5b9 Poul Sander 2022-01-15 13:55 363
  static constexpr unsigned char normal1[] = {
f8deb5b9 Poul Sander 2022-01-15 13:55 364
      0x5e, 0x22, 0x7b, 0x05, 0x03, 0x04, 0x2d, 0x03, 0x66, 0x03, 0x01, 0x2f,
f8deb5b9 Poul Sander 2022-01-15 13:55 365
      0x2e, 0x80, 0x82, 0x1d, 0x03, 0x31, 0x0f, 0x1c, 0x04, 0x24, 0x09, 0x1e,
f8deb5b9 Poul Sander 2022-01-15 13:55 366
      0x05, 0x2b, 0x05, 0x44, 0x04, 0x0e, 0x2a, 0x80, 0xaa, 0x06, 0x24, 0x04,
f8deb5b9 Poul Sander 2022-01-15 13:55 367
      0x24, 0x04, 0x28, 0x08, 0x34, 0x0b, 0x01, 0x80, 0x90, 0x81, 0x37, 0x09,
f8deb5b9 Poul Sander 2022-01-15 13:55 368
      0x16, 0x0a, 0x08, 0x80, 0x98, 0x39, 0x03, 0x63, 0x08, 0x09, 0x30, 0x16,
f8deb5b9 Poul Sander 2022-01-15 13:55 369
      0x05, 0x21, 0x03, 0x1b, 0x05, 0x01, 0x40, 0x38, 0x04, 0x4b, 0x05, 0x2f,
f8deb5b9 Poul Sander 2022-01-15 13:55 370
      0x04, 0x0a, 0x07, 0x09, 0x07, 0x40, 0x20, 0x27, 0x04, 0x0c, 0x09, 0x36,
f8deb5b9 Poul Sander 2022-01-15 13:55 371
      0x03, 0x3a, 0x05, 0x1a, 0x07, 0x04, 0x0c, 0x07, 0x50, 0x49, 0x37, 0x33,
f8deb5b9 Poul Sander 2022-01-15 13:55 372
      0x0d, 0x33, 0x07, 0x2e, 0x08, 0x0a, 0x81, 0x26, 0x52, 0x4e, 0x28, 0x08,
f8deb5b9 Poul Sander 2022-01-15 13:55 373
      0x2a, 0x56, 0x1c, 0x14, 0x17, 0x09, 0x4e, 0x04, 0x1e, 0x0f, 0x43, 0x0e,
f8deb5b9 Poul Sander 2022-01-15 13:55 374
      0x19, 0x07, 0x0a, 0x06, 0x48, 0x08, 0x27, 0x09, 0x75, 0x0b, 0x3f, 0x41,
f8deb5b9 Poul Sander 2022-01-15 13:55 375
      0x2a, 0x06, 0x3b, 0x05, 0x0a, 0x06, 0x51, 0x06, 0x01, 0x05, 0x10, 0x03,
f8deb5b9 Poul Sander 2022-01-15 13:55 376
      0x05, 0x80, 0x8b, 0x62, 0x1e, 0x48, 0x08, 0x0a, 0x80, 0xa6, 0x5e, 0x22,
f8deb5b9 Poul Sander 2022-01-15 13:55 377
      0x45, 0x0b, 0x0a, 0x06, 0x0d, 0x13, 0x39, 0x07, 0x0a, 0x36, 0x2c, 0x04,
f8deb5b9 Poul Sander 2022-01-15 13:55 378
      0x10, 0x80, 0xc0, 0x3c, 0x64, 0x53, 0x0c, 0x48, 0x09, 0x0a, 0x46, 0x45,
f8deb5b9 Poul Sander 2022-01-15 13:55 379
      0x1b, 0x48, 0x08, 0x53, 0x1d, 0x39, 0x81, 0x07, 0x46, 0x0a, 0x1d, 0x03,
f8deb5b9 Poul Sander 2022-01-15 13:55 380
      0x47, 0x49, 0x37, 0x03, 0x0e, 0x08, 0x0a, 0x06, 0x39, 0x07, 0x0a, 0x81,
f8deb5b9 Poul Sander 2022-01-15 13:55 381
      0x36, 0x19, 0x80, 0xb7, 0x01, 0x0f, 0x32, 0x0d, 0x83, 0x9b, 0x66, 0x75,
f8deb5b9 Poul Sander 2022-01-15 13:55 382
      0x0b, 0x80, 0xc4, 0x8a, 0xbc, 0x84, 0x2f, 0x8f, 0xd1, 0x82, 0x47, 0xa1,
f8deb5b9 Poul Sander 2022-01-15 13:55 383
      0xb9, 0x82, 0x39, 0x07, 0x2a, 0x04, 0x02, 0x60, 0x26, 0x0a, 0x46, 0x0a,
f8deb5b9 Poul Sander 2022-01-15 13:55 384
      0x28, 0x05, 0x13, 0x82, 0xb0, 0x5b, 0x65, 0x4b, 0x04, 0x39, 0x07, 0x11,
f8deb5b9 Poul Sander 2022-01-15 13:55 385
      0x40, 0x05, 0x0b, 0x02, 0x0e, 0x97, 0xf8, 0x08, 0x84, 0xd6, 0x2a, 0x09,
f8deb5b9 Poul Sander 2022-01-15 13:55 386
      0xa2, 0xf7, 0x81, 0x1f, 0x31, 0x03, 0x11, 0x04, 0x08, 0x81, 0x8c, 0x89,
f8deb5b9 Poul Sander 2022-01-15 13:55 387
      0x04, 0x6b, 0x05, 0x0d, 0x03, 0x09, 0x07, 0x10, 0x93, 0x60, 0x80, 0xf6,
f8deb5b9 Poul Sander 2022-01-15 13:55 388
      0x0a, 0x73, 0x08, 0x6e, 0x17, 0x46, 0x80, 0x9a, 0x14, 0x0c, 0x57, 0x09,
f8deb5b9 Poul Sander 2022-01-15 13:55 389
      0x19, 0x80, 0x87, 0x81, 0x47, 0x03, 0x85, 0x42, 0x0f, 0x15, 0x85, 0x50,
f8deb5b9 Poul Sander 2022-01-15 13:55 390
      0x2b, 0x80, 0xd5, 0x2d, 0x03, 0x1a, 0x04, 0x02, 0x81, 0x70, 0x3a, 0x05,
f8deb5b9 Poul Sander 2022-01-15 13:55 391
      0x01, 0x85, 0x00, 0x80, 0xd7, 0x29, 0x4c, 0x04, 0x0a, 0x04, 0x02, 0x83,
f8deb5b9 Poul Sander 2022-01-15 13:55 392
      0x11, 0x44, 0x4c, 0x3d, 0x80, 0xc2, 0x3c, 0x06, 0x01, 0x04, 0x55, 0x05,
f8deb5b9 Poul Sander 2022-01-15 13:55 393
      0x1b, 0x34, 0x02, 0x81, 0x0e, 0x2c, 0x04, 0x64, 0x0c, 0x56, 0x0a, 0x80,
f8deb5b9 Poul Sander 2022-01-15 13:55 394
      0xae, 0x38, 0x1d, 0x0d, 0x2c, 0x04, 0x09, 0x07, 0x02, 0x0e, 0x06, 0x80,
f8deb5b9 Poul Sander 2022-01-15 13:55 395
      0x9a, 0x83, 0xd8, 0x08, 0x0d, 0x03, 0x0d, 0x03, 0x74, 0x0c, 0x59, 0x07,
f8deb5b9 Poul Sander 2022-01-15 13:55 396
      0x0c, 0x14, 0x0c, 0x04, 0x38, 0x08, 0x0a, 0x06, 0x28, 0x08, 0x22, 0x4e,
f8deb5b9 Poul Sander 2022-01-15 13:55 397
      0x81, 0x54, 0x0c, 0x15, 0x03, 0x03, 0x05, 0x07, 0x09, 0x19, 0x07, 0x07,
f8deb5b9 Poul Sander 2022-01-15 13:55 398
      0x09, 0x03, 0x0d, 0x07, 0x29, 0x80, 0xcb, 0x25, 0x0a, 0x84, 0x06,
f8deb5b9 Poul Sander 2022-01-15 13:55 399
  };
f8deb5b9 Poul Sander 2022-01-15 13:55 400
  auto lower = static_cast<uint16_t>(cp);
f8deb5b9 Poul Sander 2022-01-15 13:55 401
  if (cp < 0x10000) {
f8deb5b9 Poul Sander 2022-01-15 13:55 402
    return is_printable(lower, singletons0,
f8deb5b9 Poul Sander 2022-01-15 13:55 403
                        sizeof(singletons0) / sizeof(*singletons0),
f8deb5b9 Poul Sander 2022-01-15 13:55 404
                        singletons0_lower, normal0, sizeof(normal0));
f8deb5b9 Poul Sander 2022-01-15 13:55 405
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 406
  if (cp < 0x20000) {
f8deb5b9 Poul Sander 2022-01-15 13:55 407
    return is_printable(lower, singletons1,
f8deb5b9 Poul Sander 2022-01-15 13:55 408
                        sizeof(singletons1) / sizeof(*singletons1),
f8deb5b9 Poul Sander 2022-01-15 13:55 409
                        singletons1_lower, normal1, sizeof(normal1));
f8deb5b9 Poul Sander 2022-01-15 13:55 410
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 411
  if (0x2a6de <= cp && cp < 0x2a700) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 412
  if (0x2b735 <= cp && cp < 0x2b740) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 413
  if (0x2b81e <= cp && cp < 0x2b820) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 414
  if (0x2cea2 <= cp && cp < 0x2ceb0) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 415
  if (0x2ebe1 <= cp && cp < 0x2f800) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 416
  if (0x2fa1e <= cp && cp < 0x30000) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 417
  if (0x3134b <= cp && cp < 0xe0100) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 418
  if (0xe01f0 <= cp && cp < 0x110000) return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 419
  return cp < 0x110000;
f8deb5b9 Poul Sander 2022-01-15 13:55 420
}
f8deb5b9 Poul Sander 2022-01-15 13:55 421
f8deb5b9 Poul Sander 2022-01-15 13:55 422
inline auto needs_escape(uint32_t cp) -> bool {
f8deb5b9 Poul Sander 2022-01-15 13:55 423
  return cp < 0x20 || cp == 0x7f || cp == '"' || cp == '\\' ||
f8deb5b9 Poul Sander 2022-01-15 13:55 424
         !is_printable(cp);
f8deb5b9 Poul Sander 2022-01-15 13:55 425
}
f8deb5b9 Poul Sander 2022-01-15 13:55 426
f8deb5b9 Poul Sander 2022-01-15 13:55 427
template <typename Char> struct find_escape_result {
f8deb5b9 Poul Sander 2022-01-15 13:55 428
  const Char* begin;
f8deb5b9 Poul Sander 2022-01-15 13:55 429
  const Char* end;
f8deb5b9 Poul Sander 2022-01-15 13:55 430
  uint32_t cp;
f8deb5b9 Poul Sander 2022-01-15 13:55 431
};
f8deb5b9 Poul Sander 2022-01-15 13:55 432
f8deb5b9 Poul Sander 2022-01-15 13:55 433
template <typename Char>
f8deb5b9 Poul Sander 2022-01-15 13:55 434
auto find_escape(const Char* begin, const Char* end)
f8deb5b9 Poul Sander 2022-01-15 13:55 435
    -> find_escape_result<Char> {
f8deb5b9 Poul Sander 2022-01-15 13:55 436
  for (; begin != end; ++begin) {
f8deb5b9 Poul Sander 2022-01-15 13:55 437
    auto cp = static_cast<typename std::make_unsigned<Char>::type>(*begin);
f8deb5b9 Poul Sander 2022-01-15 13:55 438
    if (sizeof(Char) == 1 && cp >= 0x80) continue;
f8deb5b9 Poul Sander 2022-01-15 13:55 439
    if (needs_escape(cp)) return {begin, begin + 1, cp};
f8deb5b9 Poul Sander 2022-01-15 13:55 440
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 441
  return {begin, nullptr, 0};
f8deb5b9 Poul Sander 2022-01-15 13:55 442
}
f8deb5b9 Poul Sander 2022-01-15 13:55 443
f8deb5b9 Poul Sander 2022-01-15 13:55 444
inline auto find_escape(const char* begin, const char* end)
f8deb5b9 Poul Sander 2022-01-15 13:55 445
    -> find_escape_result<char> {
f8deb5b9 Poul Sander 2022-01-15 13:55 446
  if (!is_utf8()) return find_escape<char>(begin, end);
f8deb5b9 Poul Sander 2022-01-15 13:55 447
  auto result = find_escape_result<char>{end, nullptr, 0};
f8deb5b9 Poul Sander 2022-01-15 13:55 448
  for_each_codepoint(string_view(begin, to_unsigned(end - begin)),
f8deb5b9 Poul Sander 2022-01-15 13:55 449
                     [&](uint32_t cp, string_view sv) {
f8deb5b9 Poul Sander 2022-01-15 13:55 450
                       if (needs_escape(cp)) {
f8deb5b9 Poul Sander 2022-01-15 13:55 451
                         result = {sv.begin(), sv.end(), cp};
f8deb5b9 Poul Sander 2022-01-15 13:55 452
                         return false;
f8deb5b9 Poul Sander 2022-01-15 13:55 453
                       }
f8deb5b9 Poul Sander 2022-01-15 13:55 454
                       return true;
f8deb5b9 Poul Sander 2022-01-15 13:55 455
                     });
f8deb5b9 Poul Sander 2022-01-15 13:55 456
  return result;
f8deb5b9 Poul Sander 2022-01-15 13:55 457
}
f8deb5b9 Poul Sander 2022-01-15 13:55 458
f8deb5b9 Poul Sander 2022-01-15 13:55 459
template <typename Char, typename OutputIt>
f8deb5b9 Poul Sander 2022-01-15 13:55 460
auto write_range_entry(OutputIt out, basic_string_view<Char> str) -> OutputIt {
f8deb5b9 Poul Sander 2022-01-15 13:55 461
  *out++ = '"';
f8deb5b9 Poul Sander 2022-01-15 13:55 462
  auto begin = str.begin(), end = str.end();
f8deb5b9 Poul Sander 2022-01-15 13:55 463
  do {
f8deb5b9 Poul Sander 2022-01-15 13:55 464
    auto escape = find_escape(begin, end);
f8deb5b9 Poul Sander 2022-01-15 13:55 465
    out = copy_str<Char>(begin, escape.begin, out);
f8deb5b9 Poul Sander 2022-01-15 13:55 466
    begin = escape.end;
f8deb5b9 Poul Sander 2022-01-15 13:55 467
    if (!begin) break;
f8deb5b9 Poul Sander 2022-01-15 13:55 468
    auto c = static_cast<Char>(escape.cp);
f8deb5b9 Poul Sander 2022-01-15 13:55 469
    switch (escape.cp) {
f8deb5b9 Poul Sander 2022-01-15 13:55 470
    case '\n':
f8deb5b9 Poul Sander 2022-01-15 13:55 471
      *out++ = '\\';
f8deb5b9 Poul Sander 2022-01-15 13:55 472
      c = 'n';
f8deb5b9 Poul Sander 2022-01-15 13:55 473
      break;
f8deb5b9 Poul Sander 2022-01-15 13:55 474
    case '\r':
f8deb5b9 Poul Sander 2022-01-15 13:55 475
      *out++ = '\\';
f8deb5b9 Poul Sander 2022-01-15 13:55 476
      c = 'r';
f8deb5b9 Poul Sander 2022-01-15 13:55 477
      break;
f8deb5b9 Poul Sander 2022-01-15 13:55 478
    case '\t':
f8deb5b9 Poul Sander 2022-01-15 13:55 479
      *out++ = '\\';
f8deb5b9 Poul Sander 2022-01-15 13:55 480
      c = 't';
f8deb5b9 Poul Sander 2022-01-15 13:55 481
      break;
f8deb5b9 Poul Sander 2022-01-15 13:55 482
    case '"':
f8deb5b9 Poul Sander 2022-01-15 13:55 483
      FMT_FALLTHROUGH;
f8deb5b9 Poul Sander 2022-01-15 13:55 484
    case '\\':
f8deb5b9 Poul Sander 2022-01-15 13:55 485
      *out++ = '\\';
f8deb5b9 Poul Sander 2022-01-15 13:55 486
      break;
f8deb5b9 Poul Sander 2022-01-15 13:55 487
    default:
f8deb5b9 Poul Sander 2022-01-15 13:55 488
      if (is_utf8()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 489
        if (escape.cp < 0x100) {
f8deb5b9 Poul Sander 2022-01-15 13:55 490
          out = format_to(out, "\\x{:02x}", escape.cp);
f8deb5b9 Poul Sander 2022-01-15 13:55 491
          continue;
f8deb5b9 Poul Sander 2022-01-15 13:55 492
        }
f8deb5b9 Poul Sander 2022-01-15 13:55 493
        if (escape.cp < 0x10000) {
f8deb5b9 Poul Sander 2022-01-15 13:55 494
          out = format_to(out, "\\u{:04x}", escape.cp);
f8deb5b9 Poul Sander 2022-01-15 13:55 495
          continue;
f8deb5b9 Poul Sander 2022-01-15 13:55 496
        }
f8deb5b9 Poul Sander 2022-01-15 13:55 497
        if (escape.cp < 0x110000) {
f8deb5b9 Poul Sander 2022-01-15 13:55 498
          out = format_to(out, "\\U{:08x}", escape.cp);
f8deb5b9 Poul Sander 2022-01-15 13:55 499
          continue;
f8deb5b9 Poul Sander 2022-01-15 13:55 500
        }
f8deb5b9 Poul Sander 2022-01-15 13:55 501
      }
f8deb5b9 Poul Sander 2022-01-15 13:55 502
      for (Char escape_char : basic_string_view<Char>(
f8deb5b9 Poul Sander 2022-01-15 13:55 503
               escape.begin, to_unsigned(escape.end - escape.begin))) {
f8deb5b9 Poul Sander 2022-01-15 13:55 504
        out = format_to(
f8deb5b9 Poul Sander 2022-01-15 13:55 505
            out, "\\x{:02x}",
f8deb5b9 Poul Sander 2022-01-15 13:55 506
            static_cast<typename std::make_unsigned<Char>::type>(escape_char));
f8deb5b9 Poul Sander 2022-01-15 13:55 507
      }
f8deb5b9 Poul Sander 2022-01-15 13:55 508
      continue;
f8deb5b9 Poul Sander 2022-01-15 13:55 509
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 510
    *out++ = c;
f8deb5b9 Poul Sander 2022-01-15 13:55 511
  } while (begin != end);
f8deb5b9 Poul Sander 2022-01-15 13:55 512
  *out++ = '"';
f8deb5b9 Poul Sander 2022-01-15 13:55 513
  return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 514
}
f8deb5b9 Poul Sander 2022-01-15 13:55 515
f8deb5b9 Poul Sander 2022-01-15 13:55 516
template <typename Char, typename OutputIt, typename T,
f8deb5b9 Poul Sander 2022-01-15 13:55 517
          FMT_ENABLE_IF(std::is_convertible<T, std_string_view<char>>::value)>
f8deb5b9 Poul Sander 2022-01-15 13:55 518
inline auto write_range_entry(OutputIt out, const T& str) -> OutputIt {
f8deb5b9 Poul Sander 2022-01-15 13:55 519
  auto sv = std_string_view<Char>(str);
f8deb5b9 Poul Sander 2022-01-15 13:55 520
  return write_range_entry<Char>(out, basic_string_view<Char>(sv));
f8deb5b9 Poul Sander 2022-01-15 13:55 521
}
f8deb5b9 Poul Sander 2022-01-15 13:55 522
f8deb5b9 Poul Sander 2022-01-15 13:55 523
template <typename Char, typename OutputIt, typename Arg,
f8deb5b9 Poul Sander 2022-01-15 13:55 524
          FMT_ENABLE_IF(std::is_same<Arg, Char>::value)>
f8deb5b9 Poul Sander 2022-01-15 13:55 525
OutputIt write_range_entry(OutputIt out, const Arg v) {
f8deb5b9 Poul Sander 2022-01-15 13:55 526
  *out++ = '\'';
f8deb5b9 Poul Sander 2022-01-15 13:55 527
  *out++ = v;
f8deb5b9 Poul Sander 2022-01-15 13:55 528
  *out++ = '\'';
f8deb5b9 Poul Sander 2022-01-15 13:55 529
  return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 530
}
f8deb5b9 Poul Sander 2022-01-15 13:55 531
f8deb5b9 Poul Sander 2022-01-15 13:55 532
template <
f8deb5b9 Poul Sander 2022-01-15 13:55 533
    typename Char, typename OutputIt, typename Arg,
f8deb5b9 Poul Sander 2022-01-15 13:55 534
    FMT_ENABLE_IF(!is_std_string_like<typename std::decay<Arg>::type>::value &&
f8deb5b9 Poul Sander 2022-01-15 13:55 535
                  !std::is_same<Arg, Char>::value)>
f8deb5b9 Poul Sander 2022-01-15 13:55 536
OutputIt write_range_entry(OutputIt out, const Arg& v) {
f8deb5b9 Poul Sander 2022-01-15 13:55 537
  return write<Char>(out, v);
f8deb5b9 Poul Sander 2022-01-15 13:55 538
}
f8deb5b9 Poul Sander 2022-01-15 13:55 539
f8deb5b9 Poul Sander 2022-01-15 13:55 540
}  // namespace detail
f8deb5b9 Poul Sander 2022-01-15 13:55 541
f8deb5b9 Poul Sander 2022-01-15 13:55 542
template <typename T> struct is_tuple_like {
f8deb5b9 Poul Sander 2022-01-15 13:55 543
  static FMT_CONSTEXPR_DECL const bool value =
f8deb5b9 Poul Sander 2022-01-15 13:55 544
      detail::is_tuple_like_<T>::value && !detail::is_range_<T>::value;
f8deb5b9 Poul Sander 2022-01-15 13:55 545
};
f8deb5b9 Poul Sander 2022-01-15 13:55 546
f8deb5b9 Poul Sander 2022-01-15 13:55 547
template <typename TupleT, typename Char>
f8deb5b9 Poul Sander 2022-01-15 13:55 548
struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
f8deb5b9 Poul Sander 2022-01-15 13:55 549
 private:
f8deb5b9 Poul Sander 2022-01-15 13:55 550
  // C++11 generic lambda for format().
f8deb5b9 Poul Sander 2022-01-15 13:55 551
  template <typename FormatContext> struct format_each {
f8deb5b9 Poul Sander 2022-01-15 13:55 552
    template <typename T> void operator()(const T& v) {
f8deb5b9 Poul Sander 2022-01-15 13:55 553
      if (i > 0) out = detail::write_delimiter(out);
f8deb5b9 Poul Sander 2022-01-15 13:55 554
      out = detail::write_range_entry<Char>(out, v);
f8deb5b9 Poul Sander 2022-01-15 13:55 555
      ++i;
f8deb5b9 Poul Sander 2022-01-15 13:55 556
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 557
    int i;
f8deb5b9 Poul Sander 2022-01-15 13:55 558
    typename FormatContext::iterator& out;
f8deb5b9 Poul Sander 2022-01-15 13:55 559
  };
f8deb5b9 Poul Sander 2022-01-15 13:55 560
f8deb5b9 Poul Sander 2022-01-15 13:55 561
 public:
f8deb5b9 Poul Sander 2022-01-15 13:55 562
  template <typename ParseContext>
f8deb5b9 Poul Sander 2022-01-15 13:55 563
  FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 564
    return ctx.begin();
f8deb5b9 Poul Sander 2022-01-15 13:55 565
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 566
f8deb5b9 Poul Sander 2022-01-15 13:55 567
  template <typename FormatContext = format_context>
f8deb5b9 Poul Sander 2022-01-15 13:55 568
  auto format(const TupleT& values, FormatContext& ctx) -> decltype(ctx.out()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 569
    auto out = ctx.out();
f8deb5b9 Poul Sander 2022-01-15 13:55 570
    *out++ = '(';
f8deb5b9 Poul Sander 2022-01-15 13:55 571
    detail::for_each(values, format_each<FormatContext>{0, out});
f8deb5b9 Poul Sander 2022-01-15 13:55 572
    *out++ = ')';
f8deb5b9 Poul Sander 2022-01-15 13:55 573
    return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 574
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 575
};
f8deb5b9 Poul Sander 2022-01-15 13:55 576
f8deb5b9 Poul Sander 2022-01-15 13:55 577
template <typename T, typename Char> struct is_range {
f8deb5b9 Poul Sander 2022-01-15 13:55 578
  static FMT_CONSTEXPR_DECL const bool value =
f8deb5b9 Poul Sander 2022-01-15 13:55 579
      detail::is_range_<T>::value && !detail::is_std_string_like<T>::value &&
f8deb5b9 Poul Sander 2022-01-15 13:55 580
      !detail::is_map<T>::value &&
f8deb5b9 Poul Sander 2022-01-15 13:55 581
      !std::is_convertible<T, std::basic_string<Char>>::value &&
f8deb5b9 Poul Sander 2022-01-15 13:55 582
      !std::is_constructible<detail::std_string_view<Char>, T>::value;
f8deb5b9 Poul Sander 2022-01-15 13:55 583
};
f8deb5b9 Poul Sander 2022-01-15 13:55 584
f8deb5b9 Poul Sander 2022-01-15 13:55 585
template <typename T, typename Char>
f8deb5b9 Poul Sander 2022-01-15 13:55 586
struct formatter<
f8deb5b9 Poul Sander 2022-01-15 13:55 587
    T, Char,
f8deb5b9 Poul Sander 2022-01-15 13:55 588
    enable_if_t<
f8deb5b9 Poul Sander 2022-01-15 13:55 589
        fmt::is_range<T, Char>::value
f8deb5b9 Poul Sander 2022-01-15 13:55 590
// Workaround a bug in MSVC 2019 and earlier.
f8deb5b9 Poul Sander 2022-01-15 13:55 591
#if !FMT_MSC_VER
f8deb5b9 Poul Sander 2022-01-15 13:55 592
        && (is_formattable<detail::value_type<T>, Char>::value ||
f8deb5b9 Poul Sander 2022-01-15 13:55 593
            detail::has_fallback_formatter<detail::value_type<T>, Char>::value)
f8deb5b9 Poul Sander 2022-01-15 13:55 594
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 595
        >> {
f8deb5b9 Poul Sander 2022-01-15 13:55 596
  template <typename ParseContext>
f8deb5b9 Poul Sander 2022-01-15 13:55 597
  FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 598
    return ctx.begin();
f8deb5b9 Poul Sander 2022-01-15 13:55 599
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 600
f8deb5b9 Poul Sander 2022-01-15 13:55 601
  template <
f8deb5b9 Poul Sander 2022-01-15 13:55 602
      typename FormatContext, typename U,
f8deb5b9 Poul Sander 2022-01-15 13:55 603
      FMT_ENABLE_IF(
f8deb5b9 Poul Sander 2022-01-15 13:55 604
          std::is_same<U, conditional_t<detail::has_const_begin_end<T>::value,
f8deb5b9 Poul Sander 2022-01-15 13:55 605
                                        const T, T>>::value)>
f8deb5b9 Poul Sander 2022-01-15 13:55 606
  auto format(U& range, FormatContext& ctx) -> decltype(ctx.out()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 607
#ifdef FMT_DEPRECATED_BRACED_RANGES
f8deb5b9 Poul Sander 2022-01-15 13:55 608
    Char prefix = '{';
f8deb5b9 Poul Sander 2022-01-15 13:55 609
    Char postfix = '}';
f8deb5b9 Poul Sander 2022-01-15 13:55 610
#else
f8deb5b9 Poul Sander 2022-01-15 13:55 611
    Char prefix = detail::is_set<T>::value ? '{' : '[';
f8deb5b9 Poul Sander 2022-01-15 13:55 612
    Char postfix = detail::is_set<T>::value ? '}' : ']';
f8deb5b9 Poul Sander 2022-01-15 13:55 613
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 614
    auto out = ctx.out();
f8deb5b9 Poul Sander 2022-01-15 13:55 615
    *out++ = prefix;
f8deb5b9 Poul Sander 2022-01-15 13:55 616
    int i = 0;
f8deb5b9 Poul Sander 2022-01-15 13:55 617
    auto it = std::begin(range);
f8deb5b9 Poul Sander 2022-01-15 13:55 618
    auto end = std::end(range);
f8deb5b9 Poul Sander 2022-01-15 13:55 619
    for (; it != end; ++it) {
f8deb5b9 Poul Sander 2022-01-15 13:55 620
      if (i > 0) out = detail::write_delimiter(out);
f8deb5b9 Poul Sander 2022-01-15 13:55 621
      out = detail::write_range_entry<Char>(out, *it);
f8deb5b9 Poul Sander 2022-01-15 13:55 622
      ++i;
f8deb5b9 Poul Sander 2022-01-15 13:55 623
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 624
    *out++ = postfix;
f8deb5b9 Poul Sander 2022-01-15 13:55 625
    return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 626
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 627
};
f8deb5b9 Poul Sander 2022-01-15 13:55 628
f8deb5b9 Poul Sander 2022-01-15 13:55 629
template <typename T, typename Char>
f8deb5b9 Poul Sander 2022-01-15 13:55 630
struct formatter<
f8deb5b9 Poul Sander 2022-01-15 13:55 631
    T, Char,
f8deb5b9 Poul Sander 2022-01-15 13:55 632
    enable_if_t<
f8deb5b9 Poul Sander 2022-01-15 13:55 633
        detail::is_map<T>::value
f8deb5b9 Poul Sander 2022-01-15 13:55 634
// Workaround a bug in MSVC 2019 and earlier.
f8deb5b9 Poul Sander 2022-01-15 13:55 635
#if !FMT_MSC_VER
f8deb5b9 Poul Sander 2022-01-15 13:55 636
        && (is_formattable<detail::value_type<T>, Char>::value ||
f8deb5b9 Poul Sander 2022-01-15 13:55 637
            detail::has_fallback_formatter<detail::value_type<T>, Char>::value)
f8deb5b9 Poul Sander 2022-01-15 13:55 638
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 639
        >> {
f8deb5b9 Poul Sander 2022-01-15 13:55 640
  template <typename ParseContext>
f8deb5b9 Poul Sander 2022-01-15 13:55 641
  FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 642
    return ctx.begin();
f8deb5b9 Poul Sander 2022-01-15 13:55 643
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 644
f8deb5b9 Poul Sander 2022-01-15 13:55 645
  template <
f8deb5b9 Poul Sander 2022-01-15 13:55 646
      typename FormatContext, typename U,
f8deb5b9 Poul Sander 2022-01-15 13:55 647
      FMT_ENABLE_IF(
f8deb5b9 Poul Sander 2022-01-15 13:55 648
          std::is_same<U, conditional_t<detail::has_const_begin_end<T>::value,
f8deb5b9 Poul Sander 2022-01-15 13:55 649
                                        const T, T>>::value)>
f8deb5b9 Poul Sander 2022-01-15 13:55 650
  auto format(U& map, FormatContext& ctx) -> decltype(ctx.out()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 651
    auto out = ctx.out();
f8deb5b9 Poul Sander 2022-01-15 13:55 652
    *out++ = '{';
f8deb5b9 Poul Sander 2022-01-15 13:55 653
    int i = 0;
f8deb5b9 Poul Sander 2022-01-15 13:55 654
    for (const auto& item : map) {
f8deb5b9 Poul Sander 2022-01-15 13:55 655
      if (i > 0) out = detail::write_delimiter(out);
f8deb5b9 Poul Sander 2022-01-15 13:55 656
      out = detail::write_range_entry<Char>(out, item.first);
f8deb5b9 Poul Sander 2022-01-15 13:55 657
      *out++ = ':';
f8deb5b9 Poul Sander 2022-01-15 13:55 658
      *out++ = ' ';
f8deb5b9 Poul Sander 2022-01-15 13:55 659
      out = detail::write_range_entry<Char>(out, item.second);
f8deb5b9 Poul Sander 2022-01-15 13:55 660
      ++i;
f8deb5b9 Poul Sander 2022-01-15 13:55 661
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 662
    *out++ = '}';
f8deb5b9 Poul Sander 2022-01-15 13:55 663
    return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 664
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 665
};
f8deb5b9 Poul Sander 2022-01-15 13:55 666
f8deb5b9 Poul Sander 2022-01-15 13:55 667
template <typename Char, typename... T> struct tuple_join_view : detail::view {
f8deb5b9 Poul Sander 2022-01-15 13:55 668
  const std::tuple<T...>& tuple;
f8deb5b9 Poul Sander 2022-01-15 13:55 669
  basic_string_view<Char> sep;
f8deb5b9 Poul Sander 2022-01-15 13:55 670
f8deb5b9 Poul Sander 2022-01-15 13:55 671
  tuple_join_view(const std::tuple<T...>& t, basic_string_view<Char> s)
f8deb5b9 Poul Sander 2022-01-15 13:55 672
      : tuple(t), sep{s} {}
f8deb5b9 Poul Sander 2022-01-15 13:55 673
};
f8deb5b9 Poul Sander 2022-01-15 13:55 674
f8deb5b9 Poul Sander 2022-01-15 13:55 675
template <typename Char, typename... T>
f8deb5b9 Poul Sander 2022-01-15 13:55 676
using tuple_arg_join = tuple_join_view<Char, T...>;
f8deb5b9 Poul Sander 2022-01-15 13:55 677
f8deb5b9 Poul Sander 2022-01-15 13:55 678
// Define FMT_TUPLE_JOIN_SPECIFIERS to enable experimental format specifiers
f8deb5b9 Poul Sander 2022-01-15 13:55 679
// support in tuple_join. It is disabled by default because of issues with
f8deb5b9 Poul Sander 2022-01-15 13:55 680
// the dynamic width and precision.
f8deb5b9 Poul Sander 2022-01-15 13:55 681
#ifndef FMT_TUPLE_JOIN_SPECIFIERS
f8deb5b9 Poul Sander 2022-01-15 13:55 682
#  define FMT_TUPLE_JOIN_SPECIFIERS 0
f8deb5b9 Poul Sander 2022-01-15 13:55 683
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 684
f8deb5b9 Poul Sander 2022-01-15 13:55 685
template <typename Char, typename... T>
f8deb5b9 Poul Sander 2022-01-15 13:55 686
struct formatter<tuple_join_view<Char, T...>, Char> {
f8deb5b9 Poul Sander 2022-01-15 13:55 687
  template <typename ParseContext>
f8deb5b9 Poul Sander 2022-01-15 13:55 688
  FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 689
    return do_parse(ctx, std::integral_constant<size_t, sizeof...(T)>());
f8deb5b9 Poul Sander 2022-01-15 13:55 690
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 691
f8deb5b9 Poul Sander 2022-01-15 13:55 692
  template <typename FormatContext>
f8deb5b9 Poul Sander 2022-01-15 13:55 693
  auto format(const tuple_join_view<Char, T...>& value,
f8deb5b9 Poul Sander 2022-01-15 13:55 694
              FormatContext& ctx) const -> typename FormatContext::iterator {
f8deb5b9 Poul Sander 2022-01-15 13:55 695
    return do_format(value, ctx,
f8deb5b9 Poul Sander 2022-01-15 13:55 696
                     std::integral_constant<size_t, sizeof...(T)>());
f8deb5b9 Poul Sander 2022-01-15 13:55 697
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 698
f8deb5b9 Poul Sander 2022-01-15 13:55 699
 private:
f8deb5b9 Poul Sander 2022-01-15 13:55 700
  std::tuple<formatter<typename std::decay<T>::type, Char>...> formatters_;
f8deb5b9 Poul Sander 2022-01-15 13:55 701
f8deb5b9 Poul Sander 2022-01-15 13:55 702
  template <typename ParseContext>
f8deb5b9 Poul Sander 2022-01-15 13:55 703
  FMT_CONSTEXPR auto do_parse(ParseContext& ctx,
f8deb5b9 Poul Sander 2022-01-15 13:55 704
                              std::integral_constant<size_t, 0>)
f8deb5b9 Poul Sander 2022-01-15 13:55 705
      -> decltype(ctx.begin()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 706
    return ctx.begin();
f8deb5b9 Poul Sander 2022-01-15 13:55 707
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 708
f8deb5b9 Poul Sander 2022-01-15 13:55 709
  template <typename ParseContext, size_t N>
f8deb5b9 Poul Sander 2022-01-15 13:55 710
  FMT_CONSTEXPR auto do_parse(ParseContext& ctx,
f8deb5b9 Poul Sander 2022-01-15 13:55 711
                              std::integral_constant<size_t, N>)
f8deb5b9 Poul Sander 2022-01-15 13:55 712
      -> decltype(ctx.begin()) {
f8deb5b9 Poul Sander 2022-01-15 13:55 713
    auto end = ctx.begin();
f8deb5b9 Poul Sander 2022-01-15 13:55 714
#if FMT_TUPLE_JOIN_SPECIFIERS
f8deb5b9 Poul Sander 2022-01-15 13:55 715
    end = std::get<sizeof...(T) - N>(formatters_).parse(ctx);
f8deb5b9 Poul Sander 2022-01-15 13:55 716
    if (N > 1) {
f8deb5b9 Poul Sander 2022-01-15 13:55 717
      auto end1 = do_parse(ctx, std::integral_constant<size_t, N - 1>());
f8deb5b9 Poul Sander 2022-01-15 13:55 718
      if (end != end1)
f8deb5b9 Poul Sander 2022-01-15 13:55 719
        FMT_THROW(format_error("incompatible format specs for tuple elements"));
f8deb5b9 Poul Sander 2022-01-15 13:55 720
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 721
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 722
    return end;
f8deb5b9 Poul Sander 2022-01-15 13:55 723
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 724
f8deb5b9 Poul Sander 2022-01-15 13:55 725
  template <typename FormatContext>
f8deb5b9 Poul Sander 2022-01-15 13:55 726
  auto do_format(const tuple_join_view<Char, T...>&, FormatContext& ctx,
f8deb5b9 Poul Sander 2022-01-15 13:55 727
                 std::integral_constant<size_t, 0>) const ->
f8deb5b9 Poul Sander 2022-01-15 13:55 728
      typename FormatContext::iterator {
f8deb5b9 Poul Sander 2022-01-15 13:55 729
    return ctx.out();
f8deb5b9 Poul Sander 2022-01-15 13:55 730
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 731
f8deb5b9 Poul Sander 2022-01-15 13:55 732
  template <typename FormatContext, size_t N>
f8deb5b9 Poul Sander 2022-01-15 13:55 733
  auto do_format(const tuple_join_view<Char, T...>& value, FormatContext& ctx,
f8deb5b9 Poul Sander 2022-01-15 13:55 734
                 std::integral_constant<size_t, N>) const ->
f8deb5b9 Poul Sander 2022-01-15 13:55 735
      typename FormatContext::iterator {
f8deb5b9 Poul Sander 2022-01-15 13:55 736
    auto out = std::get<sizeof...(T) - N>(formatters_)
f8deb5b9 Poul Sander 2022-01-15 13:55 737
                   .format(std::get<sizeof...(T) - N>(value.tuple), ctx);
f8deb5b9 Poul Sander 2022-01-15 13:55 738
    if (N > 1) {
f8deb5b9 Poul Sander 2022-01-15 13:55 739
      out = std::copy(value.sep.begin(), value.sep.end(), out);
f8deb5b9 Poul Sander 2022-01-15 13:55 740
      ctx.advance_to(out);
f8deb5b9 Poul Sander 2022-01-15 13:55 741
      return do_format(value, ctx, std::integral_constant<size_t, N - 1>());
f8deb5b9 Poul Sander 2022-01-15 13:55 742
    }
f8deb5b9 Poul Sander 2022-01-15 13:55 743
    return out;
f8deb5b9 Poul Sander 2022-01-15 13:55 744
  }
f8deb5b9 Poul Sander 2022-01-15 13:55 745
};
f8deb5b9 Poul Sander 2022-01-15 13:55 746
f8deb5b9 Poul Sander 2022-01-15 13:55 747
FMT_MODULE_EXPORT_BEGIN
f8deb5b9 Poul Sander 2022-01-15 13:55 748
f8deb5b9 Poul Sander 2022-01-15 13:55 749
/**
f8deb5b9 Poul Sander 2022-01-15 13:55 750
  \rst
f8deb5b9 Poul Sander 2022-01-15 13:55 751
  Returns an object that formats `tuple` with elements separated by `sep`.
f8deb5b9 Poul Sander 2022-01-15 13:55 752
f8deb5b9 Poul Sander 2022-01-15 13:55 753
  **Example**::
f8deb5b9 Poul Sander 2022-01-15 13:55 754
f8deb5b9 Poul Sander 2022-01-15 13:55 755
    std::tuple<int, char> t = {1, 'a'};
f8deb5b9 Poul Sander 2022-01-15 13:55 756
    fmt::print("{}", fmt::join(t, ", "));
f8deb5b9 Poul Sander 2022-01-15 13:55 757
    // Output: "1, a"
f8deb5b9 Poul Sander 2022-01-15 13:55 758
  \endrst
f8deb5b9 Poul Sander 2022-01-15 13:55 759
 */
f8deb5b9 Poul Sander 2022-01-15 13:55 760
template <typename... T>
f8deb5b9 Poul Sander 2022-01-15 13:55 761
FMT_CONSTEXPR auto join(const std::tuple<T...>& tuple, string_view sep)
f8deb5b9 Poul Sander 2022-01-15 13:55 762
    -> tuple_join_view<char, T...> {
f8deb5b9 Poul Sander 2022-01-15 13:55 763
  return {tuple, sep};
f8deb5b9 Poul Sander 2022-01-15 13:55 764
}
f8deb5b9 Poul Sander 2022-01-15 13:55 765
f8deb5b9 Poul Sander 2022-01-15 13:55 766
template <typename... T>
f8deb5b9 Poul Sander 2022-01-15 13:55 767
FMT_CONSTEXPR auto join(const std::tuple<T...>& tuple,
f8deb5b9 Poul Sander 2022-01-15 13:55 768
                        basic_string_view<wchar_t> sep)
f8deb5b9 Poul Sander 2022-01-15 13:55 769
    -> tuple_join_view<wchar_t, T...> {
f8deb5b9 Poul Sander 2022-01-15 13:55 770
  return {tuple, sep};
f8deb5b9 Poul Sander 2022-01-15 13:55 771
}
f8deb5b9 Poul Sander 2022-01-15 13:55 772
f8deb5b9 Poul Sander 2022-01-15 13:55 773
/**
f8deb5b9 Poul Sander 2022-01-15 13:55 774
  \rst
f8deb5b9 Poul Sander 2022-01-15 13:55 775
  Returns an object that formats `initializer_list` with elements separated by
f8deb5b9 Poul Sander 2022-01-15 13:55 776
  `sep`.
f8deb5b9 Poul Sander 2022-01-15 13:55 777
f8deb5b9 Poul Sander 2022-01-15 13:55 778
  **Example**::
f8deb5b9 Poul Sander 2022-01-15 13:55 779
f8deb5b9 Poul Sander 2022-01-15 13:55 780
    fmt::print("{}", fmt::join({1, 2, 3}, ", "));
f8deb5b9 Poul Sander 2022-01-15 13:55 781
    // Output: "1, 2, 3"
f8deb5b9 Poul Sander 2022-01-15 13:55 782
  \endrst
f8deb5b9 Poul Sander 2022-01-15 13:55 783
 */
f8deb5b9 Poul Sander 2022-01-15 13:55 784
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 785
auto join(std::initializer_list<T> list, string_view sep)
f8deb5b9 Poul Sander 2022-01-15 13:55 786
    -> join_view<const T*, const T*> {
f8deb5b9 Poul Sander 2022-01-15 13:55 787
  return join(std::begin(list), std::end(list), sep);
f8deb5b9 Poul Sander 2022-01-15 13:55 788
}
f8deb5b9 Poul Sander 2022-01-15 13:55 789
f8deb5b9 Poul Sander 2022-01-15 13:55 790
FMT_MODULE_EXPORT_END
f8deb5b9 Poul Sander 2022-01-15 13:55 791
FMT_END_NAMESPACE
f8deb5b9 Poul Sander 2022-01-15 13:55 792
f8deb5b9 Poul Sander 2022-01-15 13:55 793
#endif  // FMT_RANGES_H_
1970-01-01 00:00 794