mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
Fixed warnings conversion 'size_t' to 'int' on windows issue #119
This commit is contained in:
parent
77acf29c4d
commit
ec4233f236
@ -1,29 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
Formatting library for C++
|
Formatting library for C++
|
||||||
|
|
||||||
Copyright (c) 2012 - 2015, Victor Zverovich
|
Copyright (c) 2012 - 2015, Victor Zverovich
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
|
|
||||||
@ -133,9 +133,7 @@ struct IntChecker {
|
|||||||
unsigned max = INT_MAX;
|
unsigned max = INT_MAX;
|
||||||
return value <= max;
|
return value <= max;
|
||||||
}
|
}
|
||||||
static bool fits_in_int(bool) {
|
static bool fits_in_int(bool) { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
@ -148,7 +146,7 @@ struct IntChecker<true> {
|
|||||||
|
|
||||||
const char RESET_COLOR[] = "\x1b[0m";
|
const char RESET_COLOR[] = "\x1b[0m";
|
||||||
|
|
||||||
typedef void(*FormatFunc)(fmt::Writer &, int, fmt::StringRef);
|
typedef void (*FormatFunc)(fmt::Writer &, int, fmt::StringRef);
|
||||||
|
|
||||||
// Portable thread-safe version of strerror.
|
// Portable thread-safe version of strerror.
|
||||||
// Sets buffer to point to a string describing the error code.
|
// Sets buffer to point to a string describing the error code.
|
||||||
@ -160,7 +158,7 @@ typedef void(*FormatFunc)(fmt::Writer &, int, fmt::StringRef);
|
|||||||
// other - failure
|
// other - failure
|
||||||
// Buffer should be at least of size 1.
|
// Buffer should be at least of size 1.
|
||||||
int safe_strerror(
|
int safe_strerror(
|
||||||
int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT{
|
int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT {
|
||||||
FMT_ASSERT(buffer != 0 && buffer_size != 0, "invalid buffer");
|
FMT_ASSERT(buffer != 0 && buffer_size != 0, "invalid buffer");
|
||||||
|
|
||||||
class StrError {
|
class StrError {
|
||||||
@ -219,7 +217,7 @@ int safe_strerror(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void format_error_code(fmt::Writer &out, int error_code,
|
void format_error_code(fmt::Writer &out, int error_code,
|
||||||
fmt::StringRef message) FMT_NOEXCEPT{
|
fmt::StringRef message) FMT_NOEXCEPT {
|
||||||
// Report error code making sure that the output fits into
|
// Report error code making sure that the output fits into
|
||||||
// INLINE_BUFFER_SIZE to avoid dynamic memory allocation and potential
|
// INLINE_BUFFER_SIZE to avoid dynamic memory allocation and potential
|
||||||
// bad_alloc.
|
// bad_alloc.
|
||||||
@ -237,7 +235,7 @@ void format_error_code(fmt::Writer &out, int error_code,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void report_error(FormatFunc func,
|
void report_error(FormatFunc func,
|
||||||
int error_code, fmt::StringRef message) FMT_NOEXCEPT{
|
int error_code, fmt::StringRef message) FMT_NOEXCEPT {
|
||||||
fmt::MemoryWriter full_message;
|
fmt::MemoryWriter full_message;
|
||||||
func(full_message, error_code, message);
|
func(full_message, error_code, message);
|
||||||
// Use Writer::data instead of Writer::c_str to avoid potential memory
|
// Use Writer::data instead of Writer::c_str to avoid potential memory
|
||||||
@ -248,11 +246,9 @@ void report_error(FormatFunc func,
|
|||||||
|
|
||||||
// IsZeroInt::visit(arg) returns true iff arg is a zero integer.
|
// IsZeroInt::visit(arg) returns true iff arg is a zero integer.
|
||||||
class IsZeroInt : public fmt::internal::ArgVisitor<IsZeroInt, bool> {
|
class IsZeroInt : public fmt::internal::ArgVisitor<IsZeroInt, bool> {
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool visit_any_int(T value) {
|
bool visit_any_int(T value) { return value == 0; }
|
||||||
return value == 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parses an unsigned integer advancing s to the end of the parsed input.
|
// Parses an unsigned integer advancing s to the end of the parsed input.
|
||||||
@ -302,12 +298,12 @@ void check_sign(const Char *&s, const Arg &arg) {
|
|||||||
// Checks if an argument is a valid printf width specifier and sets
|
// Checks if an argument is a valid printf width specifier and sets
|
||||||
// left alignment if it is negative.
|
// left alignment if it is negative.
|
||||||
class WidthHandler : public fmt::internal::ArgVisitor<WidthHandler, unsigned> {
|
class WidthHandler : public fmt::internal::ArgVisitor<WidthHandler, unsigned> {
|
||||||
private:
|
private:
|
||||||
fmt::FormatSpec &spec_;
|
fmt::FormatSpec &spec_;
|
||||||
|
|
||||||
FMT_DISALLOW_COPY_AND_ASSIGN(WidthHandler);
|
FMT_DISALLOW_COPY_AND_ASSIGN(WidthHandler);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WidthHandler(fmt::FormatSpec &spec) : spec_(spec) {}
|
explicit WidthHandler(fmt::FormatSpec &spec) : spec_(spec) {}
|
||||||
|
|
||||||
void report_unhandled_arg() {
|
void report_unhandled_arg() {
|
||||||
@ -330,7 +326,7 @@ public:
|
|||||||
|
|
||||||
class PrecisionHandler :
|
class PrecisionHandler :
|
||||||
public fmt::internal::ArgVisitor<PrecisionHandler, int> {
|
public fmt::internal::ArgVisitor<PrecisionHandler, int> {
|
||||||
public:
|
public:
|
||||||
void report_unhandled_arg() {
|
void report_unhandled_arg() {
|
||||||
FMT_THROW(fmt::FormatError("precision is not integer"));
|
FMT_THROW(fmt::FormatError("precision is not integer"));
|
||||||
}
|
}
|
||||||
@ -346,13 +342,13 @@ public:
|
|||||||
// Converts an integer argument to an integral type T for printf.
|
// Converts an integer argument to an integral type T for printf.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
|
class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
|
||||||
private:
|
private:
|
||||||
fmt::internal::Arg &arg_;
|
fmt::internal::Arg &arg_;
|
||||||
wchar_t type_;
|
wchar_t type_;
|
||||||
|
|
||||||
FMT_DISALLOW_COPY_AND_ASSIGN(ArgConverter);
|
FMT_DISALLOW_COPY_AND_ASSIGN(ArgConverter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ArgConverter(fmt::internal::Arg &arg, wchar_t type)
|
ArgConverter(fmt::internal::Arg &arg, wchar_t type)
|
||||||
: arg_(arg), type_(type) {}
|
: arg_(arg), type_(type) {}
|
||||||
|
|
||||||
@ -365,20 +361,17 @@ public:
|
|||||||
if (is_signed) {
|
if (is_signed) {
|
||||||
arg_.type = Arg::INT;
|
arg_.type = Arg::INT;
|
||||||
arg_.int_value = static_cast<int>(static_cast<T>(value));
|
arg_.int_value = static_cast<int>(static_cast<T>(value));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
arg_.type = Arg::UINT;
|
arg_.type = Arg::UINT;
|
||||||
arg_.uint_value = static_cast<unsigned>(
|
arg_.uint_value = static_cast<unsigned>(
|
||||||
static_cast<typename fmt::internal::MakeUnsigned<T>::Type>(value));
|
static_cast<typename fmt::internal::MakeUnsigned<T>::Type>(value));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (is_signed) {
|
if (is_signed) {
|
||||||
arg_.type = Arg::LONG_LONG;
|
arg_.type = Arg::LONG_LONG;
|
||||||
arg_.long_long_value =
|
arg_.long_long_value =
|
||||||
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
|
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
arg_.type = Arg::ULONG_LONG;
|
arg_.type = Arg::ULONG_LONG;
|
||||||
arg_.ulong_long_value =
|
arg_.ulong_long_value =
|
||||||
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
|
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
|
||||||
@ -389,12 +382,12 @@ public:
|
|||||||
|
|
||||||
// Converts an integer argument to char for printf.
|
// Converts an integer argument to char for printf.
|
||||||
class CharConverter : public fmt::internal::ArgVisitor<CharConverter, void> {
|
class CharConverter : public fmt::internal::ArgVisitor<CharConverter, void> {
|
||||||
private:
|
private:
|
||||||
fmt::internal::Arg &arg_;
|
fmt::internal::Arg &arg_;
|
||||||
|
|
||||||
FMT_DISALLOW_COPY_AND_ASSIGN(CharConverter);
|
FMT_DISALLOW_COPY_AND_ASSIGN(CharConverter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CharConverter(fmt::internal::Arg &arg) : arg_(arg) {}
|
explicit CharConverter(fmt::internal::Arg &arg) : arg_(arg) {}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -409,33 +402,25 @@ namespace internal {
|
|||||||
|
|
||||||
template <typename Impl, typename Char>
|
template <typename Impl, typename Char>
|
||||||
class BasicArgFormatter : public ArgVisitor<Impl, void> {
|
class BasicArgFormatter : public ArgVisitor<Impl, void> {
|
||||||
private:
|
private:
|
||||||
BasicWriter<Char> &writer_;
|
BasicWriter<Char> &writer_;
|
||||||
FormatSpec &spec_;
|
FormatSpec &spec_;
|
||||||
|
|
||||||
FMT_DISALLOW_COPY_AND_ASSIGN(BasicArgFormatter);
|
FMT_DISALLOW_COPY_AND_ASSIGN(BasicArgFormatter);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BasicWriter<Char> &writer() {
|
BasicWriter<Char> &writer() { return writer_; }
|
||||||
return writer_;
|
const FormatSpec &spec() const { return spec_; }
|
||||||
}
|
|
||||||
const FormatSpec &spec() const {
|
|
||||||
return spec_;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BasicArgFormatter(BasicWriter<Char> &w, FormatSpec &s)
|
BasicArgFormatter(BasicWriter<Char> &w, FormatSpec &s)
|
||||||
: writer_(w), spec_(s) {}
|
: writer_(w), spec_(s) {}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void visit_any_int(T value) {
|
void visit_any_int(T value) { writer_.write_int(value, spec_); }
|
||||||
writer_.write_int(value, spec_);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void visit_any_double(T value) {
|
void visit_any_double(T value) { writer_.write_double(value, spec_); }
|
||||||
writer_.write_double(value, spec_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void visit_bool(bool value) {
|
void visit_bool(bool value) {
|
||||||
if (spec_.type_) {
|
if (spec_.type_) {
|
||||||
@ -463,15 +448,12 @@ public:
|
|||||||
if (spec_.align_ == ALIGN_RIGHT) {
|
if (spec_.align_ == ALIGN_RIGHT) {
|
||||||
std::fill_n(out, spec_.width_ - 1, fill);
|
std::fill_n(out, spec_.width_ - 1, fill);
|
||||||
out += spec_.width_ - 1;
|
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);
|
out = writer_.fill_padding(out, spec_.width_, 1, fill);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::fill_n(out + 1, spec_.width_ - 1, fill);
|
std::fill_n(out + 1, spec_.width_ - 1, fill);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
out = writer_.grow_buffer(1);
|
out = writer_.grow_buffer(1);
|
||||||
}
|
}
|
||||||
*out = internal::CharTraits<Char>::cast(value);
|
*out = internal::CharTraits<Char>::cast(value);
|
||||||
@ -499,11 +481,11 @@ public:
|
|||||||
// An argument formatter.
|
// An argument formatter.
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class ArgFormatter : public BasicArgFormatter<ArgFormatter<Char>, Char> {
|
class ArgFormatter : public BasicArgFormatter<ArgFormatter<Char>, Char> {
|
||||||
private:
|
private:
|
||||||
BasicFormatter<Char> &formatter_;
|
BasicFormatter<Char> &formatter_;
|
||||||
const Char *format_;
|
const Char *format_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ArgFormatter(BasicFormatter<Char> &f, FormatSpec &s, const Char *fmt)
|
ArgFormatter(BasicFormatter<Char> &f, FormatSpec &s, const Char *fmt)
|
||||||
: BasicArgFormatter<ArgFormatter<Char>, Char>(f.writer(), s),
|
: BasicArgFormatter<ArgFormatter<Char>, Char>(f.writer(), s),
|
||||||
formatter_(f), format_(fmt) {}
|
formatter_(f), format_(fmt) {}
|
||||||
@ -516,7 +498,7 @@ public:
|
|||||||
template <typename Char>
|
template <typename Char>
|
||||||
class PrintfArgFormatter :
|
class PrintfArgFormatter :
|
||||||
public BasicArgFormatter<PrintfArgFormatter<Char>, Char> {
|
public BasicArgFormatter<PrintfArgFormatter<Char>, Char> {
|
||||||
public:
|
public:
|
||||||
PrintfArgFormatter(BasicWriter<Char> &w, FormatSpec &s)
|
PrintfArgFormatter(BasicWriter<Char> &w, FormatSpec &s)
|
||||||
: BasicArgFormatter<PrintfArgFormatter<Char>, Char>(w, s) {}
|
: BasicArgFormatter<PrintfArgFormatter<Char>, Char>(w, s) {}
|
||||||
|
|
||||||
@ -533,12 +515,10 @@ public:
|
|||||||
if (fmt_spec.align_ != ALIGN_LEFT) {
|
if (fmt_spec.align_ != ALIGN_LEFT) {
|
||||||
std::fill_n(out, fmt_spec.width_ - 1, fill);
|
std::fill_n(out, fmt_spec.width_ - 1, fill);
|
||||||
out += fmt_spec.width_ - 1;
|
out += fmt_spec.width_ - 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::fill_n(out + 1, fmt_spec.width_ - 1, fill);
|
std::fill_n(out + 1, fmt_spec.width_ - 1, fill);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
out = w.grow_buffer(1);
|
out = w.grow_buffer(1);
|
||||||
}
|
}
|
||||||
*out = static_cast<Char>(value);
|
*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
|
#if FMT_USE_WINDOWS_H
|
||||||
|
|
||||||
FMT_FUNC fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) {
|
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";
|
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)
|
if (length == 0)
|
||||||
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
||||||
buffer_.resize(length + 1);
|
buffer_.resize(length + 1);
|
||||||
length = MultiByteToWideChar(
|
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)
|
if (length == 0)
|
||||||
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
||||||
buffer_[length] = 0;
|
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) {
|
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)
|
if (length == 0)
|
||||||
return GetLastError();
|
return GetLastError();
|
||||||
buffer_.resize(length + 1);
|
buffer_.resize(length + 1);
|
||||||
length = WideCharToMultiByte(
|
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)
|
if (length == 0)
|
||||||
return GetLastError();
|
return GetLastError();
|
||||||
buffer_[length] = 0;
|
buffer_[length] = 0;
|
||||||
@ -676,22 +662,18 @@ FMT_FUNC void fmt::WindowsError::init(
|
|||||||
|
|
||||||
FMT_FUNC void fmt::internal::format_windows_error(
|
FMT_FUNC void fmt::internal::format_windows_error(
|
||||||
fmt::Writer &out, int error_code,
|
fmt::Writer &out, int error_code,
|
||||||
fmt::StringRef message) FMT_NOEXCEPT{
|
fmt::StringRef message) FMT_NOEXCEPT {
|
||||||
class String {
|
class String {
|
||||||
private:
|
private:
|
||||||
LPWSTR str_;
|
LPWSTR str_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String() : str_() {}
|
String() : str_() {}
|
||||||
~String() {
|
~String() { LocalFree(str_); }
|
||||||
LocalFree(str_);
|
LPWSTR *ptr() { return &str_; }
|
||||||
}
|
|
||||||
LPWSTR *ptr() {
|
|
||||||
return &str_;
|
|
||||||
}
|
|
||||||
LPCWSTR c_str() const { return str_; }
|
LPCWSTR c_str() const { return str_; }
|
||||||
};
|
};
|
||||||
FMT_TRY{
|
FMT_TRY {
|
||||||
String system_message;
|
String system_message;
|
||||||
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0,
|
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0,
|
||||||
@ -711,8 +693,8 @@ FMT_FUNC void fmt::internal::format_windows_error(
|
|||||||
|
|
||||||
FMT_FUNC void fmt::internal::format_system_error(
|
FMT_FUNC void fmt::internal::format_system_error(
|
||||||
fmt::Writer &out, int error_code,
|
fmt::Writer &out, int error_code,
|
||||||
fmt::StringRef message) FMT_NOEXCEPT{
|
fmt::StringRef message) FMT_NOEXCEPT {
|
||||||
FMT_TRY{
|
FMT_TRY {
|
||||||
MemoryBuffer<char, INLINE_BUFFER_SIZE> buffer;
|
MemoryBuffer<char, INLINE_BUFFER_SIZE> buffer;
|
||||||
buffer.resize(INLINE_BUFFER_SIZE);
|
buffer.resize(INLINE_BUFFER_SIZE);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -749,8 +731,7 @@ void fmt::internal::ArgMap<Char>::init(const ArgList &args) {
|
|||||||
map_.insert(Pair(named_arg->name, *named_arg));
|
map_.insert(Pair(named_arg->name, *named_arg));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/*nothing*/
|
/*nothing*/;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -771,8 +752,7 @@ void fmt::internal::ArgMap<Char>::init(const ArgList &args) {
|
|||||||
map_.insert(Pair(named_arg->name, *named_arg));
|
map_.insert(Pair(named_arg->name, *named_arg));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/*nothing*/
|
/*nothing*/;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -854,8 +834,7 @@ FMT_FUNC Arg fmt::internal::FormatterBase::do_get_arg(
|
|||||||
case Arg::NAMED_ARG:
|
case Arg::NAMED_ARG:
|
||||||
arg = *static_cast<const internal::Arg*>(arg.pointer);
|
arg = *static_cast<const internal::Arg*>(arg.pointer);
|
||||||
default:
|
default:
|
||||||
/*nothing*/
|
/*nothing*/;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
@ -933,8 +912,7 @@ unsigned fmt::internal::PrintfFormatter<Char>::parse_header(
|
|||||||
if (*s == '$') { // value is an argument index
|
if (*s == '$') { // value is an argument index
|
||||||
++s;
|
++s;
|
||||||
arg_index = value;
|
arg_index = value;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (c == '0')
|
if (c == '0')
|
||||||
spec.fill_ = '0';
|
spec.fill_ = '0';
|
||||||
if (value != 0) {
|
if (value != 0) {
|
||||||
@ -949,8 +927,7 @@ unsigned fmt::internal::PrintfFormatter<Char>::parse_header(
|
|||||||
// Parse width.
|
// Parse width.
|
||||||
if (*s >= '0' && *s <= '9') {
|
if (*s >= '0' && *s <= '9') {
|
||||||
spec.width_ = parse_nonnegative_int(s);
|
spec.width_ = parse_nonnegative_int(s);
|
||||||
}
|
} else if (*s == '*') {
|
||||||
else if (*s == '*') {
|
|
||||||
++s;
|
++s;
|
||||||
spec.width_ = WidthHandler(spec).visit(get_arg(s));
|
spec.width_ = WidthHandler(spec).visit(get_arg(s));
|
||||||
}
|
}
|
||||||
@ -983,8 +960,7 @@ void fmt::internal::PrintfFormatter<Char>::format(
|
|||||||
++s;
|
++s;
|
||||||
if ('0' <= *s && *s <= '9') {
|
if ('0' <= *s && *s <= '9') {
|
||||||
spec.precision_ = parse_nonnegative_int(s);
|
spec.precision_ = parse_nonnegative_int(s);
|
||||||
}
|
} else if (*s == '*') {
|
||||||
else if (*s == '*') {
|
|
||||||
++s;
|
++s;
|
||||||
spec.precision_ = PrecisionHandler().visit(get_arg(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) {
|
if (arg.type <= Arg::LAST_INTEGER_TYPE) {
|
||||||
// Normalize type.
|
// Normalize type.
|
||||||
switch (spec.type_) {
|
switch (spec.type_) {
|
||||||
case 'i':
|
case 'i': case 'u':
|
||||||
case 'u':
|
|
||||||
spec.type_ = 'd';
|
spec.type_ = 'd';
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
@ -1095,8 +1070,7 @@ const Char *fmt::BasicFormatter<Char>::format(
|
|||||||
FMT_THROW(FormatError("invalid fill character '{'"));
|
FMT_THROW(FormatError("invalid fill character '{'"));
|
||||||
s += 2;
|
s += 2;
|
||||||
spec.fill_ = c;
|
spec.fill_ = c;
|
||||||
}
|
} else ++s;
|
||||||
else ++s;
|
|
||||||
if (spec.align_ == ALIGN_NUMERIC)
|
if (spec.align_ == ALIGN_NUMERIC)
|
||||||
require_numeric_argument(arg, '=');
|
require_numeric_argument(arg, '=');
|
||||||
break;
|
break;
|
||||||
@ -1137,8 +1111,7 @@ const Char *fmt::BasicFormatter<Char>::format(
|
|||||||
// Parse width.
|
// Parse width.
|
||||||
if ('0' <= *s && *s <= '9') {
|
if ('0' <= *s && *s <= '9') {
|
||||||
spec.width_ = parse_nonnegative_int(s);
|
spec.width_ = parse_nonnegative_int(s);
|
||||||
}
|
} else if (*s == '{') {
|
||||||
else if (*s == '{') {
|
|
||||||
++s;
|
++s;
|
||||||
Arg width_arg = is_name_start(*s) ?
|
Arg width_arg = is_name_start(*s) ?
|
||||||
parse_arg_name(s) : parse_arg_index(s);
|
parse_arg_name(s) : parse_arg_index(s);
|
||||||
@ -1176,8 +1149,7 @@ const Char *fmt::BasicFormatter<Char>::format(
|
|||||||
spec.precision_ = 0;
|
spec.precision_ = 0;
|
||||||
if ('0' <= *s && *s <= '9') {
|
if ('0' <= *s && *s <= '9') {
|
||||||
spec.precision_ = parse_nonnegative_int(s);
|
spec.precision_ = parse_nonnegative_int(s);
|
||||||
}
|
} else if (*s == '{') {
|
||||||
else if (*s == '{') {
|
|
||||||
++s;
|
++s;
|
||||||
Arg precision_arg =
|
Arg precision_arg =
|
||||||
is_name_start(*s) ? parse_arg_name(s) : parse_arg_index(s);
|
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)
|
if (value > INT_MAX)
|
||||||
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) {
|
||||||
@ -1253,13 +1224,13 @@ void fmt::BasicFormatter<Char>::format(BasicCStringRef<Char> format_str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FMT_FUNC void fmt::report_system_error(
|
FMT_FUNC void fmt::report_system_error(
|
||||||
int error_code, fmt::StringRef message) FMT_NOEXCEPT{
|
int error_code, fmt::StringRef message) FMT_NOEXCEPT {
|
||||||
report_error(internal::format_system_error, error_code, message);
|
report_error(internal::format_system_error, error_code, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FMT_USE_WINDOWS_H
|
#if FMT_USE_WINDOWS_H
|
||||||
FMT_FUNC void fmt::report_windows_error(
|
FMT_FUNC void fmt::report_windows_error(
|
||||||
int error_code, fmt::StringRef message) FMT_NOEXCEPT{
|
int error_code, fmt::StringRef message) FMT_NOEXCEPT {
|
||||||
report_error(internal::format_windows_error, error_code, message);
|
report_error(internal::format_windows_error, error_code, message);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user