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