mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Bump fmt to 6.1.2
This commit is contained in:
parent
0f8f510ebb
commit
175741ed1d
@ -696,7 +696,7 @@ inline int to_nonnegative_int(T value, int upper) {
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
inline T mod(T x, int y) {
|
||||
return x % y;
|
||||
return x % static_cast<T>(y);
|
||||
}
|
||||
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
||||
inline T mod(T x, int y) {
|
||||
@ -793,7 +793,10 @@ struct chrono_formatter {
|
||||
|
||||
explicit chrono_formatter(FormatContext& ctx, OutputIt o,
|
||||
std::chrono::duration<Rep, Period> d)
|
||||
: context(ctx), out(o), val(d.count()), negative(false) {
|
||||
: context(ctx),
|
||||
out(o),
|
||||
val(static_cast<rep>(d.count())),
|
||||
negative(false) {
|
||||
if (d.count() < 0) {
|
||||
val = 0 - val;
|
||||
negative = true;
|
||||
@ -1023,8 +1026,8 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
|
||||
void on_error(const char* msg) { FMT_THROW(format_error(msg)); }
|
||||
void on_fill(Char fill) { f.specs.fill[0] = fill; }
|
||||
void on_align(align_t align) { f.specs.align = align; }
|
||||
void on_width(unsigned width) { f.specs.width = width; }
|
||||
void on_precision(unsigned _precision) { f.precision = _precision; }
|
||||
void on_width(int width) { f.specs.width = width; }
|
||||
void on_precision(int _precision) { f.precision = _precision; }
|
||||
void end_precision() {}
|
||||
|
||||
template <typename Id> void on_dynamic_width(Id arg_id) {
|
||||
|
@ -26,11 +26,11 @@ template <typename Char> struct format_part {
|
||||
|
||||
kind part_kind;
|
||||
union value {
|
||||
unsigned arg_index;
|
||||
int arg_index;
|
||||
basic_string_view<Char> str;
|
||||
replacement repl;
|
||||
|
||||
FMT_CONSTEXPR value(unsigned index = 0) : arg_index(index) {}
|
||||
FMT_CONSTEXPR value(int index = 0) : arg_index(index) {}
|
||||
FMT_CONSTEXPR value(basic_string_view<Char> s) : str(s) {}
|
||||
FMT_CONSTEXPR value(replacement r) : repl(r) {}
|
||||
} val;
|
||||
@ -40,7 +40,7 @@ template <typename Char> struct format_part {
|
||||
FMT_CONSTEXPR format_part(kind k = kind::arg_index, value v = {})
|
||||
: part_kind(k), val(v) {}
|
||||
|
||||
static FMT_CONSTEXPR format_part make_arg_index(unsigned index) {
|
||||
static FMT_CONSTEXPR format_part make_arg_index(int index) {
|
||||
return format_part(kind::arg_index, index);
|
||||
}
|
||||
static FMT_CONSTEXPR format_part make_arg_name(basic_string_view<Char> name) {
|
||||
@ -62,7 +62,7 @@ template <typename Char> struct part_counter {
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR void on_arg_id() { ++num_parts; }
|
||||
FMT_CONSTEXPR void on_arg_id(unsigned) { ++num_parts; }
|
||||
FMT_CONSTEXPR void on_arg_id(int) { ++num_parts; }
|
||||
FMT_CONSTEXPR void on_arg_id(basic_string_view<Char>) { ++num_parts; }
|
||||
|
||||
FMT_CONSTEXPR void on_replacement_field(const Char*) {}
|
||||
@ -119,7 +119,7 @@ class format_string_compiler : public error_handler {
|
||||
part_ = part::make_arg_index(parse_context_.next_arg_id());
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR void on_arg_id(unsigned id) {
|
||||
FMT_CONSTEXPR void on_arg_id(int id) {
|
||||
parse_context_.check_arg_id(id);
|
||||
part_ = part::make_arg_index(id);
|
||||
}
|
||||
@ -512,8 +512,6 @@ template <typename CompiledFormat, typename... Args,
|
||||
CompiledFormat>::value)>
|
||||
std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
|
||||
basic_memory_buffer<Char> buffer;
|
||||
using range = buffer_range<Char>;
|
||||
using context = buffer_context<Char>;
|
||||
cf.format(std::back_inserter(buffer), args...);
|
||||
return to_string(buffer);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
// The fmt library version in the form major * 10000 + minor * 100 + patch.
|
||||
#define FMT_VERSION 60101
|
||||
#define FMT_VERSION 60102
|
||||
|
||||
#ifdef __has_feature
|
||||
# define FMT_HAS_FEATURE(x) __has_feature(x)
|
||||
@ -878,7 +878,7 @@ template <typename Context> struct arg_mapper {
|
||||
FMT_ENABLE_IF(
|
||||
std::is_constructible<std_string_view<char_type>, T>::value &&
|
||||
!std::is_constructible<basic_string_view<char_type>, T>::value &&
|
||||
!is_string<T>::value)>
|
||||
!is_string<T>::value && !has_formatter<T, Context>::value)>
|
||||
FMT_CONSTEXPR basic_string_view<char_type> map(const T& val) {
|
||||
return std_string_view<char_type>(val);
|
||||
}
|
||||
@ -911,12 +911,14 @@ template <typename Context> struct arg_mapper {
|
||||
map(static_cast<typename std::underlying_type<T>::type>(val))) {
|
||||
return map(static_cast<typename std::underlying_type<T>::type>(val));
|
||||
}
|
||||
template <typename T,
|
||||
FMT_ENABLE_IF(!is_string<T>::value && !is_char<T>::value &&
|
||||
!std::is_constructible<basic_string_view<char_type>,
|
||||
T>::value &&
|
||||
(has_formatter<T, Context>::value ||
|
||||
has_fallback_formatter<T, Context>::value))>
|
||||
template <
|
||||
typename T,
|
||||
FMT_ENABLE_IF(
|
||||
!is_string<T>::value && !is_char<T>::value &&
|
||||
!std::is_constructible<basic_string_view<char_type>, T>::value &&
|
||||
(has_formatter<T, Context>::value ||
|
||||
(has_fallback_formatter<T, Context>::value &&
|
||||
!std::is_constructible<std_string_view<char_type>, T>::value)))>
|
||||
FMT_CONSTEXPR const T& map(const T& val) {
|
||||
return val;
|
||||
}
|
||||
@ -1283,7 +1285,7 @@ template <typename Context> class basic_format_args {
|
||||
*/
|
||||
template <typename... Args>
|
||||
basic_format_args(const format_arg_store<Context, Args...>& store)
|
||||
: types_(static_cast<unsigned long long>(store.types)) {
|
||||
: types_(store.types) {
|
||||
set_data(store.data_);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,8 @@
|
||||
# define FMT_HAS_BUILTIN(x) 0
|
||||
#endif
|
||||
|
||||
#if FMT_HAS_CPP_ATTRIBUTE(fallthrough) >= 201603 && __cplusplus >= 201703
|
||||
#if FMT_HAS_CPP_ATTRIBUTE(fallthrough) && \
|
||||
(__cplusplus >= 201703 || FMT_GCC_VERSION != 0)
|
||||
# define FMT_FALLTHROUGH [[fallthrough]]
|
||||
#else
|
||||
# define FMT_FALLTHROUGH
|
||||
@ -801,60 +802,6 @@ template <> int count_digits<4>(internal::fallback_uintptr n);
|
||||
# define FMT_ALWAYS_INLINE
|
||||
#endif
|
||||
|
||||
// Computes g = floor(log10(n)) and calls h.on<g>(n);
|
||||
template <typename Handler> FMT_ALWAYS_INLINE char* lg(uint32_t n, Handler h) {
|
||||
return n < 100 ? n < 10 ? h.template on<0>(n) : h.template on<1>(n)
|
||||
: n < 1000000
|
||||
? n < 10000 ? n < 1000 ? h.template on<2>(n)
|
||||
: h.template on<3>(n)
|
||||
: n < 100000 ? h.template on<4>(n)
|
||||
: h.template on<5>(n)
|
||||
: n < 100000000 ? n < 10000000 ? h.template on<6>(n)
|
||||
: h.template on<7>(n)
|
||||
: n < 1000000000 ? h.template on<8>(n)
|
||||
: h.template on<9>(n);
|
||||
}
|
||||
|
||||
// An lg handler that formats a decimal number.
|
||||
// Usage: lg(n, decimal_formatter(buffer));
|
||||
class decimal_formatter {
|
||||
private:
|
||||
char* buffer_;
|
||||
|
||||
void write_pair(unsigned N, uint32_t index) {
|
||||
std::memcpy(buffer_ + N, data::digits + index * 2, 2);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit decimal_formatter(char* buf) : buffer_(buf) {}
|
||||
|
||||
template <unsigned N> char* on(uint32_t u) {
|
||||
if (N == 0) {
|
||||
*buffer_ = static_cast<char>(u) + '0';
|
||||
} else if (N == 1) {
|
||||
write_pair(0, u);
|
||||
} else {
|
||||
// The idea of using 4.32 fixed-point numbers is based on
|
||||
// https://github.com/jeaiii/itoa
|
||||
unsigned n = N - 1;
|
||||
unsigned a = n / 5 * n * 53 / 16;
|
||||
uint64_t t =
|
||||
((1ULL << (32 + a)) / data::zero_or_powers_of_10_32[n] + 1 - n / 9);
|
||||
t = ((t * u) >> a) + n / 5 * 4;
|
||||
write_pair(0, t >> 32);
|
||||
for (unsigned i = 2; i < N; i += 2) {
|
||||
t = 100ULL * static_cast<uint32_t>(t);
|
||||
write_pair(i, t >> 32);
|
||||
}
|
||||
if (N % 2 == 0) {
|
||||
buffer_[N] =
|
||||
static_cast<char>((10ULL * static_cast<uint32_t>(t)) >> 32) + '0';
|
||||
}
|
||||
}
|
||||
return buffer_ += N + 1;
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef FMT_BUILTIN_CLZ
|
||||
// Optional version of count_digits for better performance on 32-bit platforms.
|
||||
inline int count_digits(uint32_t n) {
|
||||
@ -2620,7 +2567,7 @@ class format_string_checker {
|
||||
public:
|
||||
explicit FMT_CONSTEXPR format_string_checker(
|
||||
basic_string_view<Char> format_str, ErrorHandler eh)
|
||||
: arg_id_(max_value<unsigned>()),
|
||||
: arg_id_(-1),
|
||||
context_(format_str, eh),
|
||||
parse_funcs_{&parse_format_specs<Args, parse_context_type>...} {}
|
||||
|
||||
@ -2661,7 +2608,7 @@ class format_string_checker {
|
||||
// Format specifier parsing function.
|
||||
using parse_func = const Char* (*)(parse_context_type&);
|
||||
|
||||
unsigned arg_id_;
|
||||
int arg_id_;
|
||||
parse_context_type context_;
|
||||
parse_func parse_funcs_[num_args > 0 ? num_args : 1];
|
||||
};
|
||||
|
@ -333,12 +333,12 @@ template <typename OutputIt, typename Char> class basic_printf_context {
|
||||
static void parse_flags(format_specs& specs, const Char*& it,
|
||||
const Char* end);
|
||||
|
||||
// Returns the argument with specified index or, if arg_index is equal
|
||||
// to the maximum unsigned value, the next argument.
|
||||
format_arg get_arg(unsigned arg_index = internal::max_value<unsigned>());
|
||||
// Returns the argument with specified index or, if arg_index is -1, the next
|
||||
// argument.
|
||||
format_arg get_arg(int arg_index = -1);
|
||||
|
||||
// Parses argument index, flags and width and returns the argument index.
|
||||
unsigned parse_header(const Char*& it, const Char* end, format_specs& specs);
|
||||
int parse_header(const Char*& it, const Char* end, format_specs& specs);
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -355,7 +355,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
|
||||
OutputIt out() { return out_; }
|
||||
void advance_to(OutputIt it) { out_ = it; }
|
||||
|
||||
format_arg arg(unsigned id) const { return args_.get(id); }
|
||||
format_arg arg(int id) const { return args_.get(id); }
|
||||
|
||||
basic_format_parse_context<Char>& parse_context() { return parse_ctx_; }
|
||||
|
||||
@ -397,8 +397,8 @@ void basic_printf_context<OutputIt, Char>::parse_flags(format_specs& specs,
|
||||
|
||||
template <typename OutputIt, typename Char>
|
||||
typename basic_printf_context<OutputIt, Char>::format_arg
|
||||
basic_printf_context<OutputIt, Char>::get_arg(unsigned arg_index) {
|
||||
if (arg_index == internal::max_value<unsigned>())
|
||||
basic_printf_context<OutputIt, Char>::get_arg(int arg_index) {
|
||||
if (arg_index < 0)
|
||||
arg_index = parse_ctx_.next_arg_id();
|
||||
else
|
||||
parse_ctx_.check_arg_id(--arg_index);
|
||||
@ -406,15 +406,15 @@ basic_printf_context<OutputIt, Char>::get_arg(unsigned arg_index) {
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Char>
|
||||
unsigned basic_printf_context<OutputIt, Char>::parse_header(
|
||||
int basic_printf_context<OutputIt, Char>::parse_header(
|
||||
const Char*& it, const Char* end, format_specs& specs) {
|
||||
unsigned arg_index = internal::max_value<unsigned>();
|
||||
int arg_index = -1;
|
||||
char_type c = *it;
|
||||
if (c >= '0' && c <= '9') {
|
||||
// Parse an argument index (if followed by '$') or a width possibly
|
||||
// preceded with '0' flag(s).
|
||||
internal::error_handler eh;
|
||||
unsigned value = parse_nonnegative_int(it, end, eh);
|
||||
int value = parse_nonnegative_int(it, end, eh);
|
||||
if (it != end && *it == '$') { // value is an argument index
|
||||
++it;
|
||||
arg_index = value;
|
||||
@ -436,8 +436,8 @@ unsigned basic_printf_context<OutputIt, Char>::parse_header(
|
||||
specs.width = parse_nonnegative_int(it, end, eh);
|
||||
} else if (*it == '*') {
|
||||
++it;
|
||||
specs.width = visit_format_arg(
|
||||
internal::printf_width_handler<char_type>(specs), get_arg());
|
||||
specs.width = static_cast<int>(visit_format_arg(
|
||||
internal::printf_width_handler<char_type>(specs), get_arg()));
|
||||
}
|
||||
}
|
||||
return arg_index;
|
||||
@ -464,7 +464,7 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
|
||||
specs.align = align::right;
|
||||
|
||||
// Parse argument index, flags and width.
|
||||
unsigned arg_index = parse_header(it, end, specs);
|
||||
int arg_index = parse_header(it, end, specs);
|
||||
if (arg_index == 0) on_error("argument index out of range");
|
||||
|
||||
// Parse precision.
|
||||
@ -473,11 +473,11 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
|
||||
c = it != end ? *it : 0;
|
||||
if ('0' <= c && c <= '9') {
|
||||
internal::error_handler eh;
|
||||
specs.precision = static_cast<int>(parse_nonnegative_int(it, end, eh));
|
||||
specs.precision = parse_nonnegative_int(it, end, eh);
|
||||
} else if (c == '*') {
|
||||
++it;
|
||||
specs.precision =
|
||||
visit_format_arg(internal::printf_precision_handler(), get_arg());
|
||||
static_cast<int>(visit_format_arg(internal::printf_precision_handler(), get_arg()));
|
||||
} else {
|
||||
specs.precision = 0;
|
||||
}
|
||||
|
@ -10,13 +10,6 @@
|
||||
// By default spdlog include its own copy.
|
||||
//
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif // __GNUC__ || __clang__
|
||||
|
||||
|
||||
#if !defined(SPDLOG_FMT_EXTERNAL)
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#ifndef FMT_HEADER_ONLY
|
||||
@ -31,9 +24,4 @@
|
||||
#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
#endif
|
||||
|
||||
// pop warnings supressions
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif
|
13
src/fmt.cpp
13
src/fmt.cpp
@ -6,22 +6,9 @@
|
||||
// Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
// All rights reserved.
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#endif
|
||||
|
||||
#if !defined(SPDLOG_FMT_EXTERNAL)
|
||||
#include "spdlog/fmt/bundled/format-inl.h"
|
||||
|
||||
|
||||
// pop warnings supressions
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
template struct FMT_API internal::basic_data<void>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user