|
|
|
@ -292,8 +292,10 @@ typedef __int64 intmax_t;
|
|
|
|
|
#if FMT_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)
|
|
|
|
|
{
|
|
|
|
@ -339,8 +341,10 @@ namespace fmt {
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace fmt {
|
|
|
|
|
namespace internal {
|
|
|
|
|
namespace fmt
|
|
|
|
|
{
|
|
|
|
|
namespace internal
|
|
|
|
|
{
|
|
|
|
|
struct DummyInt
|
|
|
|
|
{
|
|
|
|
|
int data[2];
|
|
|
|
@ -388,7 +392,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
|
|
|
|
@ -406,7 +411,8 @@ namespace std {
|
|
|
|
|
// The resolution "priority" is:
|
|
|
|
|
// isinf macro > std::isinf > ::isinf > fmt::internal::isinf
|
|
|
|
|
if (const_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));
|
|
|
|
@ -418,7 +424,8 @@ namespace std {
|
|
|
|
|
{
|
|
|
|
|
using namespace fmt::internal;
|
|
|
|
|
if (const_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;
|
|
|
|
@ -429,7 +436,8 @@ namespace std {
|
|
|
|
|
{
|
|
|
|
|
using namespace fmt::internal;
|
|
|
|
|
if (const_check(sizeof(signbit(x)) == sizeof(bool) ||
|
|
|
|
|
sizeof(signbit(x)) == sizeof(int))) {
|
|
|
|
|
sizeof(signbit(x)) == sizeof(int)))
|
|
|
|
|
{
|
|
|
|
|
return signbit(x) != 0;
|
|
|
|
|
}
|
|
|
|
|
if (x < 0) return true;
|
|
|
|
@ -442,7 +450,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.
|
|
|
|
@ -651,7 +660,8 @@ namespace fmt {
|
|
|
|
|
~FormatError() FMT_DTOR_NOEXCEPT;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
namespace internal
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// MakeUnsigned<T>::Type gives an unsigned type corresponding to integer type T.
|
|
|
|
|
template <typename T>
|
|
|
|
@ -805,7 +815,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.
|
|
|
|
@ -842,12 +853,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.
|
|
|
|
@ -1067,7 +1080,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.
|
|
|
|
@ -1130,7 +1144,8 @@ namespace fmt {
|
|
|
|
|
ThousandsSep thousands_sep)
|
|
|
|
|
{
|
|
|
|
|
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.
|
|
|
|
@ -1141,7 +1156,8 @@ namespace fmt {
|
|
|
|
|
*--buffer = Data::DIGITS[index];
|
|
|
|
|
thousands_sep(buffer);
|
|
|
|
|
}
|
|
|
|
|
if (value < 10) {
|
|
|
|
|
if (value < 10)
|
|
|
|
|
{
|
|
|
|
|
*--buffer = static_cast<char>('0' + value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -1766,7 +1782,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)
|
|
|
|
@ -1774,13 +1791,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];
|
|
|
|
|
}
|
|
|
|
@ -1940,7 +1959,8 @@ namespace fmt {
|
|
|
|
|
*/
|
|
|
|
|
Result visit(const Arg &arg)
|
|
|
|
|
{
|
|
|
|
|
switch (arg.type) {
|
|
|
|
|
switch (arg.type)
|
|
|
|
|
{
|
|
|
|
|
case Arg::NONE:
|
|
|
|
|
case Arg::NAMED_ARG:
|
|
|
|
|
FMT_ASSERT(false, "invalid argument type");
|
|
|
|
@ -2266,7 +2286,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
|
|
|
|
return StrFormatSpec<wchar_t>(str, width, fill);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
namespace internal
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
|
class ArgMap
|
|
|
|
@ -2285,7 +2306,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;
|
|
|
|
|
}
|
|
|
|
@ -2351,7 +2373,8 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
|
|
|
|
|
|
|
|
|
void visit_bool(bool value)
|
|
|
|
|
{
|
|
|
|
|
if (spec_.type_) {
|
|
|
|
|
if (spec_.type_)
|
|
|
|
|
{
|
|
|
|
|
visit_any_int(value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -2360,7 +2383,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;
|
|
|
|
@ -2371,22 +2395,27 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
|
|
|
|
Char fill = internal::CharTraits<Char>::cast(spec_.fill());
|
|
|
|
|
CharPtr out = CharPtr();
|
|
|
|
|
const unsigned CHAR_SIZE = 1;
|
|
|
|
|
if (spec_.width_ > CHAR_SIZE) {
|
|
|
|
|
if (spec_.width_ > CHAR_SIZE)
|
|
|
|
|
{
|
|
|
|
|
out = writer_.grow_buffer(spec_.width_);
|
|
|
|
|
if (spec_.align_ == ALIGN_RIGHT) {
|
|
|
|
|
if (spec_.align_ == ALIGN_RIGHT)
|
|
|
|
|
{
|
|
|
|
|
std::uninitialized_fill_n(out, spec_.width_ - CHAR_SIZE, fill);
|
|
|
|
|
out += spec_.width_ - CHAR_SIZE;
|
|
|
|
|
}
|
|
|
|
|
else if (spec_.align_ == ALIGN_CENTER) {
|
|
|
|
|
else if (spec_.align_ == ALIGN_CENTER)
|
|
|
|
|
{
|
|
|
|
|
out = writer_.fill_padding(out, spec_.width_,
|
|
|
|
|
internal::const_check(CHAR_SIZE), fill);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::uninitialized_fill_n(out + CHAR_SIZE,
|
|
|
|
|
spec_.width_ - CHAR_SIZE, fill);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
out = writer_.grow_buffer(CHAR_SIZE);
|
|
|
|
|
}
|
|
|
|
|
*out = internal::CharTraits<Char>::cast(value);
|
|
|
|
@ -2458,7 +2487,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;
|
|
|
|
|
}
|
|
|
|
@ -2603,7 +2633,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;
|
|
|
|
@ -2922,11 +2953,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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -3193,21 +3226,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);
|
|
|
|
@ -3225,8 +3263,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"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -3263,7 +3303,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')
|
|
|
|
@ -3275,44 +3316,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);
|
|
|
|
@ -3329,75 +3379,100 @@ 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;
|
|
|
|
|
internal::format_decimal(get(p), abs_value, 0);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
case 'n': {
|
|
|
|
|
case 'n':
|
|
|
|
|
{
|
|
|
|
|
unsigned num_digits = internal::count_digits(abs_value);
|
|
|
|
|
fmt::StringRef sep = "";
|
|
|
|
|
#ifndef ANDROID
|
|
|
|
@ -3423,11 +3498,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':
|
|
|
|
|
#if FMT_MSC_VER
|
|
|
|
@ -3435,7 +3514,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:
|
|
|
|
@ -3446,20 +3527,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;
|
|
|
|
|
}
|
|
|
|
@ -3469,12 +3554,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;
|
|
|
|
|
}
|
|
|
|
@ -3486,7 +3573,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;
|
|
|
|
@ -3504,16 +3592,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++ = '*';
|
|
|
|
|
}
|
|
|
|
@ -3526,13 +3617,15 @@ inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
|
|
|
|
|
Char fill = internal::CharTraits<Char>::cast(spec.fill());
|
|
|
|
|
unsigned n = 0;
|
|
|
|
|
Char *start = FMT_NULL;
|
|
|
|
|
for (;;) {
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
std::size_t buffer_size = buffer_.capacity() - offset;
|
|
|
|
|
#if FMT_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;
|
|
|
|
|
}
|
|
|
|
@ -3540,37 +3633,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)
|
|
|
|
@ -3836,7 +3936,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.
|
|
|
|
@ -3845,7 +3946,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;
|
|
|
|
|
}
|
|
|
|
@ -3930,12 +4032,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;
|
|
|
|
|
}
|
|
|
|
@ -4105,14 +4210,16 @@ 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)
|
|
|
|
|
FMT_VARIADIC(void, print, std::FILE *, CStringRef)
|
|
|
|
|
FMT_VARIADIC(void, print_colored, Color, CStringRef)
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
namespace internal
|
|
|
|
|
{
|
|
|
|
|
template <typename Char>
|
|
|
|
|
inline bool is_name_start(Char c)
|
|
|
|
|
{
|
|
|
|
@ -4126,15 +4233,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)
|
|
|
|
@ -4144,7 +4254,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));
|
|
|
|
@ -4156,7 +4267,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)));
|
|
|
|
|
}
|
|
|
|
@ -4168,7 +4280,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)
|
|
|
|
@ -4184,7 +4297,8 @@ namespace fmt {
|
|
|
|
|
const char *error = FMT_NULL;
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
@ -4197,9 +4311,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 = FMT_NULL;
|
|
|
|
|
internal::Arg arg = get_arg(BasicStringRef<Char>(start, s - start), error);
|
|
|
|
|
if (error)
|
|
|
|
@ -4214,18 +4330,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;
|
|
|
|
@ -4239,8 +4360,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 '{'"));
|
|
|
|
@ -4252,11 +4375,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;
|
|
|
|
@ -4271,14 +4396,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';
|
|
|
|
@ -4286,17 +4413,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"));
|
|
|
|
@ -4322,20 +4452,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"));
|
|
|
|
@ -4359,10 +4493,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")));
|
|
|
|
@ -4387,10 +4523,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;
|
|
|
|
@ -4407,8 +4545,10 @@ namespace fmt {
|
|
|
|
|
} // namespace fmt
|
|
|
|
|
|
|
|
|
|
#if FMT_USE_USER_DEFINED_LITERALS
|
|
|
|
|
namespace fmt {
|
|
|
|
|
namespace internal {
|
|
|
|
|
namespace fmt
|
|
|
|
|
{
|
|
|
|
|
namespace internal
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
|
struct UdlFormat
|
|
|
|
@ -4437,7 +4577,8 @@ namespace fmt {
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
inline namespace literals {
|
|
|
|
|
inline namespace literals
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\rst
|
|
|
|
|