Fixed warnings conversion 'size_t' to 'int' on windows issue #119
This commit is contained in:
parent
77acf29c4d
commit
ec4233f236
@ -133,9 +133,7 @@ struct IntChecker {
|
||||
unsigned max = INT_MAX;
|
||||
return value <= max;
|
||||
}
|
||||
static bool fits_in_int(bool) {
|
||||
return true;
|
||||
}
|
||||
static bool fits_in_int(bool) { return true; }
|
||||
};
|
||||
|
||||
template <>
|
||||
@ -250,9 +248,7 @@ void report_error(FormatFunc func,
|
||||
class IsZeroInt : public fmt::internal::ArgVisitor<IsZeroInt, bool> {
|
||||
public:
|
||||
template <typename T>
|
||||
bool visit_any_int(T value) {
|
||||
return value == 0;
|
||||
}
|
||||
bool visit_any_int(T value) { return value == 0; }
|
||||
};
|
||||
|
||||
// Parses an unsigned integer advancing s to the end of the parsed input.
|
||||
@ -365,20 +361,17 @@ public:
|
||||
if (is_signed) {
|
||||
arg_.type = Arg::INT;
|
||||
arg_.int_value = static_cast<int>(static_cast<T>(value));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
arg_.type = Arg::UINT;
|
||||
arg_.uint_value = static_cast<unsigned>(
|
||||
static_cast<typename fmt::internal::MakeUnsigned<T>::Type>(value));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (is_signed) {
|
||||
arg_.type = Arg::LONG_LONG;
|
||||
arg_.long_long_value =
|
||||
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
arg_.type = Arg::ULONG_LONG;
|
||||
arg_.ulong_long_value =
|
||||
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
|
||||
@ -416,26 +409,18 @@ private:
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(BasicArgFormatter);
|
||||
|
||||
protected:
|
||||
BasicWriter<Char> &writer() {
|
||||
return writer_;
|
||||
}
|
||||
const FormatSpec &spec() const {
|
||||
return spec_;
|
||||
}
|
||||
BasicWriter<Char> &writer() { return writer_; }
|
||||
const FormatSpec &spec() const { return spec_; }
|
||||
|
||||
public:
|
||||
BasicArgFormatter(BasicWriter<Char> &w, FormatSpec &s)
|
||||
: writer_(w), spec_(s) {}
|
||||
|
||||
template <typename T>
|
||||
void visit_any_int(T value) {
|
||||
writer_.write_int(value, spec_);
|
||||
}
|
||||
void visit_any_int(T value) { writer_.write_int(value, spec_); }
|
||||
|
||||
template <typename T>
|
||||
void visit_any_double(T value) {
|
||||
writer_.write_double(value, spec_);
|
||||
}
|
||||
void visit_any_double(T value) { writer_.write_double(value, spec_); }
|
||||
|
||||
void visit_bool(bool value) {
|
||||
if (spec_.type_) {
|
||||
@ -463,15 +448,12 @@ public:
|
||||
if (spec_.align_ == ALIGN_RIGHT) {
|
||||
std::fill_n(out, spec_.width_ - 1, fill);
|
||||
out += spec_.width_ - 1;
|
||||
}
|
||||
else if (spec_.align_ == ALIGN_CENTER) {
|
||||
} else if (spec_.align_ == ALIGN_CENTER) {
|
||||
out = writer_.fill_padding(out, spec_.width_, 1, fill);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::fill_n(out + 1, spec_.width_ - 1, fill);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
out = writer_.grow_buffer(1);
|
||||
}
|
||||
*out = internal::CharTraits<Char>::cast(value);
|
||||
@ -533,12 +515,10 @@ public:
|
||||
if (fmt_spec.align_ != ALIGN_LEFT) {
|
||||
std::fill_n(out, fmt_spec.width_ - 1, fill);
|
||||
out += fmt_spec.width_ - 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::fill_n(out + 1, fmt_spec.width_ - 1, fill);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
out = w.grow_buffer(1);
|
||||
}
|
||||
*out = static_cast<Char>(value);
|
||||
@ -632,14 +612,17 @@ FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) {
|
||||
#if FMT_USE_WINDOWS_H
|
||||
|
||||
FMT_FUNC fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) {
|
||||
int length = MultiByteToWideChar(
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s.size(), 0, 0);
|
||||
static const char ERROR_MSG[] = "cannot convert string from UTF-8 to UTF-16";
|
||||
if (s.size() > INT_MAX)
|
||||
FMT_THROW(WindowsError(ERROR_INVALID_PARAMETER, ERROR_MSG));
|
||||
int s_size = static_cast<int>(s.size());
|
||||
int length = MultiByteToWideChar(
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, 0, 0);
|
||||
if (length == 0)
|
||||
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
||||
buffer_.resize(length + 1);
|
||||
length = MultiByteToWideChar(
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s.size(), &buffer_[0], length);
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, &buffer_[0], length);
|
||||
if (length == 0)
|
||||
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
||||
buffer_[length] = 0;
|
||||
@ -653,12 +636,15 @@ FMT_FUNC fmt::internal::UTF16ToUTF8::UTF16ToUTF8(fmt::WStringRef s) {
|
||||
}
|
||||
|
||||
FMT_FUNC int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) {
|
||||
int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s.size(), 0, 0, 0, 0);
|
||||
if (s.size() > INT_MAX)
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
int s_size = static_cast<int>(s.size());
|
||||
int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, 0, 0, 0, 0);
|
||||
if (length == 0)
|
||||
return GetLastError();
|
||||
buffer_.resize(length + 1);
|
||||
length = WideCharToMultiByte(
|
||||
CP_UTF8, 0, s.data(), s.size(), &buffer_[0], length, 0, 0);
|
||||
CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, 0, 0);
|
||||
if (length == 0)
|
||||
return GetLastError();
|
||||
buffer_[length] = 0;
|
||||
@ -683,12 +669,8 @@ FMT_FUNC void fmt::internal::format_windows_error(
|
||||
|
||||
public:
|
||||
String() : str_() {}
|
||||
~String() {
|
||||
LocalFree(str_);
|
||||
}
|
||||
LPWSTR *ptr() {
|
||||
return &str_;
|
||||
}
|
||||
~String() { LocalFree(str_); }
|
||||
LPWSTR *ptr() { return &str_; }
|
||||
LPCWSTR c_str() const { return str_; }
|
||||
};
|
||||
FMT_TRY {
|
||||
@ -749,8 +731,7 @@ void fmt::internal::ArgMap<Char>::init(const ArgList &args) {
|
||||
map_.insert(Pair(named_arg->name, *named_arg));
|
||||
break;
|
||||
default:
|
||||
/*nothing*/
|
||||
;
|
||||
/*nothing*/;
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -771,8 +752,7 @@ void fmt::internal::ArgMap<Char>::init(const ArgList &args) {
|
||||
map_.insert(Pair(named_arg->name, *named_arg));
|
||||
break;
|
||||
default:
|
||||
/*nothing*/
|
||||
;
|
||||
/*nothing*/;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -854,8 +834,7 @@ FMT_FUNC Arg fmt::internal::FormatterBase::do_get_arg(
|
||||
case Arg::NAMED_ARG:
|
||||
arg = *static_cast<const internal::Arg*>(arg.pointer);
|
||||
default:
|
||||
/*nothing*/
|
||||
;
|
||||
/*nothing*/;
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
@ -933,8 +912,7 @@ unsigned fmt::internal::PrintfFormatter<Char>::parse_header(
|
||||
if (*s == '$') { // value is an argument index
|
||||
++s;
|
||||
arg_index = value;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (c == '0')
|
||||
spec.fill_ = '0';
|
||||
if (value != 0) {
|
||||
@ -949,8 +927,7 @@ unsigned fmt::internal::PrintfFormatter<Char>::parse_header(
|
||||
// Parse width.
|
||||
if (*s >= '0' && *s <= '9') {
|
||||
spec.width_ = parse_nonnegative_int(s);
|
||||
}
|
||||
else if (*s == '*') {
|
||||
} else if (*s == '*') {
|
||||
++s;
|
||||
spec.width_ = WidthHandler(spec).visit(get_arg(s));
|
||||
}
|
||||
@ -983,8 +960,7 @@ void fmt::internal::PrintfFormatter<Char>::format(
|
||||
++s;
|
||||
if ('0' <= *s && *s <= '9') {
|
||||
spec.precision_ = parse_nonnegative_int(s);
|
||||
}
|
||||
else if (*s == '*') {
|
||||
} else if (*s == '*') {
|
||||
++s;
|
||||
spec.precision_ = PrecisionHandler().visit(get_arg(s));
|
||||
}
|
||||
@ -1039,8 +1015,7 @@ void fmt::internal::PrintfFormatter<Char>::format(
|
||||
if (arg.type <= Arg::LAST_INTEGER_TYPE) {
|
||||
// Normalize type.
|
||||
switch (spec.type_) {
|
||||
case 'i':
|
||||
case 'u':
|
||||
case 'i': case 'u':
|
||||
spec.type_ = 'd';
|
||||
break;
|
||||
case 'c':
|
||||
@ -1095,8 +1070,7 @@ const Char *fmt::BasicFormatter<Char>::format(
|
||||
FMT_THROW(FormatError("invalid fill character '{'"));
|
||||
s += 2;
|
||||
spec.fill_ = c;
|
||||
}
|
||||
else ++s;
|
||||
} else ++s;
|
||||
if (spec.align_ == ALIGN_NUMERIC)
|
||||
require_numeric_argument(arg, '=');
|
||||
break;
|
||||
@ -1137,8 +1111,7 @@ const Char *fmt::BasicFormatter<Char>::format(
|
||||
// Parse width.
|
||||
if ('0' <= *s && *s <= '9') {
|
||||
spec.width_ = parse_nonnegative_int(s);
|
||||
}
|
||||
else if (*s == '{') {
|
||||
} else if (*s == '{') {
|
||||
++s;
|
||||
Arg width_arg = is_name_start(*s) ?
|
||||
parse_arg_name(s) : parse_arg_index(s);
|
||||
@ -1176,8 +1149,7 @@ const Char *fmt::BasicFormatter<Char>::format(
|
||||
spec.precision_ = 0;
|
||||
if ('0' <= *s && *s <= '9') {
|
||||
spec.precision_ = parse_nonnegative_int(s);
|
||||
}
|
||||
else if (*s == '{') {
|
||||
} else if (*s == '{') {
|
||||
++s;
|
||||
Arg precision_arg =
|
||||
is_name_start(*s) ? parse_arg_name(s) : parse_arg_index(s);
|
||||
@ -1207,8 +1179,7 @@ const Char *fmt::BasicFormatter<Char>::format(
|
||||
if (value > INT_MAX)
|
||||
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) {
|
||||
|
@ -266,14 +266,10 @@ public:
|
||||
}
|
||||
|
||||
/** Returns the pointer to a C string. */
|
||||
const Char *data() const {
|
||||
return data_;
|
||||
}
|
||||
const Char *data() const { return data_; }
|
||||
|
||||
/** Returns the string size. */
|
||||
std::size_t size() const {
|
||||
return size_;
|
||||
}
|
||||
std::size_t size() const { return size_; }
|
||||
|
||||
friend bool operator==(BasicStringRef lhs, BasicStringRef rhs) {
|
||||
return lhs.data_ == rhs.data_;
|
||||
@ -333,9 +329,7 @@ public:
|
||||
BasicCStringRef(const std::basic_string<Char> &s) : data_(s.c_str()) {}
|
||||
|
||||
/** Returns the pointer to a C string. */
|
||||
const Char *c_str() const {
|
||||
return data_;
|
||||
}
|
||||
const Char *c_str() const { return data_; }
|
||||
};
|
||||
|
||||
typedef BasicCStringRef<char> CStringRef;
|
||||
@ -363,9 +357,7 @@ inline stdext::checked_array_iterator<T*> make_ptr(T *ptr, std::size_t size) {
|
||||
}
|
||||
#else
|
||||
template <typename T>
|
||||
inline T *make_ptr(T *ptr, std::size_t) {
|
||||
return ptr;
|
||||
}
|
||||
inline T *make_ptr(T *ptr, std::size_t) { return ptr; }
|
||||
#endif
|
||||
} // namespace internal
|
||||
|
||||
@ -399,14 +391,10 @@ public:
|
||||
virtual ~Buffer() {}
|
||||
|
||||
/** Returns the size of this buffer. */
|
||||
std::size_t size() const {
|
||||
return size_;
|
||||
}
|
||||
std::size_t size() const { return size_; }
|
||||
|
||||
/** Returns the capacity of this buffer. */
|
||||
std::size_t capacity() const {
|
||||
return capacity_;
|
||||
}
|
||||
std::size_t capacity() const { return capacity_; }
|
||||
|
||||
/**
|
||||
Resizes the buffer. If T is a POD type new elements may not be initialized.
|
||||
@ -439,12 +427,8 @@ public:
|
||||
template <typename U>
|
||||
void append(const U *begin, const U *end);
|
||||
|
||||
T &operator[](std::size_t index) {
|
||||
return ptr_[index];
|
||||
}
|
||||
const T &operator[](std::size_t index) const {
|
||||
return ptr_[index];
|
||||
}
|
||||
T &operator[](std::size_t index) { return ptr_[index]; }
|
||||
const T &operator[](std::size_t index) const { return ptr_[index]; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@ -477,9 +461,7 @@ protected:
|
||||
public:
|
||||
explicit MemoryBuffer(const Allocator &alloc = Allocator())
|
||||
: Allocator(alloc), Buffer<T>(data_, SIZE) {}
|
||||
~MemoryBuffer() {
|
||||
free();
|
||||
}
|
||||
~MemoryBuffer() { free(); }
|
||||
|
||||
#if FMT_USE_RVALUE_REFERENCES
|
||||
private:
|
||||
@ -493,8 +475,7 @@ private:
|
||||
this->ptr_ = data_;
|
||||
std::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 freeing.
|
||||
@ -516,9 +497,7 @@ public:
|
||||
#endif
|
||||
|
||||
// Returns a copy of the allocator associated with this buffer.
|
||||
Allocator get_allocator() const {
|
||||
return *this;
|
||||
}
|
||||
Allocator get_allocator() const { return *this; }
|
||||
};
|
||||
|
||||
template <typename T, std::size_t SIZE, typename Allocator>
|
||||
@ -564,19 +543,11 @@ inline int getsign(double x) {
|
||||
|
||||
// Portable version of isinf.
|
||||
# ifdef isinf
|
||||
inline int isinfinity(double x) {
|
||||
return isinf(x);
|
||||
}
|
||||
inline int isinfinity(long double x) {
|
||||
return isinf(x);
|
||||
}
|
||||
inline int isinfinity(double x) { return isinf(x); }
|
||||
inline int isinfinity(long double x) { return isinf(x); }
|
||||
# else
|
||||
inline int isinfinity(double x) {
|
||||
return std::isinf(x);
|
||||
}
|
||||
inline int isinfinity(long double x) {
|
||||
return std::isinf(x);
|
||||
}
|
||||
inline int isinfinity(double x) { return std::isinf(x); }
|
||||
inline int isinfinity(long double x) { return std::isinf(x); }
|
||||
# endif
|
||||
#else
|
||||
inline int getsign(double value) {
|
||||
@ -587,9 +558,7 @@ inline int getsign(double value) {
|
||||
_ecvt_s(buffer, sizeof(buffer), value, 0, &dec, &sign);
|
||||
return sign;
|
||||
}
|
||||
inline int isinfinity(double x) {
|
||||
return !_finite(x);
|
||||
}
|
||||
inline int isinfinity(double x) { return !_finite(x); }
|
||||
inline int isinfinity(long double x) {
|
||||
return !_finite(static_cast<double>(x));
|
||||
}
|
||||
@ -603,9 +572,7 @@ public:
|
||||
#else
|
||||
typedef Char *CharPtr;
|
||||
#endif
|
||||
static Char cast(wchar_t value) {
|
||||
return static_cast<Char>(value);
|
||||
}
|
||||
static Char cast(wchar_t value) { return static_cast<Char>(value); }
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
@ -618,9 +585,7 @@ private:
|
||||
static char convert(wchar_t);
|
||||
|
||||
public:
|
||||
static char convert(char value) {
|
||||
return value;
|
||||
}
|
||||
static char convert(char value) { return value; }
|
||||
|
||||
// Formats a floating-point number.
|
||||
template <typename T>
|
||||
@ -631,12 +596,8 @@ public:
|
||||
template <>
|
||||
class CharTraits<wchar_t> : public BasicCharTraits<wchar_t> {
|
||||
public:
|
||||
static wchar_t convert(char value) {
|
||||
return value;
|
||||
}
|
||||
static wchar_t convert(wchar_t value) {
|
||||
return value;
|
||||
}
|
||||
static wchar_t convert(char value) { return value; }
|
||||
static wchar_t convert(wchar_t value) { return value; }
|
||||
|
||||
template <typename T>
|
||||
static int format_float(wchar_t *buffer, std::size_t size,
|
||||
@ -647,17 +608,13 @@ public:
|
||||
template <bool IsSigned>
|
||||
struct SignChecker {
|
||||
template <typename T>
|
||||
static bool is_negative(T value) {
|
||||
return value < 0;
|
||||
}
|
||||
static bool is_negative(T value) { return value < 0; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SignChecker<false> {
|
||||
template <typename T>
|
||||
static bool is_negative(T) {
|
||||
return false;
|
||||
}
|
||||
static bool is_negative(T) { return false; }
|
||||
};
|
||||
|
||||
// Returns true if value is negative, false otherwise.
|
||||
@ -669,14 +626,10 @@ inline bool is_negative(T value) {
|
||||
|
||||
// Selects uint32_t if FitsIn32Bits is true, uint64_t otherwise.
|
||||
template <bool FitsIn32Bits>
|
||||
struct TypeSelector {
|
||||
typedef uint32_t Type;
|
||||
};
|
||||
struct TypeSelector { typedef uint32_t Type; };
|
||||
|
||||
template <>
|
||||
struct TypeSelector<false> {
|
||||
typedef uint64_t Type;
|
||||
};
|
||||
struct TypeSelector<false> { typedef uint64_t Type; };
|
||||
|
||||
template <typename T>
|
||||
struct IntTraits {
|
||||
@ -688,9 +641,7 @@ struct IntTraits {
|
||||
|
||||
// MakeUnsigned<T>::Type gives an unsigned type corresponding to integer type T.
|
||||
template <typename T>
|
||||
struct MakeUnsigned {
|
||||
typedef T Type;
|
||||
};
|
||||
struct MakeUnsigned { typedef T Type; };
|
||||
|
||||
#define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \
|
||||
template <> \
|
||||
@ -798,18 +749,10 @@ private:
|
||||
|
||||
public:
|
||||
explicit UTF8ToUTF16(StringRef s);
|
||||
operator WStringRef() const {
|
||||
return WStringRef(&buffer_[0], size());
|
||||
}
|
||||
size_t size() const {
|
||||
return buffer_.size() - 1;
|
||||
}
|
||||
const wchar_t *c_str() const {
|
||||
return &buffer_[0];
|
||||
}
|
||||
std::wstring str() const {
|
||||
return std::wstring(&buffer_[0], size());
|
||||
}
|
||||
operator WStringRef() const { return WStringRef(&buffer_[0], size()); }
|
||||
size_t size() const { return buffer_.size() - 1; }
|
||||
const wchar_t *c_str() const { return &buffer_[0]; }
|
||||
std::wstring str() const { return std::wstring(&buffer_[0], size()); }
|
||||
};
|
||||
|
||||
// A converter from UTF-16 to UTF-8.
|
||||
@ -821,18 +764,10 @@ private:
|
||||
public:
|
||||
UTF16ToUTF8() {}
|
||||
explicit UTF16ToUTF8(WStringRef s);
|
||||
operator StringRef() const {
|
||||
return StringRef(&buffer_[0], size());
|
||||
}
|
||||
size_t size() const {
|
||||
return buffer_.size() - 1;
|
||||
}
|
||||
const char *c_str() const {
|
||||
return &buffer_[0];
|
||||
}
|
||||
std::string str() const {
|
||||
return std::string(&buffer_[0], size());
|
||||
}
|
||||
operator StringRef() const { return StringRef(&buffer_[0], size()); }
|
||||
size_t size() const { return buffer_.size() - 1; }
|
||||
const char *c_str() const { return &buffer_[0]; }
|
||||
std::string str() const { return std::string(&buffer_[0], size()); }
|
||||
|
||||
// Performs conversion returning a system error code instead of
|
||||
// throwing exception on conversion error. This method may still throw
|
||||
@ -945,25 +880,17 @@ template<bool B, class T = void>
|
||||
struct EnableIf {};
|
||||
|
||||
template<class T>
|
||||
struct EnableIf<true, T> {
|
||||
typedef T type;
|
||||
};
|
||||
struct EnableIf<true, T> { typedef T type; };
|
||||
|
||||
template<bool B, class T, class F>
|
||||
struct Conditional {
|
||||
typedef T type;
|
||||
};
|
||||
struct Conditional { typedef T type; };
|
||||
|
||||
template<class T, class F>
|
||||
struct Conditional<false, T, F> {
|
||||
typedef F type;
|
||||
};
|
||||
struct Conditional<false, T, F> { typedef F type; };
|
||||
|
||||
// A helper function to suppress bogus "conditional expression is constant"
|
||||
// warnings.
|
||||
inline bool check(bool value) {
|
||||
return value;
|
||||
}
|
||||
inline bool check(bool value) { return value; }
|
||||
|
||||
// Makes an Arg object from any type.
|
||||
template <typename Char>
|
||||
@ -1059,9 +986,7 @@ public:
|
||||
MakeValue(typename WCharHelper<wchar_t, Char>::Supported value) {
|
||||
int_value = value;
|
||||
}
|
||||
static uint64_t type(wchar_t) {
|
||||
return Arg::CHAR;
|
||||
}
|
||||
static uint64_t type(wchar_t) { return Arg::CHAR; }
|
||||
|
||||
#define FMT_MAKE_STR_VALUE(Type, TYPE) \
|
||||
MakeValue(Type value) { set_string(value); } \
|
||||
@ -1110,14 +1035,10 @@ public:
|
||||
// Additional template param `Char_` is needed here because make_type always
|
||||
// uses MakeValue<char>.
|
||||
template <typename Char_>
|
||||
MakeValue(const NamedArg<Char_> &value) {
|
||||
pointer = &value;
|
||||
}
|
||||
MakeValue(const NamedArg<Char_> &value) { pointer = &value; }
|
||||
|
||||
template <typename Char_>
|
||||
static uint64_t type(const NamedArg<Char_> &) {
|
||||
return Arg::NAMED_ARG;
|
||||
}
|
||||
static uint64_t type(const NamedArg<Char_> &) { return Arg::NAMED_ARG; }
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
@ -1357,9 +1278,7 @@ private:
|
||||
Arg do_get_arg(unsigned arg_index, const char *&error);
|
||||
|
||||
protected:
|
||||
const ArgList &args() const {
|
||||
return args_;
|
||||
}
|
||||
const ArgList &args() const { return args_; }
|
||||
|
||||
explicit FormatterBase(const ArgList &args) {
|
||||
args_ = args;
|
||||
@ -1427,9 +1346,7 @@ public:
|
||||
BasicFormatter(const ArgList &args, BasicWriter<Char> &w)
|
||||
: FormatterBase(args), writer_(w) {}
|
||||
|
||||
BasicWriter<Char> &writer() {
|
||||
return writer_;
|
||||
}
|
||||
BasicWriter<Char> &writer() { return writer_; }
|
||||
|
||||
void format(BasicCStringRef<Char> format_str);
|
||||
|
||||
@ -1452,24 +1369,12 @@ struct EmptySpec {};
|
||||
// A type specifier.
|
||||
template <char TYPE>
|
||||
struct TypeSpec : EmptySpec {
|
||||
Alignment align() const {
|
||||
return ALIGN_DEFAULT;
|
||||
}
|
||||
unsigned width() const {
|
||||
return 0;
|
||||
}
|
||||
int precision() const {
|
||||
return -1;
|
||||
}
|
||||
bool flag(unsigned) const {
|
||||
return false;
|
||||
}
|
||||
char type() const {
|
||||
return TYPE;
|
||||
}
|
||||
char fill() const {
|
||||
return ' ';
|
||||
}
|
||||
Alignment align() const { return ALIGN_DEFAULT; }
|
||||
unsigned width() const { return 0; }
|
||||
int precision() const { return -1; }
|
||||
bool flag(unsigned) const { return false; }
|
||||
char type() const { return TYPE; }
|
||||
char fill() const { return ' '; }
|
||||
};
|
||||
|
||||
// A width specifier.
|
||||
@ -1481,12 +1386,8 @@ struct WidthSpec {
|
||||
|
||||
WidthSpec(unsigned width, wchar_t fill) : width_(width), fill_(fill) {}
|
||||
|
||||
unsigned width() const {
|
||||
return width_;
|
||||
}
|
||||
wchar_t fill() const {
|
||||
return fill_;
|
||||
}
|
||||
unsigned width() const { return width_; }
|
||||
wchar_t fill() const { return fill_; }
|
||||
};
|
||||
|
||||
// An alignment specifier.
|
||||
@ -1496,13 +1397,9 @@ struct AlignSpec : WidthSpec {
|
||||
AlignSpec(unsigned width, wchar_t fill, Alignment align = ALIGN_DEFAULT)
|
||||
: WidthSpec(width, fill), align_(align) {}
|
||||
|
||||
Alignment align() const {
|
||||
return align_;
|
||||
}
|
||||
Alignment align() const { return align_; }
|
||||
|
||||
int precision() const {
|
||||
return -1;
|
||||
}
|
||||
int precision() const { return -1; }
|
||||
};
|
||||
|
||||
// An alignment and type specifier.
|
||||
@ -1510,12 +1407,8 @@ template <char TYPE>
|
||||
struct AlignTypeSpec : AlignSpec {
|
||||
AlignTypeSpec(unsigned width, wchar_t fill) : AlignSpec(width, fill) {}
|
||||
|
||||
bool flag(unsigned) const {
|
||||
return false;
|
||||
}
|
||||
char type() const {
|
||||
return TYPE;
|
||||
}
|
||||
bool flag(unsigned) const { return false; }
|
||||
char type() const { return TYPE; }
|
||||
};
|
||||
|
||||
// A full format specifier.
|
||||
@ -1528,15 +1421,9 @@ struct FormatSpec : AlignSpec {
|
||||
unsigned width = 0, char type = 0, wchar_t fill = ' ')
|
||||
: AlignSpec(width, fill), flags_(0), precision_(-1), type_(type) {}
|
||||
|
||||
bool flag(unsigned f) const {
|
||||
return (flags_ & f) != 0;
|
||||
}
|
||||
int precision() const {
|
||||
return precision_;
|
||||
}
|
||||
char type() const {
|
||||
return type_;
|
||||
}
|
||||
bool flag(unsigned f) const { return (flags_ & f) != 0; }
|
||||
int precision() const { return precision_; }
|
||||
char type() const { return type_; }
|
||||
};
|
||||
|
||||
// An integer format specifier.
|
||||
@ -1549,9 +1436,7 @@ public:
|
||||
IntFormatSpec(T val, const SpecT &spec = SpecT())
|
||||
: SpecT(spec), value_(val) {}
|
||||
|
||||
T value() const {
|
||||
return value_;
|
||||
}
|
||||
T value() const { return value_; }
|
||||
};
|
||||
|
||||
// A string format specifier.
|
||||
@ -1567,9 +1452,7 @@ public:
|
||||
internal::CharTraits<Char>::convert(FillChar());
|
||||
}
|
||||
|
||||
const Char *str() const {
|
||||
return str_;
|
||||
}
|
||||
const Char *str() const { return str_; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1711,14 +1594,10 @@ inline StrFormatSpec<wchar_t> pad(
|
||||
# define FMT_GEN15(f) FMT_GEN14(f), f(14)
|
||||
|
||||
namespace internal {
|
||||
inline uint64_t make_type() {
|
||||
return 0;
|
||||
}
|
||||
inline uint64_t make_type() { return 0; }
|
||||
|
||||
template <typename T>
|
||||
inline uint64_t make_type(const T &arg) {
|
||||
return MakeValue<char>::type(arg);
|
||||
}
|
||||
inline uint64_t make_type(const T &arg) { return MakeValue<char>::type(arg); }
|
||||
|
||||
template <unsigned N>
|
||||
struct ArgArray {
|
||||
@ -1937,9 +1816,7 @@ public:
|
||||
}
|
||||
FMT_VARIADIC_CTOR(SystemError, init, int, CStringRef)
|
||||
|
||||
int error_code() const {
|
||||
return error_code_;
|
||||
}
|
||||
int error_code() const { return error_code_; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1972,13 +1849,9 @@ private:
|
||||
|
||||
#if _SECURE_SCL
|
||||
// Returns pointer value.
|
||||
static Char *get(CharPtr p) {
|
||||
return p.base();
|
||||
}
|
||||
static Char *get(CharPtr p) { return p.base(); }
|
||||
#else
|
||||
static Char *get(Char *p) {
|
||||
return p;
|
||||
}
|
||||
static Char *get(Char *p) { return p; }
|
||||
#endif
|
||||
|
||||
// Fills the padding around the content and returns the pointer to the
|
||||
@ -2010,8 +1883,7 @@ private:
|
||||
if (internal::is_negative(value)) {
|
||||
abs_value = 0 - abs_value;
|
||||
*write_unsigned_decimal(abs_value, 1) = '-';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
write_unsigned_decimal(abs_value, 0);
|
||||
}
|
||||
}
|
||||
@ -2085,17 +1957,13 @@ public:
|
||||
/**
|
||||
Returns the total number of characters written.
|
||||
*/
|
||||
std::size_t size() const {
|
||||
return buffer_.size();
|
||||
}
|
||||
std::size_t size() const { return buffer_.size(); }
|
||||
|
||||
/**
|
||||
Returns a pointer to the output buffer content. No terminating null
|
||||
character is appended.
|
||||
*/
|
||||
const Char *data() const FMT_NOEXCEPT {
|
||||
return &buffer_[0];
|
||||
}
|
||||
const Char *data() const FMT_NOEXCEPT { return &buffer_[0]; }
|
||||
|
||||
/**
|
||||
Returns a pointer to the output buffer content with terminating null
|
||||
@ -2251,15 +2119,12 @@ typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str(
|
||||
if (spec.align() == ALIGN_RIGHT) {
|
||||
std::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::fill_n(out + size, spec.width() - size, fill);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
out = grow_buffer(size);
|
||||
}
|
||||
std::copy(s, s + size, out);
|
||||
@ -2325,20 +2190,17 @@ BasicWriter<Char>::prepare_int_buffer(
|
||||
std::copy(prefix, prefix + prefix_size, p);
|
||||
p += size;
|
||||
std::fill(p, end, fill);
|
||||
}
|
||||
else if (align == ALIGN_CENTER) {
|
||||
} else if (align == ALIGN_CENTER) {
|
||||
p = fill_padding(p, width, size, fill);
|
||||
std::copy(prefix, prefix + prefix_size, p);
|
||||
p += size;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (align == ALIGN_NUMERIC) {
|
||||
if (prefix_size != 0) {
|
||||
p = std::copy(prefix, prefix + prefix_size, p);
|
||||
size -= prefix_size;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::copy(prefix, prefix + prefix_size, end - size);
|
||||
}
|
||||
std::fill(p, end - size, fill);
|
||||
@ -2358,22 +2220,19 @@ void BasicWriter<Char>::write_int(T value, Spec spec) {
|
||||
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': {
|
||||
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)) {
|
||||
prefix[prefix_size++] = '0';
|
||||
@ -2393,8 +2252,7 @@ void BasicWriter<Char>::write_int(T value, Spec spec) {
|
||||
} while ((n >>= 4) != 0);
|
||||
break;
|
||||
}
|
||||
case 'b':
|
||||
case 'B': {
|
||||
case 'b': case 'B': {
|
||||
UnsignedType n = abs_value;
|
||||
if (spec.flag(HASH_FLAG)) {
|
||||
prefix[prefix_size++] = '0';
|
||||
@ -2444,10 +2302,7 @@ void BasicWriter<Char>::write_double(
|
||||
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
|
||||
@ -2455,9 +2310,7 @@ void BasicWriter<Char>::write_double(
|
||||
type = 'f';
|
||||
#endif
|
||||
// Fall through.
|
||||
case 'E':
|
||||
case 'G':
|
||||
case 'A':
|
||||
case 'E': case 'G': case 'A':
|
||||
upper = true;
|
||||
break;
|
||||
default:
|
||||
@ -2471,8 +2324,7 @@ void BasicWriter<Char>::write_double(
|
||||
if (internal::getsign(static_cast<double>(value))) {
|
||||
sign = '-';
|
||||
value = -value;
|
||||
}
|
||||
else if (spec.flag(SIGN_FLAG)) {
|
||||
} else if (spec.flag(SIGN_FLAG)) {
|
||||
sign = spec.flag(PLUS_FLAG) ? '+' : ' ';
|
||||
}
|
||||
|
||||
@ -2525,8 +2377,7 @@ void BasicWriter<Char>::write_double(
|
||||
*format_ptr++ = '#';
|
||||
if (spec.align() == ALIGN_CENTER) {
|
||||
width_for_sprintf = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (spec.align() == ALIGN_LEFT)
|
||||
*format_ptr++ = '-';
|
||||
if (width != 0)
|
||||
@ -2563,8 +2414,7 @@ void BasicWriter<Char>::write_double(
|
||||
*start != ' ') {
|
||||
*(start - 1) = sign;
|
||||
sign = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*(start - 1) = fill;
|
||||
}
|
||||
++n;
|
||||
@ -2926,15 +2776,9 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
explicit FormatInt(int value) {
|
||||
FormatSigned(value);
|
||||
}
|
||||
explicit FormatInt(long value) {
|
||||
FormatSigned(value);
|
||||
}
|
||||
explicit FormatInt(LongLong value) {
|
||||
FormatSigned(value);
|
||||
}
|
||||
explicit FormatInt(int value) { FormatSigned(value); }
|
||||
explicit FormatInt(long value) { FormatSigned(value); }
|
||||
explicit FormatInt(LongLong value) { FormatSigned(value); }
|
||||
explicit FormatInt(unsigned value) : str_(format_decimal(value)) {}
|
||||
explicit FormatInt(unsigned long value) : str_(format_decimal(value)) {}
|
||||
explicit FormatInt(ULongLong value) : str_(format_decimal(value)) {}
|
||||
@ -2942,17 +2786,13 @@ public:
|
||||
/**
|
||||
Returns the number of characters written to the output buffer.
|
||||
*/
|
||||
std::size_t size() const {
|
||||
return buffer_ - str_ + BUFFER_SIZE - 1;
|
||||
}
|
||||
std::size_t size() const { return buffer_ - str_ + BUFFER_SIZE - 1; }
|
||||
|
||||
/**
|
||||
Returns a pointer to the output buffer content. No terminating null
|
||||
character is appended.
|
||||
*/
|
||||
const char *data() const {
|
||||
return str_;
|
||||
}
|
||||
const char *data() const { return str_; }
|
||||
|
||||
/**
|
||||
Returns a pointer to the output buffer content with terminating null
|
||||
@ -2968,9 +2808,7 @@ public:
|
||||
Returns the content of the output buffer as an ``std::string``.
|
||||
\endrst
|
||||
*/
|
||||
std::string str() const {
|
||||
return std::string(str_, size());
|
||||
}
|
||||
std::string str() const { return std::string(str_, size()); }
|
||||
};
|
||||
|
||||
// Formats a decimal integer value writing into buffer and returns
|
||||
|
Loading…
Reference in New Issue
Block a user