mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
astyle
This commit is contained in:
parent
9230d9e63d
commit
495ecaeaee
@ -13,7 +13,8 @@ static void output_callback(zf_log_message *msg)
|
||||
int main(int, char* [])
|
||||
{
|
||||
g_f = fopen(g_path, "wb");
|
||||
if (!g_f) {
|
||||
if (!g_f)
|
||||
{
|
||||
ZF_LOGE_AUX(ZF_LOG_STDERR, "Failed to open log file: %s", g_path);
|
||||
return -1;
|
||||
}
|
||||
|
@ -246,8 +246,10 @@ typedef __int64 intmax_t;
|
||||
#if defined(_MSC_VER) && !defined(FMT_BUILTIN_CLZLL)
|
||||
# include <intrin.h> // _BitScanReverse, _BitScanReverse64
|
||||
|
||||
namespace fmt {
|
||||
namespace internal {
|
||||
namespace fmt
|
||||
{
|
||||
namespace internal
|
||||
{
|
||||
# pragma intrinsic(_BitScanReverse)
|
||||
inline uint32_t clz(uint32_t x)
|
||||
{
|
||||
@ -293,8 +295,10 @@ namespace fmt {
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace fmt {
|
||||
namespace internal {
|
||||
namespace fmt
|
||||
{
|
||||
namespace internal
|
||||
{
|
||||
struct DummyInt
|
||||
{
|
||||
int data[2];
|
||||
@ -342,7 +346,8 @@ namespace fmt {
|
||||
}
|
||||
} // namespace fmt
|
||||
|
||||
namespace std {
|
||||
namespace std
|
||||
{
|
||||
// Standard permits specialization of std::numeric_limits. This specialization
|
||||
// is used to resolve ambiguity between isinf and std::isinf in glibc:
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891
|
||||
@ -360,7 +365,8 @@ namespace std {
|
||||
// The resolution "priority" is:
|
||||
// isinf macro > std::isinf > ::isinf > fmt::internal::isinf
|
||||
if (check(sizeof(isinf(x)) == sizeof(bool) ||
|
||||
sizeof(isinf(x)) == sizeof(int))) {
|
||||
sizeof(isinf(x)) == sizeof(int)))
|
||||
{
|
||||
return isinf(x) != 0;
|
||||
}
|
||||
return !_finite(static_cast<double>(x));
|
||||
@ -372,7 +378,8 @@ namespace std {
|
||||
{
|
||||
using namespace fmt::internal;
|
||||
if (check(sizeof(isnan(x)) == sizeof(bool) ||
|
||||
sizeof(isnan(x)) == sizeof(int))) {
|
||||
sizeof(isnan(x)) == sizeof(int)))
|
||||
{
|
||||
return isnan(x) != 0;
|
||||
}
|
||||
return _isnan(static_cast<double>(x)) != 0;
|
||||
@ -394,7 +401,8 @@ namespace std {
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
namespace fmt {
|
||||
namespace fmt
|
||||
{
|
||||
|
||||
// Fix the warning about long long on older versions of GCC
|
||||
// that don't support the diagnostic pragma.
|
||||
@ -411,7 +419,8 @@ namespace fmt {
|
||||
typedef BasicWriter<char> Writer;
|
||||
typedef BasicWriter<wchar_t> WWriter;
|
||||
|
||||
namespace internal {
|
||||
namespace internal
|
||||
{
|
||||
template <typename Char>
|
||||
class BasicArgFormatter;
|
||||
}
|
||||
@ -604,7 +613,8 @@ namespace fmt {
|
||||
{}
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
namespace internal
|
||||
{
|
||||
|
||||
// MakeUnsigned<T>::Type gives an unsigned type corresponding to integer type T.
|
||||
template <typename T>
|
||||
@ -758,7 +768,8 @@ namespace fmt {
|
||||
size_ = new_size;
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
namespace internal
|
||||
{
|
||||
|
||||
// A memory buffer for trivially copyable/constructible types with the first SIZE
|
||||
// elements stored in the object itself.
|
||||
@ -795,12 +806,14 @@ namespace fmt {
|
||||
this_alloc = std::move(other_alloc);
|
||||
this->size_ = other.size_;
|
||||
this->capacity_ = other.capacity_;
|
||||
if (other.ptr_ == other.data_) {
|
||||
if (other.ptr_ == other.data_)
|
||||
{
|
||||
this->ptr_ = data_;
|
||||
std::uninitialized_copy(other.data_, other.data_ + this->size_,
|
||||
make_ptr(data_, this->capacity_));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
this->ptr_ = other.ptr_;
|
||||
// Set pointer to the inline array so that delete is not called
|
||||
// when deallocating.
|
||||
@ -998,7 +1011,8 @@ namespace fmt {
|
||||
inline unsigned count_digits(uint64_t n)
|
||||
{
|
||||
unsigned count = 1;
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
// Integer division is slow so do it for a group of four digits instead
|
||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||
@ -1026,7 +1040,8 @@ namespace fmt {
|
||||
inline void format_decimal(Char *buffer, UInt value, unsigned num_digits)
|
||||
{
|
||||
buffer += num_digits;
|
||||
while (value >= 100) {
|
||||
while (value >= 100)
|
||||
{
|
||||
// Integer division is slow so do it for a group of two digits instead
|
||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||
@ -1035,7 +1050,8 @@ namespace fmt {
|
||||
*--buffer = Data::DIGITS[index + 1];
|
||||
*--buffer = Data::DIGITS[index];
|
||||
}
|
||||
if (value < 10) {
|
||||
if (value < 10)
|
||||
{
|
||||
*--buffer = static_cast<char>('0' + value);
|
||||
return;
|
||||
}
|
||||
@ -1627,7 +1643,8 @@ namespace fmt {
|
||||
|
||||
Result visit(const Arg &arg)
|
||||
{
|
||||
switch (arg.type) {
|
||||
switch (arg.type)
|
||||
{
|
||||
default:
|
||||
FMT_ASSERT(false, "invalid argument type");
|
||||
return Result();
|
||||
@ -1727,7 +1744,8 @@ namespace fmt {
|
||||
using internal::Arg;
|
||||
Arg arg;
|
||||
bool use_values = type(MAX_PACKED_ARGS - 1) == Arg::NONE;
|
||||
if (index < MAX_PACKED_ARGS) {
|
||||
if (index < MAX_PACKED_ARGS)
|
||||
{
|
||||
Arg::Type arg_type = type(index);
|
||||
internal::Value &val = arg;
|
||||
if (arg_type != Arg::NONE)
|
||||
@ -1735,13 +1753,15 @@ namespace fmt {
|
||||
arg.type = arg_type;
|
||||
return arg;
|
||||
}
|
||||
if (use_values) {
|
||||
if (use_values)
|
||||
{
|
||||
// The index is greater than the number of arguments that can be stored
|
||||
// in values, so return a "none" argument.
|
||||
arg.type = Arg::NONE;
|
||||
return arg;
|
||||
}
|
||||
for (unsigned i = MAX_PACKED_ARGS; i <= index; ++i) {
|
||||
for (unsigned i = MAX_PACKED_ARGS; i <= index; ++i)
|
||||
{
|
||||
if (args_[i].type == Arg::NONE)
|
||||
return args_[i];
|
||||
}
|
||||
@ -2039,7 +2059,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
return StrFormatSpec<wchar_t>(str, width, fill);
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
namespace internal
|
||||
{
|
||||
|
||||
template <typename Char>
|
||||
class ArgMap
|
||||
@ -2057,7 +2078,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
{
|
||||
// The list is unsorted, so just return the first matching name.
|
||||
for (typename MapType::const_iterator it = map_.begin(), end = map_.end();
|
||||
it != end; ++it) {
|
||||
it != end; ++it)
|
||||
{
|
||||
if (it->first == name)
|
||||
return &it->second;
|
||||
}
|
||||
@ -2130,7 +2152,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
|
||||
void visit_char(int value)
|
||||
{
|
||||
if (spec_.type_ && spec_.type_ != 'c') {
|
||||
if (spec_.type_ && spec_.type_ != 'c')
|
||||
{
|
||||
spec_.flags_ |= CHAR_FLAG;
|
||||
writer_.write_int(value, spec_);
|
||||
return;
|
||||
@ -2141,22 +2164,27 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
Char fill = internal::CharTraits<Char>::cast(spec_.fill());
|
||||
CharPtr out = CharPtr();
|
||||
const unsigned CHAR_WIDTH = 1;
|
||||
if (spec_.width_ > CHAR_WIDTH) {
|
||||
if (spec_.width_ > CHAR_WIDTH)
|
||||
{
|
||||
out = writer_.grow_buffer(spec_.width_);
|
||||
if (spec_.align_ == ALIGN_RIGHT) {
|
||||
if (spec_.align_ == ALIGN_RIGHT)
|
||||
{
|
||||
std::uninitialized_fill_n(out, spec_.width_ - CHAR_WIDTH, fill);
|
||||
out += spec_.width_ - CHAR_WIDTH;
|
||||
}
|
||||
else if (spec_.align_ == ALIGN_CENTER) {
|
||||
else if (spec_.align_ == ALIGN_CENTER)
|
||||
{
|
||||
out = writer_.fill_padding(out, spec_.width_,
|
||||
internal::check(CHAR_WIDTH), fill);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
std::uninitialized_fill_n(out + CHAR_WIDTH,
|
||||
spec_.width_ - CHAR_WIDTH, fill);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
out = writer_.grow_buffer(CHAR_WIDTH);
|
||||
}
|
||||
*out = internal::CharTraits<Char>::cast(value);
|
||||
@ -2249,7 +2277,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
|
||||
bool check_no_auto_index(const char *&error)
|
||||
{
|
||||
if (next_arg_index_ > 0) {
|
||||
if (next_arg_index_ > 0)
|
||||
{
|
||||
error = "cannot switch from automatic to manual argument indexing";
|
||||
return false;
|
||||
}
|
||||
@ -2358,7 +2387,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
# define FMT_GEN14(f) FMT_GEN13(f), f(13)
|
||||
# define FMT_GEN15(f) FMT_GEN14(f), f(14)
|
||||
|
||||
namespace internal {
|
||||
namespace internal
|
||||
{
|
||||
inline uint64_t make_type()
|
||||
{
|
||||
return 0;
|
||||
@ -2451,7 +2481,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
|
||||
int_type overflow(int_type ch = traits_type::eof())
|
||||
{
|
||||
if (!traits_type::eq_int_type(ch, traits_type::eof())) {
|
||||
if (!traits_type::eq_int_type(ch, traits_type::eof()))
|
||||
{
|
||||
size_t size = this->size();
|
||||
buffer_.resize(size);
|
||||
buffer_.reserve(size * 2);
|
||||
@ -2695,11 +2726,13 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
{
|
||||
typedef typename internal::IntTraits<Int>::MainType MainType;
|
||||
MainType abs_value = static_cast<MainType>(value);
|
||||
if (internal::is_negative(value)) {
|
||||
if (internal::is_negative(value))
|
||||
{
|
||||
abs_value = 0 - abs_value;
|
||||
*write_unsigned_decimal(abs_value, 1) = '-';
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
write_unsigned_decimal(abs_value, 0);
|
||||
}
|
||||
}
|
||||
@ -2960,21 +2993,26 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
const StrChar *s, std::size_t size, const AlignSpec &spec)
|
||||
{
|
||||
CharPtr out = CharPtr();
|
||||
if (spec.width() > size) {
|
||||
if (spec.width() > size)
|
||||
{
|
||||
out = grow_buffer(spec.width());
|
||||
Char fill = internal::CharTraits<Char>::cast(spec.fill());
|
||||
if (spec.align() == ALIGN_RIGHT) {
|
||||
if (spec.align() == ALIGN_RIGHT)
|
||||
{
|
||||
std::uninitialized_fill_n(out, spec.width() - size, fill);
|
||||
out += spec.width() - size;
|
||||
}
|
||||
else if (spec.align() == ALIGN_CENTER) {
|
||||
else if (spec.align() == ALIGN_CENTER)
|
||||
{
|
||||
out = fill_padding(out, spec.width(), size, fill);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
std::uninitialized_fill_n(out + size, spec.width() - size, fill);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
out = grow_buffer(size);
|
||||
}
|
||||
std::uninitialized_copy(s, s + size, out);
|
||||
@ -2992,8 +3030,10 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
internal::report_unknown_type(spec.type_, "string");
|
||||
const StrChar *str_value = s.value;
|
||||
std::size_t str_size = s.size;
|
||||
if (str_size == 0) {
|
||||
if (!str_value) {
|
||||
if (str_size == 0)
|
||||
{
|
||||
if (!str_value)
|
||||
{
|
||||
FMT_THROW(FormatError("string pointer is null"));
|
||||
return;
|
||||
}
|
||||
@ -3031,7 +3071,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
unsigned width = spec.width();
|
||||
Alignment align = spec.align();
|
||||
Char fill = internal::CharTraits<Char>::cast(spec.fill());
|
||||
if (spec.precision() > static_cast<int>(num_digits)) {
|
||||
if (spec.precision() > static_cast<int>(num_digits))
|
||||
{
|
||||
// Octal prefix '0' is counted as a digit, so ignore it if precision
|
||||
// is specified.
|
||||
if (prefix_size > 0 && prefix[prefix_size - 1] == '0')
|
||||
@ -3043,44 +3084,53 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
return prepare_int_buffer(num_digits, subspec, prefix, prefix_size);
|
||||
buffer_.reserve(width);
|
||||
unsigned fill_size = width - number_size;
|
||||
if (align != ALIGN_LEFT) {
|
||||
if (align != ALIGN_LEFT)
|
||||
{
|
||||
CharPtr p = grow_buffer(fill_size);
|
||||
std::uninitialized_fill(p, p + fill_size, fill);
|
||||
}
|
||||
CharPtr result = prepare_int_buffer(
|
||||
num_digits, subspec, prefix, prefix_size);
|
||||
if (align == ALIGN_LEFT) {
|
||||
if (align == ALIGN_LEFT)
|
||||
{
|
||||
CharPtr p = grow_buffer(fill_size);
|
||||
std::uninitialized_fill(p, p + fill_size, fill);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
unsigned size = prefix_size + num_digits;
|
||||
if (width <= size) {
|
||||
if (width <= size)
|
||||
{
|
||||
CharPtr p = grow_buffer(size);
|
||||
std::uninitialized_copy(prefix, prefix + prefix_size, p);
|
||||
return p + size - 1;
|
||||
}
|
||||
CharPtr p = grow_buffer(width);
|
||||
CharPtr end = p + width;
|
||||
if (align == ALIGN_LEFT) {
|
||||
if (align == ALIGN_LEFT)
|
||||
{
|
||||
std::uninitialized_copy(prefix, prefix + prefix_size, p);
|
||||
p += size;
|
||||
std::uninitialized_fill(p, end, fill);
|
||||
}
|
||||
else if (align == ALIGN_CENTER) {
|
||||
else if (align == ALIGN_CENTER)
|
||||
{
|
||||
p = fill_padding(p, width, size, fill);
|
||||
std::uninitialized_copy(prefix, prefix + prefix_size, p);
|
||||
p += size;
|
||||
}
|
||||
else {
|
||||
if (align == ALIGN_NUMERIC) {
|
||||
if (prefix_size != 0) {
|
||||
else
|
||||
{
|
||||
if (align == ALIGN_NUMERIC)
|
||||
{
|
||||
if (prefix_size != 0)
|
||||
{
|
||||
p = std::uninitialized_copy(prefix, prefix + prefix_size, p);
|
||||
size -= prefix_size;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
std::uninitialized_copy(prefix, prefix + prefix_size, end - size);
|
||||
}
|
||||
std::uninitialized_fill(p, end - size, fill);
|
||||
@ -3097,73 +3147,97 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
typedef typename internal::IntTraits<T>::MainType UnsignedType;
|
||||
UnsignedType abs_value = static_cast<UnsignedType>(value);
|
||||
char prefix[4] = "";
|
||||
if (internal::is_negative(value)) {
|
||||
if (internal::is_negative(value))
|
||||
{
|
||||
prefix[0] = '-';
|
||||
++prefix_size;
|
||||
abs_value = 0 - abs_value;
|
||||
}
|
||||
else if (spec.flag(SIGN_FLAG)) {
|
||||
else if (spec.flag(SIGN_FLAG))
|
||||
{
|
||||
prefix[0] = spec.flag(PLUS_FLAG) ? '+' : ' ';
|
||||
++prefix_size;
|
||||
}
|
||||
switch (spec.type()) {
|
||||
case 0: case 'd': {
|
||||
switch (spec.type())
|
||||
{
|
||||
case 0:
|
||||
case 'd':
|
||||
{
|
||||
unsigned num_digits = internal::count_digits(abs_value);
|
||||
CharPtr p = prepare_int_buffer(
|
||||
num_digits, spec, prefix, prefix_size) + 1 - num_digits;
|
||||
internal::format_decimal(get(p), abs_value, num_digits);
|
||||
break;
|
||||
}
|
||||
case 'x': case 'X': {
|
||||
case 'x':
|
||||
case 'X':
|
||||
{
|
||||
UnsignedType n = abs_value;
|
||||
if (spec.flag(HASH_FLAG)) {
|
||||
if (spec.flag(HASH_FLAG))
|
||||
{
|
||||
prefix[prefix_size++] = '0';
|
||||
prefix[prefix_size++] = spec.type();
|
||||
}
|
||||
unsigned num_digits = 0;
|
||||
do {
|
||||
do
|
||||
{
|
||||
++num_digits;
|
||||
} while ((n >>= 4) != 0);
|
||||
}
|
||||
while ((n >>= 4) != 0);
|
||||
Char *p = get(prepare_int_buffer(
|
||||
num_digits, spec, prefix, prefix_size));
|
||||
n = abs_value;
|
||||
const char *digits = spec.type() == 'x' ?
|
||||
"0123456789abcdef" : "0123456789ABCDEF";
|
||||
do {
|
||||
do
|
||||
{
|
||||
*p-- = digits[n & 0xf];
|
||||
} while ((n >>= 4) != 0);
|
||||
}
|
||||
while ((n >>= 4) != 0);
|
||||
break;
|
||||
}
|
||||
case 'b': case 'B': {
|
||||
case 'b':
|
||||
case 'B':
|
||||
{
|
||||
UnsignedType n = abs_value;
|
||||
if (spec.flag(HASH_FLAG)) {
|
||||
if (spec.flag(HASH_FLAG))
|
||||
{
|
||||
prefix[prefix_size++] = '0';
|
||||
prefix[prefix_size++] = spec.type();
|
||||
}
|
||||
unsigned num_digits = 0;
|
||||
do {
|
||||
do
|
||||
{
|
||||
++num_digits;
|
||||
} while ((n >>= 1) != 0);
|
||||
}
|
||||
while ((n >>= 1) != 0);
|
||||
Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
|
||||
n = abs_value;
|
||||
do {
|
||||
do
|
||||
{
|
||||
*p-- = static_cast<Char>('0' + (n & 1));
|
||||
} while ((n >>= 1) != 0);
|
||||
}
|
||||
while ((n >>= 1) != 0);
|
||||
break;
|
||||
}
|
||||
case 'o': {
|
||||
case 'o':
|
||||
{
|
||||
UnsignedType n = abs_value;
|
||||
if (spec.flag(HASH_FLAG))
|
||||
prefix[prefix_size++] = '0';
|
||||
unsigned num_digits = 0;
|
||||
do {
|
||||
do
|
||||
{
|
||||
++num_digits;
|
||||
} while ((n >>= 3) != 0);
|
||||
}
|
||||
while ((n >>= 3) != 0);
|
||||
Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
|
||||
n = abs_value;
|
||||
do {
|
||||
do
|
||||
{
|
||||
*p-- = static_cast<Char>('0' + (n & 7));
|
||||
} while ((n >>= 3) != 0);
|
||||
}
|
||||
while ((n >>= 3) != 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -3180,11 +3254,15 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
// Check type.
|
||||
char type = spec.type();
|
||||
bool upper = false;
|
||||
switch (type) {
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
type = 'g';
|
||||
break;
|
||||
case 'e': case 'f': case 'g': case 'a':
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'a':
|
||||
break;
|
||||
case 'F':
|
||||
#ifdef _MSC_VER
|
||||
@ -3192,7 +3270,9 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
type = 'f';
|
||||
#endif
|
||||
// Fall through.
|
||||
case 'E': case 'G': case 'A':
|
||||
case 'E':
|
||||
case 'G':
|
||||
case 'A':
|
||||
upper = true;
|
||||
break;
|
||||
default:
|
||||
@ -3203,20 +3283,24 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
char sign = 0;
|
||||
// Use isnegative instead of value < 0 because the latter is always
|
||||
// false for NaN.
|
||||
if (internal::FPUtil::isnegative(static_cast<double>(value))) {
|
||||
if (internal::FPUtil::isnegative(static_cast<double>(value)))
|
||||
{
|
||||
sign = '-';
|
||||
value = -value;
|
||||
}
|
||||
else if (spec.flag(SIGN_FLAG)) {
|
||||
else if (spec.flag(SIGN_FLAG))
|
||||
{
|
||||
sign = spec.flag(PLUS_FLAG) ? '+' : ' ';
|
||||
}
|
||||
|
||||
if (internal::FPUtil::isnotanumber(value)) {
|
||||
if (internal::FPUtil::isnotanumber(value))
|
||||
{
|
||||
// Format NaN ourselves because sprintf's output is not consistent
|
||||
// across platforms.
|
||||
std::size_t nan_size = 4;
|
||||
const char *nan = upper ? " NAN" : " nan";
|
||||
if (!sign) {
|
||||
if (!sign)
|
||||
{
|
||||
--nan_size;
|
||||
++nan;
|
||||
}
|
||||
@ -3226,12 +3310,14 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
return;
|
||||
}
|
||||
|
||||
if (internal::FPUtil::isinfinity(value)) {
|
||||
if (internal::FPUtil::isinfinity(value))
|
||||
{
|
||||
// Format infinity ourselves because sprintf's output is not consistent
|
||||
// across platforms.
|
||||
std::size_t inf_size = 4;
|
||||
const char *inf = upper ? " INF" : " inf";
|
||||
if (!sign) {
|
||||
if (!sign)
|
||||
{
|
||||
--inf_size;
|
||||
++inf;
|
||||
}
|
||||
@ -3243,7 +3329,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
|
||||
std::size_t offset = buffer_.size();
|
||||
unsigned width = spec.width();
|
||||
if (sign) {
|
||||
if (sign)
|
||||
{
|
||||
buffer_.reserve(buffer_.size() + (width > 1u ? width : 1u));
|
||||
if (width > 0)
|
||||
--width;
|
||||
@ -3261,16 +3348,19 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
unsigned width_for_sprintf = width;
|
||||
if (spec.flag(HASH_FLAG))
|
||||
*format_ptr++ = '#';
|
||||
if (spec.align() == ALIGN_CENTER) {
|
||||
if (spec.align() == ALIGN_CENTER)
|
||||
{
|
||||
width_for_sprintf = 0;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (spec.align() == ALIGN_LEFT)
|
||||
*format_ptr++ = '-';
|
||||
if (width != 0)
|
||||
*format_ptr++ = '*';
|
||||
}
|
||||
if (spec.precision() >= 0) {
|
||||
if (spec.precision() >= 0)
|
||||
{
|
||||
*format_ptr++ = '.';
|
||||
*format_ptr++ = '*';
|
||||
}
|
||||
@ -3283,13 +3373,15 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
Char fill = internal::CharTraits<Char>::cast(spec.fill());
|
||||
unsigned n = 0;
|
||||
Char *start = 0;
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
std::size_t buffer_size = buffer_.capacity() - offset;
|
||||
#ifdef _MSC_VER
|
||||
// MSVC's vsnprintf_s doesn't work with zero size, so reserve
|
||||
// space for at least one extra character to make the size non-zero.
|
||||
// Note that the buffer's capacity will increase by more than 1.
|
||||
if (buffer_size == 0) {
|
||||
if (buffer_size == 0)
|
||||
{
|
||||
buffer_.reserve(offset + 1);
|
||||
buffer_size = buffer_.capacity() - offset;
|
||||
}
|
||||
@ -3297,37 +3389,44 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
start = &buffer_[offset];
|
||||
int result = internal::CharTraits<Char>::format_float(
|
||||
start, buffer_size, format, width_for_sprintf, spec.precision(), value);
|
||||
if (result >= 0) {
|
||||
if (result >= 0)
|
||||
{
|
||||
n = internal::to_unsigned(result);
|
||||
if (offset + n < buffer_.capacity())
|
||||
break; // The buffer is large enough - continue with formatting.
|
||||
buffer_.reserve(offset + n + 1);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// If result is negative we ask to increase the capacity by at least 1,
|
||||
// but as std::vector, the buffer grows exponentially.
|
||||
buffer_.reserve(buffer_.capacity() + 1);
|
||||
}
|
||||
}
|
||||
if (sign) {
|
||||
if (sign)
|
||||
{
|
||||
if ((spec.align() != ALIGN_RIGHT && spec.align() != ALIGN_DEFAULT) ||
|
||||
*start != ' ') {
|
||||
*start != ' ')
|
||||
{
|
||||
*(start - 1) = sign;
|
||||
sign = 0;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
*(start - 1) = fill;
|
||||
}
|
||||
++n;
|
||||
}
|
||||
if (spec.align() == ALIGN_CENTER && spec.width() > n) {
|
||||
if (spec.align() == ALIGN_CENTER && spec.width() > n)
|
||||
{
|
||||
width = spec.width();
|
||||
CharPtr p = grow_buffer(width);
|
||||
std::memmove(get(p) + (width - n) / 2, get(p), n * sizeof(Char));
|
||||
fill_padding(p, spec.width(), n, fill);
|
||||
return;
|
||||
}
|
||||
if (spec.fill() != ' ' || sign) {
|
||||
if (spec.fill() != ' ' || sign)
|
||||
{
|
||||
while (*start == ' ')
|
||||
*start++ = fill;
|
||||
if (sign)
|
||||
@ -3662,7 +3761,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
char *format_decimal(ULongLong value)
|
||||
{
|
||||
char *buffer_end = buffer_ + BUFFER_SIZE - 1;
|
||||
while (value >= 100) {
|
||||
while (value >= 100)
|
||||
{
|
||||
// Integer division is slow so do it for a group of two digits instead
|
||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||
@ -3671,7 +3771,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
*--buffer_end = internal::Data::DIGITS[index + 1];
|
||||
*--buffer_end = internal::Data::DIGITS[index];
|
||||
}
|
||||
if (value < 10) {
|
||||
if (value < 10)
|
||||
{
|
||||
*--buffer_end = static_cast<char>('0' + value);
|
||||
return buffer_end;
|
||||
}
|
||||
@ -3756,12 +3857,15 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
||||
{
|
||||
typedef typename internal::IntTraits<T>::MainType MainType;
|
||||
MainType abs_value = static_cast<MainType>(value);
|
||||
if (internal::is_negative(value)) {
|
||||
if (internal::is_negative(value))
|
||||
{
|
||||
*buffer++ = '-';
|
||||
abs_value = 0 - abs_value;
|
||||
}
|
||||
if (abs_value < 100) {
|
||||
if (abs_value < 10) {
|
||||
if (abs_value < 100)
|
||||
{
|
||||
if (abs_value < 10)
|
||||
{
|
||||
*buffer++ = static_cast<char>('0' + abs_value);
|
||||
return;
|
||||
}
|
||||
@ -3932,7 +4036,8 @@ print("point: ({x}, {y})", FMT_CAPTURE(x, y));
|
||||
|
||||
#define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__)
|
||||
|
||||
namespace fmt {
|
||||
namespace fmt
|
||||
{
|
||||
FMT_VARIADIC(std::string, format, CStringRef)
|
||||
FMT_VARIADIC_W(std::wstring, format, WCStringRef)
|
||||
FMT_VARIADIC(void, print, CStringRef)
|
||||
@ -3970,7 +4075,8 @@ namespace fmt {
|
||||
FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef)
|
||||
#endif
|
||||
|
||||
namespace internal {
|
||||
namespace internal
|
||||
{
|
||||
template <typename Char>
|
||||
inline bool is_name_start(Char c)
|
||||
{
|
||||
@ -3984,15 +4090,18 @@ namespace fmt {
|
||||
{
|
||||
assert('0' <= *s && *s <= '9');
|
||||
unsigned value = 0;
|
||||
do {
|
||||
do
|
||||
{
|
||||
unsigned new_value = value * 10 + (*s++ - '0');
|
||||
// Check if value wrapped around.
|
||||
if (new_value < value) {
|
||||
if (new_value < value)
|
||||
{
|
||||
value = (std::numeric_limits<unsigned>::max)();
|
||||
break;
|
||||
}
|
||||
value = new_value;
|
||||
} while ('0' <= *s && *s <= '9');
|
||||
}
|
||||
while ('0' <= *s && *s <= '9');
|
||||
// Convert to unsigned to prevent a warning.
|
||||
unsigned max_int = (std::numeric_limits<int>::max)();
|
||||
if (value > max_int)
|
||||
@ -4002,7 +4111,8 @@ namespace fmt {
|
||||
|
||||
inline void require_numeric_argument(const Arg &arg, char spec)
|
||||
{
|
||||
if (arg.type > Arg::LAST_NUMERIC_TYPE) {
|
||||
if (arg.type > Arg::LAST_NUMERIC_TYPE)
|
||||
{
|
||||
std::string message =
|
||||
fmt::format("format specifier '{}' requires numeric argument", spec);
|
||||
FMT_THROW(fmt::FormatError(message));
|
||||
@ -4014,7 +4124,8 @@ namespace fmt {
|
||||
{
|
||||
char sign = static_cast<char>(*s);
|
||||
require_numeric_argument(arg, sign);
|
||||
if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) {
|
||||
if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG)
|
||||
{
|
||||
FMT_THROW(FormatError(fmt::format(
|
||||
"format specifier '{}' requires signed argument", sign)));
|
||||
}
|
||||
@ -4026,7 +4137,8 @@ namespace fmt {
|
||||
inline internal::Arg BasicFormatter<Char, AF>::get_arg(
|
||||
BasicStringRef<Char> arg_name, const char *&error)
|
||||
{
|
||||
if (check_no_auto_index(error)) {
|
||||
if (check_no_auto_index(error))
|
||||
{
|
||||
map_.init(args());
|
||||
const internal::Arg *arg = map_.find(arg_name);
|
||||
if (arg)
|
||||
@ -4042,7 +4154,8 @@ namespace fmt {
|
||||
const char *error = 0;
|
||||
internal::Arg arg = *s < '0' || *s > '9' ?
|
||||
next_arg(error) : get_arg(internal::parse_nonnegative_int(s), error);
|
||||
if (error) {
|
||||
if (error)
|
||||
{
|
||||
FMT_THROW(FormatError(
|
||||
*s != '}' && *s != ':' ? "invalid format string" : error));
|
||||
}
|
||||
@ -4055,9 +4168,11 @@ namespace fmt {
|
||||
assert(internal::is_name_start(*s));
|
||||
const Char *start = s;
|
||||
Char c;
|
||||
do {
|
||||
do
|
||||
{
|
||||
c = *++s;
|
||||
} while (internal::is_name_start(c) || ('0' <= c && c <= '9'));
|
||||
}
|
||||
while (internal::is_name_start(c) || ('0' <= c && c <= '9'));
|
||||
const char *error = 0;
|
||||
internal::Arg arg = get_arg(BasicStringRef<Char>(start, s - start), error);
|
||||
if (error)
|
||||
@ -4072,18 +4187,23 @@ namespace fmt {
|
||||
using internal::Arg;
|
||||
const Char *s = format_str;
|
||||
FormatSpec spec;
|
||||
if (*s == ':') {
|
||||
if (arg.type == Arg::CUSTOM) {
|
||||
if (*s == ':')
|
||||
{
|
||||
if (arg.type == Arg::CUSTOM)
|
||||
{
|
||||
arg.custom.format(this, arg.custom.value, &s);
|
||||
return s;
|
||||
}
|
||||
++s;
|
||||
// Parse fill and alignment.
|
||||
if (Char c = *s) {
|
||||
if (Char c = *s)
|
||||
{
|
||||
const Char *p = s + 1;
|
||||
spec.align_ = ALIGN_DEFAULT;
|
||||
do {
|
||||
switch (*p) {
|
||||
do
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case '<':
|
||||
spec.align_ = ALIGN_LEFT;
|
||||
break;
|
||||
@ -4097,8 +4217,10 @@ namespace fmt {
|
||||
spec.align_ = ALIGN_CENTER;
|
||||
break;
|
||||
}
|
||||
if (spec.align_ != ALIGN_DEFAULT) {
|
||||
if (p != s) {
|
||||
if (spec.align_ != ALIGN_DEFAULT)
|
||||
{
|
||||
if (p != s)
|
||||
{
|
||||
if (c == '}') break;
|
||||
if (c == '{')
|
||||
FMT_THROW(FormatError("invalid fill character '{'"));
|
||||
@ -4110,11 +4232,13 @@ namespace fmt {
|
||||
require_numeric_argument(arg, '=');
|
||||
break;
|
||||
}
|
||||
} while (--p >= s);
|
||||
}
|
||||
while (--p >= s);
|
||||
}
|
||||
|
||||
// Parse sign.
|
||||
switch (*s) {
|
||||
switch (*s)
|
||||
{
|
||||
case '+':
|
||||
check_sign(s, arg);
|
||||
spec.flags_ |= SIGN_FLAG | PLUS_FLAG;
|
||||
@ -4129,14 +4253,16 @@ namespace fmt {
|
||||
break;
|
||||
}
|
||||
|
||||
if (*s == '#') {
|
||||
if (*s == '#')
|
||||
{
|
||||
require_numeric_argument(arg, '#');
|
||||
spec.flags_ |= HASH_FLAG;
|
||||
++s;
|
||||
}
|
||||
|
||||
// Parse zero flag.
|
||||
if (*s == '0') {
|
||||
if (*s == '0')
|
||||
{
|
||||
require_numeric_argument(arg, '0');
|
||||
spec.align_ = ALIGN_NUMERIC;
|
||||
spec.fill_ = '0';
|
||||
@ -4144,17 +4270,20 @@ namespace fmt {
|
||||
}
|
||||
|
||||
// Parse width.
|
||||
if ('0' <= *s && *s <= '9') {
|
||||
if ('0' <= *s && *s <= '9')
|
||||
{
|
||||
spec.width_ = internal::parse_nonnegative_int(s);
|
||||
}
|
||||
else if (*s == '{') {
|
||||
else if (*s == '{')
|
||||
{
|
||||
++s;
|
||||
Arg width_arg = internal::is_name_start(*s) ?
|
||||
parse_arg_name(s) : parse_arg_index(s);
|
||||
if (*s++ != '}')
|
||||
FMT_THROW(FormatError("invalid format string"));
|
||||
ULongLong value = 0;
|
||||
switch (width_arg.type) {
|
||||
switch (width_arg.type)
|
||||
{
|
||||
case Arg::INT:
|
||||
if (width_arg.int_value < 0)
|
||||
FMT_THROW(FormatError("negative width"));
|
||||
@ -4180,20 +4309,24 @@ namespace fmt {
|
||||
}
|
||||
|
||||
// Parse precision.
|
||||
if (*s == '.') {
|
||||
if (*s == '.')
|
||||
{
|
||||
++s;
|
||||
spec.precision_ = 0;
|
||||
if ('0' <= *s && *s <= '9') {
|
||||
if ('0' <= *s && *s <= '9')
|
||||
{
|
||||
spec.precision_ = internal::parse_nonnegative_int(s);
|
||||
}
|
||||
else if (*s == '{') {
|
||||
else if (*s == '{')
|
||||
{
|
||||
++s;
|
||||
Arg precision_arg = internal::is_name_start(*s) ?
|
||||
parse_arg_name(s) : parse_arg_index(s);
|
||||
if (*s++ != '}')
|
||||
FMT_THROW(FormatError("invalid format string"));
|
||||
ULongLong value = 0;
|
||||
switch (precision_arg.type) {
|
||||
switch (precision_arg.type)
|
||||
{
|
||||
case Arg::INT:
|
||||
if (precision_arg.int_value < 0)
|
||||
FMT_THROW(FormatError("negative precision"));
|
||||
@ -4217,10 +4350,12 @@ namespace fmt {
|
||||
FMT_THROW(FormatError("number is too big"));
|
||||
spec.precision_ = static_cast<int>(value);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
FMT_THROW(FormatError("missing precision specifier"));
|
||||
}
|
||||
if (arg.type <= Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER) {
|
||||
if (arg.type <= Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER)
|
||||
{
|
||||
FMT_THROW(FormatError(
|
||||
fmt::format("precision not allowed in {} format specifier",
|
||||
arg.type == Arg::POINTER ? "pointer" : "integer")));
|
||||
@ -4245,10 +4380,12 @@ namespace fmt {
|
||||
{
|
||||
const Char *s = format_str.c_str();
|
||||
const Char *start = s;
|
||||
while (*s) {
|
||||
while (*s)
|
||||
{
|
||||
Char c = *s++;
|
||||
if (c != '{' && c != '}') continue;
|
||||
if (*s == c) {
|
||||
if (*s == c)
|
||||
{
|
||||
write(writer_, start, s);
|
||||
start = ++s;
|
||||
continue;
|
||||
@ -4265,8 +4402,10 @@ namespace fmt {
|
||||
} // namespace fmt
|
||||
|
||||
#if FMT_USE_USER_DEFINED_LITERALS
|
||||
namespace fmt {
|
||||
namespace internal {
|
||||
namespace fmt
|
||||
{
|
||||
namespace internal
|
||||
{
|
||||
|
||||
template <typename Char>
|
||||
struct UdlFormat
|
||||
@ -4295,7 +4434,8 @@ namespace fmt {
|
||||
|
||||
} // namespace internal
|
||||
|
||||
inline namespace literals {
|
||||
inline namespace literals
|
||||
{
|
||||
|
||||
/**
|
||||
\rst
|
||||
|
@ -11,15 +11,18 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
namespace spdlog
|
||||
{
|
||||
namespace sinks
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The ansi_color_sink is a decorator around another sink and prefixes
|
||||
* the output with an ANSI escape sequence color code depending on the severity
|
||||
* of the message.
|
||||
*/
|
||||
class ansicolor_sink : public sink {
|
||||
class ansicolor_sink : public sink
|
||||
{
|
||||
public:
|
||||
ansicolor_sink(sink_ptr wrapped_sink);
|
||||
virtual ~ansicolor_sink();
|
||||
|
Loading…
Reference in New Issue
Block a user