Unverified Commit 63cbbf96 authored by Richard Berger's avatar Richard Berger
Browse files

Upgrade embedded fmt library to v7.0.2

parent 6576c4cb
Loading
Loading
Loading
Loading
+66 −62
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
    // From fits in To without any problem.
  } else {
    // From does not always fit in To, resort to a dynamic check.
    if (from < T::min() || from > T::max()) {
    if (from < (T::min)() || from > (T::max)()) {
      // outside range.
      ec = 1;
      return {};
@@ -74,7 +74,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {

  if (F::is_signed && !T::is_signed) {
    // From may be negative, not allowed!
    if (fmt::internal::is_negative(from)) {
    if (fmt::detail::is_negative(from)) {
      ec = 1;
      return {};
    }
@@ -84,7 +84,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
      // yes, From always fits in To.
    } else {
      // from may not fit in To, we have to do a dynamic check
      if (from > static_cast<From>(T::max())) {
      if (from > static_cast<From>((T::max)())) {
        ec = 1;
        return {};
      }
@@ -97,7 +97,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
      // yes, From always fits in To.
    } else {
      // from may not fit in To, we have to do a dynamic check
      if (from > static_cast<From>(T::max())) {
      if (from > static_cast<From>((T::max)())) {
        // outside range.
        ec = 1;
        return {};
@@ -141,7 +141,7 @@ FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {

  // catch the only happy case
  if (std::isfinite(from)) {
    if (from >= T::lowest() && from <= T::max()) {
    if (from >= T::lowest() && from <= (T::max)()) {
      return static_cast<To>(from);
    }
    // not within range.
@@ -195,12 +195,13 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
  }
  // multiply with Factor::num without overflow or underflow
  if (Factor::num != 1) {
    const auto max1 = internal::max_value<IntermediateRep>() / Factor::num;
    const auto max1 = detail::max_value<IntermediateRep>() / Factor::num;
    if (count > max1) {
      ec = 1;
      return {};
    }
    const auto min1 = std::numeric_limits<IntermediateRep>::min() / Factor::num;
    const auto min1 =
        (std::numeric_limits<IntermediateRep>::min)() / Factor::num;
    if (count < min1) {
      ec = 1;
      return {};
@@ -269,7 +270,7 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,

  // multiply with Factor::num without overflow or underflow
  if (Factor::num != 1) {
    constexpr auto max1 = internal::max_value<IntermediateRep>() /
    constexpr auto max1 = detail::max_value<IntermediateRep>() /
                          static_cast<IntermediateRep>(Factor::num);
    if (count > max1) {
      ec = 1;
@@ -306,12 +307,12 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
// Usage: f FMT_NOMACRO()
#define FMT_NOMACRO

namespace internal {
namespace detail {
inline null<> localtime_r FMT_NOMACRO(...) { return null<>(); }
inline null<> localtime_s(...) { return null<>(); }
inline null<> gmtime_r(...) { return null<>(); }
inline null<> gmtime_s(...) { return null<>(); }
}  // namespace internal
}  // namespace detail

// Thread-safe replacement for std::localtime
inline std::tm localtime(std::time_t time) {
@@ -322,22 +323,22 @@ inline std::tm localtime(std::time_t time) {
    dispatcher(std::time_t t) : time_(t) {}

    bool run() {
      using namespace fmt::internal;
      using namespace fmt::detail;
      return handle(localtime_r(&time_, &tm_));
    }

    bool handle(std::tm* tm) { return tm != nullptr; }

    bool handle(internal::null<>) {
      using namespace fmt::internal;
    bool handle(detail::null<>) {
      using namespace fmt::detail;
      return fallback(localtime_s(&tm_, &time_));
    }

    bool fallback(int res) { return res == 0; }

#if !FMT_MSC_VER
    bool fallback(internal::null<>) {
      using namespace fmt::internal;
    bool fallback(detail::null<>) {
      using namespace fmt::detail;
      std::tm* tm = std::localtime(&time_);
      if (tm) tm_ = *tm;
      return tm != nullptr;
@@ -359,21 +360,21 @@ inline std::tm gmtime(std::time_t time) {
    dispatcher(std::time_t t) : time_(t) {}

    bool run() {
      using namespace fmt::internal;
      using namespace fmt::detail;
      return handle(gmtime_r(&time_, &tm_));
    }

    bool handle(std::tm* tm) { return tm != nullptr; }

    bool handle(internal::null<>) {
      using namespace fmt::internal;
    bool handle(detail::null<>) {
      using namespace fmt::detail;
      return fallback(gmtime_s(&tm_, &time_));
    }

    bool fallback(int res) { return res == 0; }

#if !FMT_MSC_VER
    bool fallback(internal::null<>) {
    bool fallback(detail::null<>) {
      std::tm* tm = std::gmtime(&time_);
      if (tm) tm_ = *tm;
      return tm != nullptr;
@@ -386,17 +387,17 @@ inline std::tm gmtime(std::time_t time) {
  return gt.tm_;
}

namespace internal {
inline std::size_t strftime(char* str, std::size_t count, const char* format,
namespace detail {
inline size_t strftime(char* str, size_t count, const char* format,
                       const std::tm* time) {
  return std::strftime(str, count, format, time);
}

inline std::size_t strftime(wchar_t* str, std::size_t count,
                            const wchar_t* format, const std::tm* time) {
inline size_t strftime(wchar_t* str, size_t count, const wchar_t* format,
                       const std::tm* time) {
  return std::wcsftime(str, count, format, time);
}
}  // namespace internal
}  // namespace detail

template <typename Char> struct formatter<std::tm, Char> {
  template <typename ParseContext>
@@ -405,7 +406,7 @@ template <typename Char> struct formatter<std::tm, Char> {
    if (it != ctx.end() && *it == ':') ++it;
    auto end = it;
    while (end != ctx.end() && *end != '}') ++end;
    tm_format.reserve(internal::to_unsigned(end - it + 1));
    tm_format.reserve(detail::to_unsigned(end - it + 1));
    tm_format.append(it, end);
    tm_format.push_back('\0');
    return end;
@@ -414,11 +415,10 @@ template <typename Char> struct formatter<std::tm, Char> {
  template <typename FormatContext>
  auto format(const std::tm& tm, FormatContext& ctx) -> decltype(ctx.out()) {
    basic_memory_buffer<Char> buf;
    std::size_t start = buf.size();
    size_t start = buf.size();
    for (;;) {
      std::size_t size = buf.capacity() - start;
      std::size_t count =
          internal::strftime(&buf[start], size, &tm_format[0], &tm);
      size_t size = buf.capacity() - start;
      size_t count = detail::strftime(&buf[start], size, &tm_format[0], &tm);
      if (count != 0) {
        buf.resize(start + count);
        break;
@@ -430,7 +430,7 @@ template <typename Char> struct formatter<std::tm, Char> {
        // https://github.com/fmtlib/fmt/issues/367
        break;
      }
      const std::size_t MIN_GROWTH = 10;
      const size_t MIN_GROWTH = 10;
      buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
    }
    return std::copy(buf.begin(), buf.end(), ctx.out());
@@ -439,7 +439,7 @@ template <typename Char> struct formatter<std::tm, Char> {
  basic_memory_buffer<Char> tm_format;
};

namespace internal {
namespace detail {
template <typename Period> FMT_CONSTEXPR const char* get_units() {
  return nullptr;
}
@@ -768,19 +768,25 @@ OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
  return format_to(out, std::is_floating_point<Rep>::value ? fp_f : format,
                   val);
}
template <typename Char, typename OutputIt>
OutputIt copy_unit(string_view unit, OutputIt out, Char) {
  return std::copy(unit.begin(), unit.end(), out);
}

template <typename Char, typename Period, typename OutputIt>
OutputIt format_duration_unit(OutputIt out) {
  if (const char* unit = get_units<Period>()) {
    string_view s(unit);
    if (const_check(std::is_same<Char, wchar_t>())) {
      utf8_to_utf16 u(s);
template <typename OutputIt>
OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) {
  // This works when wchar_t is UTF-32 because units only contain characters
  // that have the same representation in UTF-16 and UTF-32.
  utf8_to_utf16 u(unit);
  return std::copy(u.c_str(), u.c_str() + u.size(), out);
}
    return std::copy(s.begin(), s.end(), out);
  }

template <typename Char, typename Period, typename OutputIt>
OutputIt format_duration_unit(OutputIt out) {
  if (const char* unit = get_units<Period>())
    return copy_unit(string_view(unit), out, Char());
  const Char num_f[] = {'[', '{', '}', ']', 's', 0};
  if (Period::den == 1) return format_to(out, num_f, Period::num);
  if (const_check(Period::den == 1)) return format_to(out, num_f, Period::num);
  const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0};
  return format_to(out, num_def_f, Period::num, Period::den);
}
@@ -874,9 +880,9 @@ struct chrono_formatter {
    if (isnan(value)) return write_nan();
    uint32_or_64_or_128_t<int> n =
        to_unsigned(to_nonnegative_int(value, max_value<int>()));
    int num_digits = internal::count_digits(n);
    int num_digits = detail::count_digits(n);
    if (width > num_digits) out = std::fill_n(out, width - num_digits, '0');
    out = format_decimal<char_type>(out, n, num_digits);
    out = format_decimal<char_type>(out, n, num_digits).end;
  }

  void write_nan() { std::copy_n("nan", 3, out); }
@@ -1004,14 +1010,14 @@ struct chrono_formatter {
    out = format_duration_unit<char_type, Period>(out);
  }
};
}  // namespace internal
}  // namespace detail

template <typename Rep, typename Period, typename Char>
struct formatter<std::chrono::duration<Rep, Period>, Char> {
 private:
  basic_format_specs<Char> specs;
  int precision;
  using arg_ref_type = internal::arg_ref<Char>;
  using arg_ref_type = detail::arg_ref<Char>;
  arg_ref_type width_ref;
  arg_ref_type precision_ref;
  mutable basic_string_view<Char> format_str;
@@ -1032,7 +1038,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
      return arg_ref_type(arg_id);
    }

    FMT_CONSTEXPR arg_ref_type make_arg_ref(internal::auto_id) {
    FMT_CONSTEXPR arg_ref_type make_arg_ref(detail::auto_id) {
      return arg_ref_type(context.next_arg_id());
    }

@@ -1062,17 +1068,17 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
    auto begin = ctx.begin(), end = ctx.end();
    if (begin == end || *begin == '}') return {begin, begin};
    spec_handler handler{*this, ctx, format_str};
    begin = internal::parse_align(begin, end, handler);
    begin = detail::parse_align(begin, end, handler);
    if (begin == end) return {begin, begin};
    begin = internal::parse_width(begin, end, handler);
    begin = detail::parse_width(begin, end, handler);
    if (begin == end) return {begin, begin};
    if (*begin == '.') {
      if (std::is_floating_point<Rep>::value)
        begin = internal::parse_precision(begin, end, handler);
        begin = detail::parse_precision(begin, end, handler);
      else
        handler.on_error("precision not allowed for this argument type");
    }
    end = parse_chrono_format(begin, end, internal::chrono_format_checker());
    end = parse_chrono_format(begin, end, detail::chrono_format_checker());
    return {begin, end};
  }

@@ -1083,7 +1089,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
      -> decltype(ctx.begin()) {
    auto range = do_parse(ctx);
    format_str = basic_string_view<Char>(
        &*range.begin, internal::to_unsigned(range.end - range.begin));
        &*range.begin, detail::to_unsigned(range.end - range.begin));
    return range.end;
  }

@@ -1094,23 +1100,21 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
    // is not specified.
    basic_memory_buffer<Char> buf;
    auto out = std::back_inserter(buf);
    using range = internal::output_range<decltype(ctx.out()), Char>;
    internal::basic_writer<range> w(range(ctx.out()));
    internal::handle_dynamic_spec<internal::width_checker>(specs.width,
                                                           width_ref, ctx);
    internal::handle_dynamic_spec<internal::precision_checker>(
        precision, precision_ref, ctx);
    detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref,
                                                       ctx);
    detail::handle_dynamic_spec<detail::precision_checker>(precision,
                                                           precision_ref, ctx);
    if (begin == end || *begin == '}') {
      out = internal::format_duration_value<Char>(out, d.count(), precision);
      internal::format_duration_unit<Char, Period>(out);
      out = detail::format_duration_value<Char>(out, d.count(), precision);
      detail::format_duration_unit<Char, Period>(out);
    } else {
      internal::chrono_formatter<FormatContext, decltype(out), Rep, Period> f(
      detail::chrono_formatter<FormatContext, decltype(out), Rep, Period> f(
          ctx, out, d);
      f.precision = precision;
      parse_chrono_format(begin, end, f);
    }
    w.write(buf.data(), buf.size(), specs);
    return w.out();
    return detail::write(
        ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
  }
};

+35 −37
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ struct rgb {
  uint8_t b;
};

namespace internal {
namespace detail {

// color is a struct of either a rgb color or a terminal color.
struct color_type {
@@ -221,7 +221,7 @@ struct color_type {
    uint32_t rgb_color;
  } value;
};
}  // namespace internal
}  // namespace detail

// Experimental text formatting support.
class text_style {
@@ -298,11 +298,11 @@ class text_style {
  FMT_CONSTEXPR bool has_emphasis() const FMT_NOEXCEPT {
    return static_cast<uint8_t>(ems) != 0;
  }
  FMT_CONSTEXPR internal::color_type get_foreground() const FMT_NOEXCEPT {
  FMT_CONSTEXPR detail::color_type get_foreground() const FMT_NOEXCEPT {
    FMT_ASSERT(has_foreground(), "no foreground specified for this style");
    return foreground_color;
  }
  FMT_CONSTEXPR internal::color_type get_background() const FMT_NOEXCEPT {
  FMT_CONSTEXPR detail::color_type get_background() const FMT_NOEXCEPT {
    FMT_ASSERT(has_background(), "no background specified for this style");
    return background_color;
  }
@@ -313,7 +313,7 @@ class text_style {

 private:
  FMT_CONSTEXPR text_style(bool is_foreground,
                           internal::color_type text_color) FMT_NOEXCEPT
                           detail::color_type text_color) FMT_NOEXCEPT
      : set_foreground_color(),
        set_background_color(),
        ems() {
@@ -326,23 +326,23 @@ class text_style {
    }
  }

  friend FMT_CONSTEXPR_DECL text_style fg(internal::color_type foreground)
  friend FMT_CONSTEXPR_DECL text_style fg(detail::color_type foreground)
      FMT_NOEXCEPT;
  friend FMT_CONSTEXPR_DECL text_style bg(internal::color_type background)
  friend FMT_CONSTEXPR_DECL text_style bg(detail::color_type background)
      FMT_NOEXCEPT;

  internal::color_type foreground_color;
  internal::color_type background_color;
  detail::color_type foreground_color;
  detail::color_type background_color;
  bool set_foreground_color;
  bool set_background_color;
  emphasis ems;
};

FMT_CONSTEXPR text_style fg(internal::color_type foreground) FMT_NOEXCEPT {
FMT_CONSTEXPR text_style fg(detail::color_type foreground) FMT_NOEXCEPT {
  return text_style(/*is_foreground=*/true, foreground);
}

FMT_CONSTEXPR text_style bg(internal::color_type background) FMT_NOEXCEPT {
FMT_CONSTEXPR text_style bg(detail::color_type background) FMT_NOEXCEPT {
  return text_style(/*is_foreground=*/false, background);
}

@@ -350,21 +350,21 @@ FMT_CONSTEXPR text_style operator|(emphasis lhs, emphasis rhs) FMT_NOEXCEPT {
  return text_style(lhs) | rhs;
}

namespace internal {
namespace detail {

template <typename Char> struct ansi_color_escape {
  FMT_CONSTEXPR ansi_color_escape(internal::color_type text_color,
  FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color,
                                  const char* esc) FMT_NOEXCEPT {
    // If we have a terminal color, we need to output another escape code
    // sequence.
    if (!text_color.is_rgb) {
      bool is_background = esc == internal::data::background_color;
      bool is_background = esc == detail::data::background_color;
      uint32_t value = text_color.value.term_color;
      // Background ASCII codes are the same as the foreground ones but with
      // 10 more.
      if (is_background) value += 10u;

      std::size_t index = 0;
      size_t index = 0;
      buffer[index++] = static_cast<Char>('\x1b');
      buffer[index++] = static_cast<Char>('[');

@@ -398,7 +398,7 @@ template <typename Char> struct ansi_color_escape {
    if (em_bits & static_cast<uint8_t>(emphasis::strikethrough))
      em_codes[3] = 9;

    std::size_t index = 0;
    size_t index = 0;
    for (int i = 0; i < 4; ++i) {
      if (!em_codes[i]) continue;
      buffer[index++] = static_cast<Char>('\x1b');
@@ -429,14 +429,14 @@ template <typename Char> struct ansi_color_escape {

template <typename Char>
FMT_CONSTEXPR ansi_color_escape<Char> make_foreground_color(
    internal::color_type foreground) FMT_NOEXCEPT {
  return ansi_color_escape<Char>(foreground, internal::data::foreground_color);
    detail::color_type foreground) FMT_NOEXCEPT {
  return ansi_color_escape<Char>(foreground, detail::data::foreground_color);
}

template <typename Char>
FMT_CONSTEXPR ansi_color_escape<Char> make_background_color(
    internal::color_type background) FMT_NOEXCEPT {
  return ansi_color_escape<Char>(background, internal::data::background_color);
    detail::color_type background) FMT_NOEXCEPT {
  return ansi_color_escape<Char>(background, detail::data::background_color);
}

template <typename Char>
@@ -455,11 +455,11 @@ inline void fputs<wchar_t>(const wchar_t* chars, FILE* stream) FMT_NOEXCEPT {
}

template <typename Char> inline void reset_color(FILE* stream) FMT_NOEXCEPT {
  fputs(internal::data::reset_color, stream);
  fputs(detail::data::reset_color, stream);
}

template <> inline void reset_color<wchar_t>(FILE* stream) FMT_NOEXCEPT {
  fputs(internal::data::wreset_color, stream);
  fputs(detail::data::wreset_color, stream);
}

template <typename Char>
@@ -476,33 +476,31 @@ void vformat_to(basic_memory_buffer<Char>& buf, const text_style& ts,
  bool has_style = false;
  if (ts.has_emphasis()) {
    has_style = true;
    auto emphasis = internal::make_emphasis<Char>(ts.get_emphasis());
    auto emphasis = detail::make_emphasis<Char>(ts.get_emphasis());
    buf.append(emphasis.begin(), emphasis.end());
  }
  if (ts.has_foreground()) {
    has_style = true;
    auto foreground =
        internal::make_foreground_color<Char>(ts.get_foreground());
    auto foreground = detail::make_foreground_color<Char>(ts.get_foreground());
    buf.append(foreground.begin(), foreground.end());
  }
  if (ts.has_background()) {
    has_style = true;
    auto background =
        internal::make_background_color<Char>(ts.get_background());
    auto background = detail::make_background_color<Char>(ts.get_background());
    buf.append(background.begin(), background.end());
  }
  internal::vformat_to(buf, format_str, args);
  if (has_style) internal::reset_color<Char>(buf);
  detail::vformat_to(buf, format_str, args);
  if (has_style) detail::reset_color<Char>(buf);
}
}  // namespace internal
}  // namespace detail

template <typename S, typename Char = char_t<S>>
void vprint(std::FILE* f, const text_style& ts, const S& format,
            basic_format_args<buffer_context<Char>> args) {
  basic_memory_buffer<Char> buf;
  internal::vformat_to(buf, ts, to_string_view(format), args);
  detail::vformat_to(buf, ts, to_string_view(format), args);
  buf.push_back(Char(0));
  internal::fputs(buf.data(), f);
  detail::fputs(buf.data(), f);
}

/**
@@ -513,10 +511,10 @@ void vprint(std::FILE* f, const text_style& ts, const S& format,
               "Elapsed time: {0:.2f} seconds", 1.23);
 */
template <typename S, typename... Args,
          FMT_ENABLE_IF(internal::is_string<S>::value)>
          FMT_ENABLE_IF(detail::is_string<S>::value)>
void print(std::FILE* f, const text_style& ts, const S& format_str,
           const Args&... args) {
  internal::check_format_string<Args...>(format_str);
  detail::check_format_string<Args...>(format_str);
  using context = buffer_context<char_t<S>>;
  format_arg_store<context, Args...> as{args...};
  vprint(f, ts, format_str, basic_format_args<context>(as));
@@ -530,7 +528,7 @@ void print(std::FILE* f, const text_style& ts, const S& format_str,
               "Elapsed time: {0:.2f} seconds", 1.23);
 */
template <typename S, typename... Args,
          FMT_ENABLE_IF(internal::is_string<S>::value)>
          FMT_ENABLE_IF(detail::is_string<S>::value)>
void print(const text_style& ts, const S& format_str, const Args&... args) {
  return print(stdout, ts, format_str, args...);
}
@@ -540,7 +538,7 @@ inline std::basic_string<Char> vformat(
    const text_style& ts, const S& format_str,
    basic_format_args<buffer_context<type_identity_t<Char>>> args) {
  basic_memory_buffer<Char> buf;
  internal::vformat_to(buf, ts, to_string_view(format_str), args);
  detail::vformat_to(buf, ts, to_string_view(format_str), args);
  return fmt::to_string(buf);
}

@@ -560,7 +558,7 @@ template <typename S, typename... Args, typename Char = char_t<S>>
inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
                                      const Args&... args) {
  return vformat(ts, to_string_view(format_str),
                 internal::make_args_checked<Args...>(format_str, args...));
                 detail::make_args_checked<Args...>(format_str, args...));
}

FMT_END_NAMESPACE
+173 −103

File changed.

Preview size limit exceeded, changes collapsed.

+527 −441

File changed.

Preview size limit exceeded, changes collapsed.

+114 −64

File changed.

Preview size limit exceeded, changes collapsed.

Loading