|
|
@ -1,10 +1,7 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
|
|
|
|
Formatting library for C++
|
|
|
|
|
|
|
|
|
|
|
|
Modified version of cppformat formatting library
|
|
|
|
Copyright (c) 2012 - 2015, Victor Zverovich
|
|
|
|
|
|
|
|
|
|
|
|
Orginal license:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2012 - 2014, 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
|
|
|
@ -28,7 +25,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
@ -39,18 +36,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#include <cstdarg>
|
|
|
|
#include <cstdarg>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef _WIN32
|
|
|
|
# ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifdef __MINGW32__
|
|
|
|
# ifdef __MINGW32__
|
|
|
|
# include <cstring>
|
|
|
|
# include <cstring>
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
# include <windows.h>
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
using spdlog::details::fmt::LongLong;
|
|
|
|
using fmt::internal::Arg;
|
|
|
|
using spdlog::details::fmt::ULongLong;
|
|
|
|
|
|
|
|
using spdlog::details::fmt::internal::Arg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if exceptions are disabled.
|
|
|
|
// Check if exceptions are disabled.
|
|
|
|
#if __GNUC__ && !__EXCEPTIONS
|
|
|
|
#if __GNUC__ && !__EXCEPTIONS
|
|
|
@ -88,8 +80,21 @@ using spdlog::details::fmt::internal::Arg;
|
|
|
|
#if _MSC_VER
|
|
|
|
#if _MSC_VER
|
|
|
|
# pragma warning(push)
|
|
|
|
# pragma warning(push)
|
|
|
|
# pragma warning(disable: 4127) // conditional expression is constant
|
|
|
|
# pragma warning(disable: 4127) // conditional expression is constant
|
|
|
|
|
|
|
|
# pragma warning(disable: 4702) // unreachable code
|
|
|
|
|
|
|
|
// Disable deprecation warning for strerror. The latter is not called but
|
|
|
|
|
|
|
|
// MSVC fails to detect it.
|
|
|
|
|
|
|
|
# pragma warning(disable: 4996)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dummy implementations of strerror_r and strerror_s called if corresponding
|
|
|
|
|
|
|
|
// system functions are not available.
|
|
|
|
|
|
|
|
static inline fmt::internal::None<> strerror_r(int, char *, ...) {
|
|
|
|
|
|
|
|
return fmt::internal::None<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline fmt::internal::None<> strerror_s(char *, std::size_t, ...) {
|
|
|
|
|
|
|
|
return fmt::internal::None<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
#ifndef _MSC_VER
|
|
|
@ -105,6 +110,12 @@ inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) {
|
|
|
|
# define FMT_SNPRINTF fmt_snprintf
|
|
|
|
# define FMT_SNPRINTF fmt_snprintf
|
|
|
|
#endif // _MSC_VER
|
|
|
|
#endif // _MSC_VER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)
|
|
|
|
|
|
|
|
# define FMT_SWPRINTF snwprintf
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
# define FMT_SWPRINTF swprintf
|
|
|
|
|
|
|
|
#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)
|
|
|
|
|
|
|
|
|
|
|
|
// Checks if a value fits in int - used to avoid warnings about comparing
|
|
|
|
// Checks if a value fits in int - used to avoid warnings about comparing
|
|
|
|
// signed and unsigned integers.
|
|
|
|
// signed and unsigned integers.
|
|
|
|
template <bool IsSigned>
|
|
|
|
template <bool IsSigned>
|
|
|
@ -126,7 +137,7 @@ struct IntChecker<true> {
|
|
|
|
|
|
|
|
|
|
|
|
const char RESET_COLOR[] = "\x1b[0m";
|
|
|
|
const char RESET_COLOR[] = "\x1b[0m";
|
|
|
|
|
|
|
|
|
|
|
|
typedef void(*FormatFunc)(spdlog::details::fmt::Writer &, int, spdlog::details::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.
|
|
|
@ -137,55 +148,83 @@ typedef void(*FormatFunc)(spdlog::details::fmt::Writer &, int, spdlog::details::
|
|
|
|
// ERANGE - buffer is not large enough to store the error message
|
|
|
|
// ERANGE - buffer is not large enough to store the error message
|
|
|
|
// other - failure
|
|
|
|
// other - failure
|
|
|
|
// Buffer should be at least of size 1.
|
|
|
|
// Buffer should be at least of size 1.
|
|
|
|
FMT_FUNC int safe_strerror(
|
|
|
|
int safe_strerror(
|
|
|
|
int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT(true) {
|
|
|
|
int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT {
|
|
|
|
assert(buffer != 0 && buffer_size != 0);
|
|
|
|
assert(buffer != 0 && buffer_size != 0);
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
#ifdef _GNU_SOURCE
|
|
|
|
class StrError {
|
|
|
|
char *message = strerror_r(error_code, buffer, buffer_size);
|
|
|
|
private:
|
|
|
|
|
|
|
|
int error_code_;
|
|
|
|
|
|
|
|
char *&buffer_;
|
|
|
|
|
|
|
|
std::size_t buffer_size_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A noop assignment operator to avoid bogus warnings.
|
|
|
|
|
|
|
|
void operator=(const StrError &) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the result of XSI-compliant version of strerror_r.
|
|
|
|
|
|
|
|
int handle(int result) {
|
|
|
|
|
|
|
|
// glibc versions before 2.13 return result in errno.
|
|
|
|
|
|
|
|
return result == -1 ? errno : result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the result of GNU-specific version of strerror_r.
|
|
|
|
|
|
|
|
int handle(char *message) {
|
|
|
|
// If the buffer is full then the message is probably truncated.
|
|
|
|
// If the buffer is full then the message is probably truncated.
|
|
|
|
if (message == buffer && strlen(buffer) == buffer_size - 1)
|
|
|
|
if (message == buffer_ && strlen(buffer_) == buffer_size_ - 1)
|
|
|
|
result = ERANGE;
|
|
|
|
return ERANGE;
|
|
|
|
buffer = message;
|
|
|
|
buffer_ = message;
|
|
|
|
#elif __MINGW32__
|
|
|
|
return 0;
|
|
|
|
errno = 0;
|
|
|
|
}
|
|
|
|
(void)buffer_size;
|
|
|
|
|
|
|
|
buffer = strerror(error_code);
|
|
|
|
// Handle the case when strerror_r is not available.
|
|
|
|
result = errno;
|
|
|
|
int handle(fmt::internal::None<>) {
|
|
|
|
#elif _WIN32
|
|
|
|
return fallback(strerror_s(buffer_, buffer_size_, error_code_));
|
|
|
|
result = strerror_s(buffer, buffer_size, error_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fallback to strerror_s when strerror_r is not available.
|
|
|
|
|
|
|
|
int fallback(int result) {
|
|
|
|
// If the buffer is full then the message is probably truncated.
|
|
|
|
// If the buffer is full then the message is probably truncated.
|
|
|
|
if (result == 0 && std::strlen(buffer) == buffer_size - 1)
|
|
|
|
return result == 0 && strlen(buffer_) == buffer_size_ - 1 ?
|
|
|
|
result = ERANGE;
|
|
|
|
ERANGE : result;
|
|
|
|
#else
|
|
|
|
}
|
|
|
|
result = strerror_r(error_code, buffer, buffer_size);
|
|
|
|
|
|
|
|
if (result == -1)
|
|
|
|
// Fallback to strerror if strerror_r and strerror_s are not available.
|
|
|
|
result = errno; // glibc versions before 2.13 return result in errno.
|
|
|
|
int fallback(fmt::internal::None<>) {
|
|
|
|
#endif
|
|
|
|
errno = 0;
|
|
|
|
return result;
|
|
|
|
buffer_ = strerror(error_code_);
|
|
|
|
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
StrError(int error_code, char *&buffer, std::size_t buffer_size)
|
|
|
|
|
|
|
|
: error_code_(error_code), buffer_(buffer), buffer_size_(buffer_size) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int run() { return handle(strerror_r(error_code_, buffer_, buffer_size_)); }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return StrError(error_code, buffer, buffer_size).run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void format_error_code(spdlog::details::fmt::Writer &out, int error_code,
|
|
|
|
void format_error_code(fmt::Writer &out, int error_code,
|
|
|
|
spdlog::details::fmt::StringRef message) FMT_NOEXCEPT(true) {
|
|
|
|
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.
|
|
|
|
out.clear();
|
|
|
|
out.clear();
|
|
|
|
static const char SEP[] = ": ";
|
|
|
|
static const char SEP[] = ": ";
|
|
|
|
static const char FMT_ERROR[] = "error ";
|
|
|
|
static const char ERROR_STR[] = "error ";
|
|
|
|
spdlog::details::fmt::internal::IntTraits<int>::MainType ec_value = error_code;
|
|
|
|
fmt::internal::IntTraits<int>::MainType ec_value = error_code;
|
|
|
|
// Subtract 2 to account for terminating null characters in SEP and FMT_ERROR.
|
|
|
|
// Subtract 2 to account for terminating null characters in SEP and ERROR_STR.
|
|
|
|
std::size_t error_code_size =
|
|
|
|
std::size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2;
|
|
|
|
sizeof(SEP) + sizeof(FMT_ERROR) + spdlog::details::fmt::internal::count_digits(ec_value) - 2;
|
|
|
|
error_code_size += fmt::internal::count_digits(ec_value);
|
|
|
|
if (message.size() <= spdlog::details::fmt::internal::INLINE_BUFFER_SIZE - error_code_size)
|
|
|
|
if (message.size() <= fmt::internal::INLINE_BUFFER_SIZE - error_code_size)
|
|
|
|
out << message << SEP;
|
|
|
|
out << message << SEP;
|
|
|
|
out << FMT_ERROR << error_code;
|
|
|
|
out << ERROR_STR << error_code;
|
|
|
|
assert(out.size() <= spdlog::details::fmt::internal::INLINE_BUFFER_SIZE);
|
|
|
|
assert(out.size() <= fmt::internal::INLINE_BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void report_error(FormatFunc func,
|
|
|
|
void report_error(FormatFunc func,
|
|
|
|
int error_code, spdlog::details::fmt::StringRef message) FMT_NOEXCEPT(true) {
|
|
|
|
int error_code, fmt::StringRef message) FMT_NOEXCEPT {
|
|
|
|
spdlog::details::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
|
|
|
|
// allocation.
|
|
|
|
// allocation.
|
|
|
@ -194,18 +233,16 @@ FMT_FUNC 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 spdlog::details::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.
|
|
|
|
// This function assumes that the first character of s is a digit.
|
|
|
|
// This function assumes that the first character of s is a digit.
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
FMT_FUNC int parse_nonnegative_int(const Char *&s) {
|
|
|
|
int parse_nonnegative_int(const Char *&s) {
|
|
|
|
assert('0' <= *s && *s <= '9');
|
|
|
|
assert('0' <= *s && *s <= '9');
|
|
|
|
unsigned value = 0;
|
|
|
|
unsigned value = 0;
|
|
|
|
do {
|
|
|
|
do {
|
|
|
@ -218,24 +255,24 @@ FMT_FUNC int parse_nonnegative_int(const Char *&s) {
|
|
|
|
value = new_value;
|
|
|
|
value = new_value;
|
|
|
|
} while ('0' <= *s && *s <= '9');
|
|
|
|
} while ('0' <= *s && *s <= '9');
|
|
|
|
if (value > INT_MAX)
|
|
|
|
if (value > INT_MAX)
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError("number is too big"));
|
|
|
|
FMT_THROW(fmt::FormatError("number is too big"));
|
|
|
|
return value;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void require_numeric_argument(const Arg &arg, char spec) {
|
|
|
|
inline void require_numeric_argument(const Arg &arg, char spec) {
|
|
|
|
if (arg.type > Arg::LAST_NUMERIC_TYPE) {
|
|
|
|
if (arg.type > Arg::LAST_NUMERIC_TYPE) {
|
|
|
|
std::string message =
|
|
|
|
std::string message =
|
|
|
|
spdlog::details::fmt::format("format specifier '{}' requires numeric argument", spec);
|
|
|
|
fmt::format("format specifier '{}' requires numeric argument", spec);
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError(message));
|
|
|
|
FMT_THROW(fmt::FormatError(message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
FMT_FUNC void check_sign(const Char *&s, const Arg &arg) {
|
|
|
|
void check_sign(const Char *&s, const Arg &arg) {
|
|
|
|
char sign = static_cast<char>(*s);
|
|
|
|
char sign = static_cast<char>(*s);
|
|
|
|
require_numeric_argument(arg, sign);
|
|
|
|
require_numeric_argument(arg, sign);
|
|
|
|
if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) {
|
|
|
|
if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) {
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError(spdlog::details::fmt::format(
|
|
|
|
FMT_THROW(fmt::FormatError(fmt::format(
|
|
|
|
"format specifier '{}' requires signed argument", sign)));
|
|
|
|
"format specifier '{}' requires signed argument", sign)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++s;
|
|
|
|
++s;
|
|
|
@ -243,97 +280,98 @@ FMT_FUNC 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 spdlog::details::fmt::internal::ArgVisitor<WidthHandler, unsigned> {
|
|
|
|
class WidthHandler : public fmt::internal::ArgVisitor<WidthHandler, unsigned> {
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
spdlog::details::fmt::FormatSpec &spec_;
|
|
|
|
fmt::FormatSpec &spec_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FMT_DISALLOW_COPY_AND_ASSIGN(WidthHandler);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit WidthHandler(spdlog::details::fmt::FormatSpec &spec) : spec_(spec) {}
|
|
|
|
explicit WidthHandler(fmt::FormatSpec &spec) : spec_(spec) {}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned visit_unhandled_arg() {
|
|
|
|
void report_unhandled_arg() {
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError("width is not integer"));
|
|
|
|
FMT_THROW(fmt::FormatError("width is not integer"));
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
unsigned visit_any_int(T value) {
|
|
|
|
unsigned visit_any_int(T value) {
|
|
|
|
typedef typename spdlog::details::fmt::internal::IntTraits<T>::MainType UnsignedType;
|
|
|
|
typedef typename fmt::internal::IntTraits<T>::MainType UnsignedType;
|
|
|
|
UnsignedType width = value;
|
|
|
|
UnsignedType width = value;
|
|
|
|
if (spdlog::details::fmt::internal::is_negative(value)) {
|
|
|
|
if (fmt::internal::is_negative(value)) {
|
|
|
|
spec_.align_ = spdlog::details::fmt::ALIGN_LEFT;
|
|
|
|
spec_.align_ = fmt::ALIGN_LEFT;
|
|
|
|
width = 0 - width;
|
|
|
|
width = 0 - width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (width > INT_MAX)
|
|
|
|
if (width > INT_MAX)
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError("number is too big"));
|
|
|
|
FMT_THROW(fmt::FormatError("number is too big"));
|
|
|
|
return static_cast<unsigned>(width);
|
|
|
|
return static_cast<unsigned>(width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class PrecisionHandler :
|
|
|
|
class PrecisionHandler :
|
|
|
|
public spdlog::details::fmt::internal::ArgVisitor<PrecisionHandler, int> {
|
|
|
|
public fmt::internal::ArgVisitor<PrecisionHandler, int> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
unsigned visit_unhandled_arg() {
|
|
|
|
void report_unhandled_arg() {
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError("precision is not integer"));
|
|
|
|
FMT_THROW(fmt::FormatError("precision is not integer"));
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
int visit_any_int(T value) {
|
|
|
|
int visit_any_int(T value) {
|
|
|
|
if (!IntChecker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
|
|
|
|
if (!IntChecker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError("number is too big"));
|
|
|
|
FMT_THROW(fmt::FormatError("number is too big"));
|
|
|
|
return static_cast<int>(value);
|
|
|
|
return static_cast<int>(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 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 spdlog::details::fmt::internal::ArgVisitor<ArgConverter<T>, void> {
|
|
|
|
class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
spdlog::details::fmt::internal::Arg &arg_;
|
|
|
|
fmt::internal::Arg &arg_;
|
|
|
|
wchar_t type_;
|
|
|
|
wchar_t type_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FMT_DISALLOW_COPY_AND_ASSIGN(ArgConverter);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ArgConverter(spdlog::details::fmt::internal::Arg &arg, wchar_t type)
|
|
|
|
ArgConverter(fmt::internal::Arg &arg, wchar_t type)
|
|
|
|
: arg_(arg), type_(type) {}
|
|
|
|
: arg_(arg), type_(type) {}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
template <typename U>
|
|
|
|
void visit_any_int(U value) {
|
|
|
|
void visit_any_int(U value) {
|
|
|
|
bool is_signed = type_ == 'd' || type_ == 'i';
|
|
|
|
bool is_signed = type_ == 'd' || type_ == 'i';
|
|
|
|
using spdlog::details::fmt::internal::Arg;
|
|
|
|
using fmt::internal::Arg;
|
|
|
|
if (sizeof(T) <= sizeof(int)) {
|
|
|
|
if (sizeof(T) <= sizeof(int)) {
|
|
|
|
// Extra casts are used to silence warnings.
|
|
|
|
// Extra casts are used to silence warnings.
|
|
|
|
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 spdlog::details::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 spdlog::details::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 spdlog::details::fmt::internal::MakeUnsigned<U>::Type>(value);
|
|
|
|
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Converts an integer argument to char for printf.
|
|
|
|
// Converts an integer argument to char for printf.
|
|
|
|
class CharConverter : public spdlog::details::fmt::internal::ArgVisitor<CharConverter, void> {
|
|
|
|
class CharConverter : public fmt::internal::ArgVisitor<CharConverter, void> {
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
spdlog::details::fmt::internal::Arg &arg_;
|
|
|
|
fmt::internal::Arg &arg_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FMT_DISALLOW_COPY_AND_ASSIGN(CharConverter);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit CharConverter(spdlog::details::fmt::internal::Arg &arg) : arg_(arg) {}
|
|
|
|
explicit CharConverter(fmt::internal::Arg &arg) : arg_(arg) {}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
void visit_any_int(T value) {
|
|
|
|
void visit_any_int(T value) {
|
|
|
@ -350,28 +388,24 @@ Arg::StringValue<Char> ignore_incompatible_str(Arg::StringValue<wchar_t>);
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
template <>
|
|
|
|
inline Arg::StringValue<char> ignore_incompatible_str(
|
|
|
|
inline Arg::StringValue<char> ignore_incompatible_str(
|
|
|
|
Arg::StringValue<wchar_t>) {
|
|
|
|
Arg::StringValue<wchar_t>) { return Arg::StringValue<char>(); }
|
|
|
|
return Arg::StringValue<char>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
template <>
|
|
|
|
inline Arg::StringValue<wchar_t> ignore_incompatible_str(
|
|
|
|
inline Arg::StringValue<wchar_t> ignore_incompatible_str(
|
|
|
|
Arg::StringValue<wchar_t> s) {
|
|
|
|
Arg::StringValue<wchar_t> s) { return s; }
|
|
|
|
return s;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::SystemError::init(
|
|
|
|
FMT_FUNC void fmt::SystemError::init(
|
|
|
|
int error_code, StringRef format_str, ArgList args) {
|
|
|
|
int err_code, StringRef format_str, ArgList args) {
|
|
|
|
error_code_ = error_code;
|
|
|
|
error_code_ = err_code;
|
|
|
|
MemoryWriter w;
|
|
|
|
MemoryWriter w;
|
|
|
|
internal::format_system_error(w, error_code, format(format_str, args));
|
|
|
|
internal::format_system_error(w, err_code, format(format_str, args));
|
|
|
|
std::runtime_error &base = *this;
|
|
|
|
std::runtime_error &base = *this;
|
|
|
|
base = std::runtime_error(w.str());
|
|
|
|
base = std::runtime_error(w.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
FMT_FUNC int spdlog::details::fmt::internal::CharTraits<char>::format_float(
|
|
|
|
int fmt::internal::CharTraits<char>::format_float(
|
|
|
|
char *buffer, std::size_t size, const char *format,
|
|
|
|
char *buffer, std::size_t size, const char *format,
|
|
|
|
unsigned width, int precision, T value) {
|
|
|
|
unsigned width, int precision, T value) {
|
|
|
|
if (width == 0) {
|
|
|
|
if (width == 0) {
|
|
|
@ -385,21 +419,21 @@ FMT_FUNC int spdlog::details::fmt::internal::CharTraits<char>::format_float(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
FMT_FUNC int spdlog::details::fmt::internal::CharTraits<wchar_t>::format_float(
|
|
|
|
int fmt::internal::CharTraits<wchar_t>::format_float(
|
|
|
|
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
|
|
|
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
|
|
|
unsigned width, int precision, T value) {
|
|
|
|
unsigned width, int precision, T value) {
|
|
|
|
if (width == 0) {
|
|
|
|
if (width == 0) {
|
|
|
|
return precision < 0 ?
|
|
|
|
return precision < 0 ?
|
|
|
|
swprintf(buffer, size, format, value) :
|
|
|
|
FMT_SWPRINTF(buffer, size, format, value) :
|
|
|
|
swprintf(buffer, size, format, precision, value);
|
|
|
|
FMT_SWPRINTF(buffer, size, format, precision, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return precision < 0 ?
|
|
|
|
return precision < 0 ?
|
|
|
|
swprintf(buffer, size, format, width, value) :
|
|
|
|
FMT_SWPRINTF(buffer, size, format, width, value) :
|
|
|
|
swprintf(buffer, size, format, width, precision, value);
|
|
|
|
FMT_SWPRINTF(buffer, size, format, width, precision, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
const char spdlog::details::fmt::internal::BasicData<T>::DIGITS[] =
|
|
|
|
const char fmt::internal::BasicData<T>::DIGITS[] =
|
|
|
|
"0001020304050607080910111213141516171819"
|
|
|
|
"0001020304050607080910111213141516171819"
|
|
|
|
"2021222324252627282930313233343536373839"
|
|
|
|
"2021222324252627282930313233343536373839"
|
|
|
|
"4041424344454647484950515253545556575859"
|
|
|
|
"4041424344454647484950515253545556575859"
|
|
|
@ -418,53 +452,54 @@ const char spdlog::details::fmt::internal::BasicData<T>::DIGITS[] =
|
|
|
|
factor * 1000000000
|
|
|
|
factor * 1000000000
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
const uint32_t spdlog::details::fmt::internal::BasicData<T>::POWERS_OF_10_32[] = {
|
|
|
|
const uint32_t fmt::internal::BasicData<T>::POWERS_OF_10_32[] = {
|
|
|
|
0, FMT_POWERS_OF_10(1)
|
|
|
|
0, FMT_POWERS_OF_10(1)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
const uint64_t spdlog::details::fmt::internal::BasicData<T>::POWERS_OF_10_64[] = {
|
|
|
|
const uint64_t fmt::internal::BasicData<T>::POWERS_OF_10_64[] = {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
FMT_POWERS_OF_10(1),
|
|
|
|
FMT_POWERS_OF_10(1),
|
|
|
|
FMT_POWERS_OF_10(ULongLong(1000000000)),
|
|
|
|
FMT_POWERS_OF_10(fmt::ULongLong(1000000000)),
|
|
|
|
// Multiply several constants instead of using a single long long constant
|
|
|
|
// Multiply several constants instead of using a single long long constant
|
|
|
|
// to avoid warnings about C++98 not supporting long long.
|
|
|
|
// to avoid warnings about C++98 not supporting long long.
|
|
|
|
ULongLong(1000000000) * ULongLong(1000000000) * 10
|
|
|
|
fmt::ULongLong(1000000000) * fmt::ULongLong(1000000000) * 10
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::internal::report_unknown_type(char code, const char *type) {
|
|
|
|
FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) {
|
|
|
|
|
|
|
|
(void)type;
|
|
|
|
if (std::isprint(static_cast<unsigned char>(code))) {
|
|
|
|
if (std::isprint(static_cast<unsigned char>(code))) {
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError(
|
|
|
|
FMT_THROW(fmt::FormatError(
|
|
|
|
spdlog::details::fmt::format("unknown format code '{}' for {}", code, type)));
|
|
|
|
fmt::format("unknown format code '{}' for {}", code, type)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FMT_THROW(spdlog::details::fmt::FormatError(
|
|
|
|
FMT_THROW(fmt::FormatError(
|
|
|
|
spdlog::details::fmt::format("unknown format code '\\x{:02x}' for {}",
|
|
|
|
fmt::format("unknown format code '\\x{:02x}' for {}",
|
|
|
|
static_cast<unsigned>(code), type)));
|
|
|
|
static_cast<unsigned>(code), type)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC spdlog::details::fmt::internal::UTF8ToUTF16::UTF8ToUTF16(spdlog::details::fmt::StringRef s) {
|
|
|
|
FMT_FUNC fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) {
|
|
|
|
int length = MultiByteToWideChar(
|
|
|
|
int length = MultiByteToWideChar(
|
|
|
|
CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, 0, 0);
|
|
|
|
CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, 0, 0);
|
|
|
|
static const char FMT_ERROR[] = "cannot convert string from UTF-8 to UTF-16";
|
|
|
|
static const char ERROR_MSG[] = "cannot convert string from UTF-8 to UTF-16";
|
|
|
|
if (length == 0)
|
|
|
|
if (length == 0)
|
|
|
|
FMT_THROW(WindowsError(GetLastError(), FMT_ERROR));
|
|
|
|
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
|
|
|
buffer_.resize(length);
|
|
|
|
buffer_.resize(length);
|
|
|
|
length = MultiByteToWideChar(
|
|
|
|
length = MultiByteToWideChar(
|
|
|
|
CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, &buffer_[0], length);
|
|
|
|
CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, &buffer_[0], length);
|
|
|
|
if (length == 0)
|
|
|
|
if (length == 0)
|
|
|
|
FMT_THROW(WindowsError(GetLastError(), FMT_ERROR));
|
|
|
|
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC spdlog::details::fmt::internal::UTF16ToUTF8::UTF16ToUTF8(spdlog::details::fmt::WStringRef s) {
|
|
|
|
FMT_FUNC fmt::internal::UTF16ToUTF8::UTF16ToUTF8(fmt::WStringRef s) {
|
|
|
|
if (int error_code = convert(s)) {
|
|
|
|
if (int error_code = convert(s)) {
|
|
|
|
FMT_THROW(WindowsError(error_code,
|
|
|
|
FMT_THROW(WindowsError(error_code,
|
|
|
|
"cannot convert string from UTF-16 to UTF-8"));
|
|
|
|
"cannot convert string from UTF-16 to UTF-8"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC int spdlog::details::fmt::internal::UTF16ToUTF8::convert(spdlog::details::fmt::WStringRef s) {
|
|
|
|
FMT_FUNC int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) {
|
|
|
|
int length = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, 0, 0, 0, 0);
|
|
|
|
int length = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, 0, 0, 0, 0);
|
|
|
|
if (length == 0)
|
|
|
|
if (length == 0)
|
|
|
|
return GetLastError();
|
|
|
|
return GetLastError();
|
|
|
@ -476,20 +511,20 @@ FMT_FUNC int spdlog::details::fmt::internal::UTF16ToUTF8::convert(spdlog::detail
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::WindowsError::init(
|
|
|
|
FMT_FUNC void fmt::WindowsError::init(
|
|
|
|
int error_code, StringRef format_str, ArgList args) {
|
|
|
|
int err_code, StringRef format_str, ArgList args) {
|
|
|
|
error_code_ = error_code;
|
|
|
|
error_code_ = err_code;
|
|
|
|
MemoryWriter w;
|
|
|
|
MemoryWriter w;
|
|
|
|
internal::format_windows_error(w, error_code, format(format_str, args));
|
|
|
|
internal::format_windows_error(w, err_code, format(format_str, args));
|
|
|
|
std::runtime_error &base = *this;
|
|
|
|
std::runtime_error &base = *this;
|
|
|
|
base = std::runtime_error(w.str());
|
|
|
|
base = std::runtime_error(w.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::internal::format_system_error(
|
|
|
|
FMT_FUNC void fmt::internal::format_system_error(
|
|
|
|
spdlog::details::fmt::Writer &out, int error_code,
|
|
|
|
fmt::Writer &out, int error_code,
|
|
|
|
spdlog::details::fmt::StringRef message) FMT_NOEXCEPT(true) {
|
|
|
|
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);
|
|
|
@ -509,24 +544,18 @@ FMT_FUNC void spdlog::details::fmt::internal::format_system_error(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef _WIN32
|
|
|
|
FMT_FUNC void spdlog::details::fmt::internal::format_windows_error(
|
|
|
|
FMT_FUNC void fmt::internal::format_windows_error(
|
|
|
|
spdlog::details::fmt::Writer &out, int error_code,
|
|
|
|
fmt::Writer &out, int error_code,
|
|
|
|
spdlog::details::fmt::StringRef message) FMT_NOEXCEPT(true) {
|
|
|
|
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_; }
|
|
|
|
}
|
|
|
|
LPCWSTR c_str() const { return str_; }
|
|
|
|
LPWSTR *ptr() {
|
|
|
|
|
|
|
|
return &str_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LPCWSTR c_str() const {
|
|
|
|
|
|
|
|
return str_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
FMT_TRY {
|
|
|
|
FMT_TRY {
|
|
|
|
String system_message;
|
|
|
|
String system_message;
|
|
|
@ -547,28 +576,26 @@ FMT_FUNC void spdlog::details::fmt::internal::format_windows_error(
|
|
|
|
|
|
|
|
|
|
|
|
// An argument formatter.
|
|
|
|
// An argument formatter.
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
class spdlog::details::fmt::internal::ArgFormatter :
|
|
|
|
class fmt::internal::ArgFormatter :
|
|
|
|
public spdlog::details::fmt::internal::ArgVisitor<spdlog::details::fmt::internal::ArgFormatter<Char>, void> {
|
|
|
|
public fmt::internal::ArgVisitor<fmt::internal::ArgFormatter<Char>, void> {
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
spdlog::details::fmt::BasicFormatter<Char> &formatter_;
|
|
|
|
fmt::BasicFormatter<Char> &formatter_;
|
|
|
|
spdlog::details::fmt::BasicWriter<Char> &writer_;
|
|
|
|
fmt::BasicWriter<Char> &writer_;
|
|
|
|
spdlog::details::fmt::FormatSpec &spec_;
|
|
|
|
fmt::FormatSpec &spec_;
|
|
|
|
const Char *format_;
|
|
|
|
const Char *format_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FMT_DISALLOW_COPY_AND_ASSIGN(ArgFormatter);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ArgFormatter(
|
|
|
|
ArgFormatter(
|
|
|
|
spdlog::details::fmt::BasicFormatter<Char> &f, spdlog::details::fmt::FormatSpec &s, const Char *fmt)
|
|
|
|
fmt::BasicFormatter<Char> &f,fmt::FormatSpec &s, const Char *fmt)
|
|
|
|
: formatter_(f), writer_(f.writer()), spec_(s), format_(fmt) {}
|
|
|
|
: formatter_(f), writer_(f.writer()), spec_(s), format_(fmt) {}
|
|
|
|
|
|
|
|
|
|
|
|
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_char(int value) {
|
|
|
|
void visit_char(int value) {
|
|
|
|
if (spec_.type_ && spec_.type_ != 'c') {
|
|
|
|
if (spec_.type_ && spec_.type_ != 'c') {
|
|
|
@ -578,23 +605,24 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (spec_.align_ == ALIGN_NUMERIC || spec_.flags_ != 0)
|
|
|
|
if (spec_.align_ == ALIGN_NUMERIC || spec_.flags_ != 0)
|
|
|
|
FMT_THROW(FormatError("invalid format specifier for char"));
|
|
|
|
FMT_THROW(FormatError("invalid format specifier for char"));
|
|
|
|
typedef typename spdlog::details::fmt::BasicWriter<Char>::CharPtr CharPtr;
|
|
|
|
typedef typename fmt::BasicWriter<Char>::CharPtr CharPtr;
|
|
|
|
|
|
|
|
Char fill = static_cast<Char>(spec_.fill());
|
|
|
|
|
|
|
|
if (spec_.precision_ == 0) {
|
|
|
|
|
|
|
|
std::fill_n(writer_.grow_buffer(spec_.width_), spec_.width_, fill);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
CharPtr out = CharPtr();
|
|
|
|
CharPtr out = CharPtr();
|
|
|
|
if (spec_.width_ > 1) {
|
|
|
|
if (spec_.width_ > 1) {
|
|
|
|
Char fill = static_cast<Char>(spec_.fill());
|
|
|
|
|
|
|
|
out = writer_.grow_buffer(spec_.width_);
|
|
|
|
out = writer_.grow_buffer(spec_.width_);
|
|
|
|
if (spec_.align_ == spdlog::details::fmt::ALIGN_RIGHT) {
|
|
|
|
if (spec_.align_ == fmt::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_ == fmt::ALIGN_CENTER) {
|
|
|
|
else if (spec_.align_ == spdlog::details::fmt::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 = static_cast<Char>(value);
|
|
|
|
*out = static_cast<Char>(value);
|
|
|
@ -609,8 +637,8 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
void visit_pointer(const void *value) {
|
|
|
|
void visit_pointer(const void *value) {
|
|
|
|
if (spec_.type_ && spec_.type_ != 'p')
|
|
|
|
if (spec_.type_ && spec_.type_ != 'p')
|
|
|
|
spdlog::details::fmt::internal::report_unknown_type(spec_.type_, "pointer");
|
|
|
|
fmt::internal::report_unknown_type(spec_.type_, "pointer");
|
|
|
|
spec_.flags_ = spdlog::details::fmt::HASH_FLAG;
|
|
|
|
spec_.flags_ = fmt::HASH_FLAG;
|
|
|
|
spec_.type_ = 'x';
|
|
|
|
spec_.type_ = 'x';
|
|
|
|
writer_.write_int(reinterpret_cast<uintptr_t>(value), spec_);
|
|
|
|
writer_.write_int(reinterpret_cast<uintptr_t>(value), spec_);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -620,27 +648,35 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
|
|
|
|
void fmt::internal::FixedBuffer<Char>::grow(std::size_t) {
|
|
|
|
|
|
|
|
FMT_THROW(std::runtime_error("buffer overflow"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
template <typename StrChar>
|
|
|
|
template <typename StrChar>
|
|
|
|
FMT_FUNC void spdlog::details::fmt::BasicWriter<Char>::write_str(
|
|
|
|
void fmt::BasicWriter<Char>::write_str(
|
|
|
|
const Arg::StringValue<StrChar> &str, const FormatSpec &spec) {
|
|
|
|
const Arg::StringValue<StrChar> &s, const FormatSpec &spec) {
|
|
|
|
// Check if StrChar is convertible to Char.
|
|
|
|
// Check if StrChar is convertible to Char.
|
|
|
|
internal::CharTraits<Char>::convert(StrChar());
|
|
|
|
internal::CharTraits<Char>::convert(StrChar());
|
|
|
|
if (spec.type_ && spec.type_ != 's')
|
|
|
|
if (spec.type_ && spec.type_ != 's')
|
|
|
|
internal::report_unknown_type(spec.type_, "string");
|
|
|
|
internal::report_unknown_type(spec.type_, "string");
|
|
|
|
const StrChar *s = str.value;
|
|
|
|
const StrChar *str_value = s.value;
|
|
|
|
std::size_t size = str.size;
|
|
|
|
std::size_t str_size = s.size;
|
|
|
|
if (size == 0) {
|
|
|
|
if (str_size == 0) {
|
|
|
|
if (!s)
|
|
|
|
if (!str_value)
|
|
|
|
FMT_THROW(FormatError("string pointer is null"));
|
|
|
|
FMT_THROW(FormatError("string pointer is null"));
|
|
|
|
if (*s)
|
|
|
|
if (*str_value)
|
|
|
|
size = std::char_traits<StrChar>::length(s);
|
|
|
|
str_size = std::char_traits<StrChar>::length(str_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write_str(s, size, spec);
|
|
|
|
std::size_t precision = spec.precision_;
|
|
|
|
|
|
|
|
if (spec.precision_ >= 0 && precision < str_size)
|
|
|
|
|
|
|
|
str_size = spec.precision_;
|
|
|
|
|
|
|
|
write_str(str_value, str_size, spec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
inline Arg spdlog::details::fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) {
|
|
|
|
inline Arg fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) {
|
|
|
|
const char *error = 0;
|
|
|
|
const char *error = 0;
|
|
|
|
Arg arg = *s < '0' || *s > '9' ?
|
|
|
|
Arg arg = *s < '0' || *s > '9' ?
|
|
|
|
next_arg(error) : get_arg(parse_nonnegative_int(s), error);
|
|
|
|
next_arg(error) : get_arg(parse_nonnegative_int(s), error);
|
|
|
@ -651,7 +687,7 @@ inline Arg spdlog::details::fmt::BasicFormatter<Char>::parse_arg_index(const Cha
|
|
|
|
return arg;
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC Arg spdlog::details::fmt::internal::FormatterBase::do_get_arg(
|
|
|
|
FMT_FUNC Arg fmt::internal::FormatterBase::do_get_arg(
|
|
|
|
unsigned arg_index, const char *&error) {
|
|
|
|
unsigned arg_index, const char *&error) {
|
|
|
|
Arg arg = args_[arg_index];
|
|
|
|
Arg arg = args_[arg_index];
|
|
|
|
if (arg.type == Arg::NONE)
|
|
|
|
if (arg.type == Arg::NONE)
|
|
|
@ -659,14 +695,14 @@ FMT_FUNC Arg spdlog::details::fmt::internal::FormatterBase::do_get_arg(
|
|
|
|
return arg;
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Arg spdlog::details::fmt::internal::FormatterBase::next_arg(const char *&error) {
|
|
|
|
inline Arg fmt::internal::FormatterBase::next_arg(const char *&error) {
|
|
|
|
if (next_arg_index_ >= 0)
|
|
|
|
if (next_arg_index_ >= 0)
|
|
|
|
return do_get_arg(next_arg_index_++, error);
|
|
|
|
return do_get_arg(next_arg_index_++, error);
|
|
|
|
error = "cannot switch from manual to automatic argument indexing";
|
|
|
|
error = "cannot switch from manual to automatic argument indexing";
|
|
|
|
return Arg();
|
|
|
|
return Arg();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Arg spdlog::details::fmt::internal::FormatterBase::get_arg(
|
|
|
|
inline Arg fmt::internal::FormatterBase::get_arg(
|
|
|
|
unsigned arg_index, const char *&error) {
|
|
|
|
unsigned arg_index, const char *&error) {
|
|
|
|
if (next_arg_index_ <= 0) {
|
|
|
|
if (next_arg_index_ <= 0) {
|
|
|
|
next_arg_index_ = -1;
|
|
|
|
next_arg_index_ = -1;
|
|
|
@ -677,7 +713,7 @@ inline Arg spdlog::details::fmt::internal::FormatterBase::get_arg(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
FMT_FUNC void spdlog::details::fmt::internal::PrintfFormatter<Char>::parse_flags(
|
|
|
|
void fmt::internal::PrintfFormatter<Char>::parse_flags(
|
|
|
|
FormatSpec &spec, const Char *&s) {
|
|
|
|
FormatSpec &spec, const Char *&s) {
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
|
switch (*s++) {
|
|
|
|
switch (*s++) {
|
|
|
@ -704,8 +740,9 @@ FMT_FUNC void spdlog::details::fmt::internal::PrintfFormatter<Char>::parse_flags
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
FMT_FUNC Arg spdlog::details::fmt::internal::PrintfFormatter<Char>::get_arg(
|
|
|
|
Arg fmt::internal::PrintfFormatter<Char>::get_arg(
|
|
|
|
const Char *s, unsigned arg_index) {
|
|
|
|
const Char *s, unsigned arg_index) {
|
|
|
|
|
|
|
|
(void)s;
|
|
|
|
const char *error = 0;
|
|
|
|
const char *error = 0;
|
|
|
|
Arg arg = arg_index == UINT_MAX ?
|
|
|
|
Arg arg = arg_index == UINT_MAX ?
|
|
|
|
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
|
|
|
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
|
|
@ -715,7 +752,7 @@ FMT_FUNC Arg spdlog::details::fmt::internal::PrintfFormatter<Char>::get_arg(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
FMT_FUNC unsigned spdlog::details::fmt::internal::PrintfFormatter<Char>::parse_header(
|
|
|
|
unsigned fmt::internal::PrintfFormatter<Char>::parse_header(
|
|
|
|
const Char *&s, FormatSpec &spec) {
|
|
|
|
const Char *&s, FormatSpec &spec) {
|
|
|
|
unsigned arg_index = UINT_MAX;
|
|
|
|
unsigned arg_index = UINT_MAX;
|
|
|
|
Char c = *s;
|
|
|
|
Char c = *s;
|
|
|
@ -726,8 +763,7 @@ FMT_FUNC unsigned spdlog::details::fmt::internal::PrintfFormatter<Char>::parse_h
|
|
|
|
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) {
|
|
|
@ -742,8 +778,7 @@ FMT_FUNC unsigned spdlog::details::fmt::internal::PrintfFormatter<Char>::parse_h
|
|
|
|
// 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));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -751,10 +786,10 @@ FMT_FUNC unsigned spdlog::details::fmt::internal::PrintfFormatter<Char>::parse_h
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
FMT_FUNC void spdlog::details::fmt::internal::PrintfFormatter<Char>::format(
|
|
|
|
void fmt::internal::PrintfFormatter<Char>::format(
|
|
|
|
BasicWriter<Char> &writer, BasicStringRef<Char> format,
|
|
|
|
BasicWriter<Char> &writer, BasicStringRef<Char> format_str,
|
|
|
|
const ArgList &args) {
|
|
|
|
const ArgList &args) {
|
|
|
|
const Char *start = format.c_str();
|
|
|
|
const Char *start = format_str.c_str();
|
|
|
|
set_args(args);
|
|
|
|
set_args(args);
|
|
|
|
const Char *s = start;
|
|
|
|
const Char *s = start;
|
|
|
|
while (*s) {
|
|
|
|
while (*s) {
|
|
|
@ -778,8 +813,7 @@ FMT_FUNC void spdlog::details::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));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -805,7 +839,7 @@ FMT_FUNC void spdlog::details::fmt::internal::PrintfFormatter<Char>::format(
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
case 'l':
|
|
|
|
if (*s == 'l')
|
|
|
|
if (*s == 'l')
|
|
|
|
ArgConverter<spdlog::details::fmt::LongLong>(arg, *++s).visit(arg);
|
|
|
|
ArgConverter<fmt::LongLong>(arg, *++s).visit(arg);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
ArgConverter<long>(arg, *s).visit(arg);
|
|
|
|
ArgConverter<long>(arg, *s).visit(arg);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -834,8 +868,7 @@ FMT_FUNC void spdlog::details::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':
|
|
|
@ -872,12 +905,10 @@ FMT_FUNC void spdlog::details::fmt::internal::PrintfFormatter<Char>::format(
|
|
|
|
if (spec.align_ != ALIGN_LEFT) {
|
|
|
|
if (spec.align_ != ALIGN_LEFT) {
|
|
|
|
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 {
|
|
|
|
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 = static_cast<Char>(arg.int_value);
|
|
|
|
*out = static_cast<Char>(arg.int_value);
|
|
|
@ -909,8 +940,8 @@ FMT_FUNC void spdlog::details::fmt::internal::PrintfFormatter<Char>::format(
|
|
|
|
case Arg::CUSTOM: {
|
|
|
|
case Arg::CUSTOM: {
|
|
|
|
if (spec.type_)
|
|
|
|
if (spec.type_)
|
|
|
|
internal::report_unknown_type(spec.type_, "object");
|
|
|
|
internal::report_unknown_type(spec.type_, "object");
|
|
|
|
const void *s = "s";
|
|
|
|
const void *str_format = "s";
|
|
|
|
arg.custom.format(&writer, arg.custom.value, &s);
|
|
|
|
arg.custom.format(&writer, arg.custom.value, &str_format);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -922,7 +953,7 @@ FMT_FUNC void spdlog::details::fmt::internal::PrintfFormatter<Char>::format(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
FMT_FUNC const Char *spdlog::details::fmt::BasicFormatter<Char>::format(
|
|
|
|
const Char *fmt::BasicFormatter<Char>::format(
|
|
|
|
const Char *&format_str, const Arg &arg) {
|
|
|
|
const Char *&format_str, const Arg &arg) {
|
|
|
|
const Char *s = format_str;
|
|
|
|
const Char *s = format_str;
|
|
|
|
FormatSpec spec;
|
|
|
|
FormatSpec spec;
|
|
|
@ -958,8 +989,7 @@ FMT_FUNC const Char *spdlog::details::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;
|
|
|
@ -1007,8 +1037,7 @@ FMT_FUNC const Char *spdlog::details::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;
|
|
|
|
const Arg &precision_arg = parse_arg_index(s);
|
|
|
|
const Arg &precision_arg = parse_arg_index(s);
|
|
|
|
if (*s++ != '}')
|
|
|
|
if (*s++ != '}')
|
|
|
@ -1037,13 +1066,13 @@ FMT_FUNC const Char *spdlog::details::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::DOUBLE && arg.type != Arg::LONG_DOUBLE) {
|
|
|
|
if (arg.type < Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER) {
|
|
|
|
FMT_THROW(FormatError(
|
|
|
|
FMT_THROW(FormatError(
|
|
|
|
"precision specifier requires floating-point argument"));
|
|
|
|
fmt::format("precision not allowed in {} format specifier",
|
|
|
|
|
|
|
|
arg.type == Arg::POINTER ? "pointer" : "integer")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1062,7 +1091,7 @@ FMT_FUNC const Char *spdlog::details::fmt::BasicFormatter<Char>::format(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Char>
|
|
|
|
template <typename Char>
|
|
|
|
FMT_FUNC void spdlog::details::fmt::BasicFormatter<Char>::format(
|
|
|
|
void fmt::BasicFormatter<Char>::format(
|
|
|
|
BasicStringRef<Char> format_str, const ArgList &args) {
|
|
|
|
BasicStringRef<Char> format_str, const ArgList &args) {
|
|
|
|
const Char *s = start_ = format_str.c_str();
|
|
|
|
const Char *s = start_ = format_str.c_str();
|
|
|
|
set_args(args);
|
|
|
|
set_args(args);
|
|
|
@ -1083,35 +1112,35 @@ FMT_FUNC void spdlog::details::fmt::BasicFormatter<Char>::format(
|
|
|
|
write(writer_, start_, s);
|
|
|
|
write(writer_, start_, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::report_system_error(
|
|
|
|
FMT_FUNC void fmt::report_system_error(
|
|
|
|
int error_code, spdlog::details::fmt::StringRef message) FMT_NOEXCEPT(true) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef _WIN32
|
|
|
|
FMT_FUNC void spdlog::details::fmt::report_windows_error(
|
|
|
|
FMT_FUNC void fmt::report_windows_error(
|
|
|
|
int error_code, spdlog::details::fmt::StringRef message) FMT_NOEXCEPT(true) {
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::print(std::FILE *f, StringRef format_str, ArgList args) {
|
|
|
|
FMT_FUNC void fmt::print(std::FILE *f, StringRef format_str, ArgList args) {
|
|
|
|
MemoryWriter w;
|
|
|
|
MemoryWriter w;
|
|
|
|
w.write(format_str, args);
|
|
|
|
w.write(format_str, args);
|
|
|
|
std::fwrite(w.data(), 1, w.size(), f);
|
|
|
|
std::fwrite(w.data(), 1, w.size(), f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::print(StringRef format_str, ArgList args) {
|
|
|
|
FMT_FUNC void fmt::print(StringRef format_str, ArgList args) {
|
|
|
|
print(stdout, format_str, args);
|
|
|
|
print(stdout, format_str, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::print(std::ostream &os, StringRef format_str, ArgList args) {
|
|
|
|
FMT_FUNC void fmt::print(std::ostream &os, StringRef format_str, ArgList args) {
|
|
|
|
MemoryWriter w;
|
|
|
|
MemoryWriter w;
|
|
|
|
w.write(format_str, args);
|
|
|
|
w.write(format_str, args);
|
|
|
|
os.write(w.data(), w.size());
|
|
|
|
os.write(w.data(), w.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC void spdlog::details::fmt::print_colored(Color c, StringRef format, ArgList args) {
|
|
|
|
FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) {
|
|
|
|
char escape[] = "\x1b[30m";
|
|
|
|
char escape[] = "\x1b[30m";
|
|
|
|
escape[3] = '0' + static_cast<char>(c);
|
|
|
|
escape[3] = '0' + static_cast<char>(c);
|
|
|
|
std::fputs(escape, stdout);
|
|
|
|
std::fputs(escape, stdout);
|
|
|
@ -1119,52 +1148,60 @@ FMT_FUNC void spdlog::details::fmt::print_colored(Color c, StringRef format, Arg
|
|
|
|
std::fputs(RESET_COLOR, stdout);
|
|
|
|
std::fputs(RESET_COLOR, stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FMT_FUNC int spdlog::details::fmt::fprintf(std::FILE *f, StringRef format, ArgList args) {
|
|
|
|
FMT_FUNC int fmt::fprintf(std::FILE *f, StringRef format, ArgList args) {
|
|
|
|
MemoryWriter w;
|
|
|
|
MemoryWriter w;
|
|
|
|
printf(w, format, args);
|
|
|
|
printf(w, format, args);
|
|
|
|
std::size_t size = w.size();
|
|
|
|
std::size_t size = w.size();
|
|
|
|
return std::fwrite(w.data(), 1, size, f) < size ? -1 : static_cast<int>(size);
|
|
|
|
return std::fwrite(w.data(), 1, size, f) < size ? -1 : static_cast<int>(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FMT_HEADER_ONLY
|
|
|
|
|
|
|
|
|
|
|
|
// Explicit instantiations for char.
|
|
|
|
// Explicit instantiations for char.
|
|
|
|
|
|
|
|
|
|
|
|
template const char *spdlog::details::fmt::BasicFormatter<char>::format(
|
|
|
|
template void fmt::internal::FixedBuffer<char>::grow(std::size_t);
|
|
|
|
const char *&format_str, const spdlog::details::fmt::internal::Arg &arg);
|
|
|
|
|
|
|
|
|
|
|
|
template const char *fmt::BasicFormatter<char>::format(
|
|
|
|
|
|
|
|
const char *&format_str, const fmt::internal::Arg &arg);
|
|
|
|
|
|
|
|
|
|
|
|
template void spdlog::details::fmt::BasicFormatter<char>::format(
|
|
|
|
template void fmt::BasicFormatter<char>::format(
|
|
|
|
BasicStringRef<char> format, const ArgList &args);
|
|
|
|
BasicStringRef<char> format, const ArgList &args);
|
|
|
|
|
|
|
|
|
|
|
|
template void spdlog::details::fmt::internal::PrintfFormatter<char>::format(
|
|
|
|
template void fmt::internal::PrintfFormatter<char>::format(
|
|
|
|
BasicWriter<char> &writer, BasicStringRef<char> format, const ArgList &args);
|
|
|
|
BasicWriter<char> &writer, BasicStringRef<char> format, const ArgList &args);
|
|
|
|
|
|
|
|
|
|
|
|
template int spdlog::details::fmt::internal::CharTraits<char>::format_float(
|
|
|
|
template int fmt::internal::CharTraits<char>::format_float(
|
|
|
|
char *buffer, std::size_t size, const char *format,
|
|
|
|
char *buffer, std::size_t size, const char *format,
|
|
|
|
unsigned width, int precision, double value);
|
|
|
|
unsigned width, int precision, double value);
|
|
|
|
|
|
|
|
|
|
|
|
template int spdlog::details::fmt::internal::CharTraits<char>::format_float(
|
|
|
|
template int fmt::internal::CharTraits<char>::format_float(
|
|
|
|
char *buffer, std::size_t size, const char *format,
|
|
|
|
char *buffer, std::size_t size, const char *format,
|
|
|
|
unsigned width, int precision, long double value);
|
|
|
|
unsigned width, int precision, long double value);
|
|
|
|
|
|
|
|
|
|
|
|
// Explicit instantiations for wchar_t.
|
|
|
|
// Explicit instantiations for wchar_t.
|
|
|
|
|
|
|
|
|
|
|
|
template const wchar_t *spdlog::details::fmt::BasicFormatter<wchar_t>::format(
|
|
|
|
template void fmt::internal::FixedBuffer<wchar_t>::grow(std::size_t);
|
|
|
|
const wchar_t *&format_str, const spdlog::details::fmt::internal::Arg &arg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template void spdlog::details::fmt::BasicFormatter<wchar_t>::format(
|
|
|
|
template const wchar_t *fmt::BasicFormatter<wchar_t>::format(
|
|
|
|
|
|
|
|
const wchar_t *&format_str, const fmt::internal::Arg &arg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template void fmt::BasicFormatter<wchar_t>::format(
|
|
|
|
BasicStringRef<wchar_t> format, const ArgList &args);
|
|
|
|
BasicStringRef<wchar_t> format, const ArgList &args);
|
|
|
|
|
|
|
|
|
|
|
|
template void spdlog::details::fmt::internal::PrintfFormatter<wchar_t>::format(
|
|
|
|
template void fmt::internal::PrintfFormatter<wchar_t>::format(
|
|
|
|
BasicWriter<wchar_t> &writer, BasicStringRef<wchar_t> format,
|
|
|
|
BasicWriter<wchar_t> &writer, BasicStringRef<wchar_t> format,
|
|
|
|
const ArgList &args);
|
|
|
|
const ArgList &args);
|
|
|
|
|
|
|
|
|
|
|
|
template int spdlog::details::fmt::internal::CharTraits<wchar_t>::format_float(
|
|
|
|
template int fmt::internal::CharTraits<wchar_t>::format_float(
|
|
|
|
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
|
|
|
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
|
|
|
unsigned width, int precision, double value);
|
|
|
|
unsigned width, int precision, double value);
|
|
|
|
|
|
|
|
|
|
|
|
template int spdlog::details::fmt::internal::CharTraits<wchar_t>::format_float(
|
|
|
|
template int fmt::internal::CharTraits<wchar_t>::format_float(
|
|
|
|
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
|
|
|
wchar_t *buffer, std::size_t size, const wchar_t *format,
|
|
|
|
unsigned width, int precision, long double value);
|
|
|
|
unsigned width, int precision, long double value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FMT_HEADER_ONLY
|
|
|
|
|
|
|
|
|
|
|
|
#if _MSC_VER
|
|
|
|
#if _MSC_VER
|
|
|
|
# pragma warning(pop)
|
|
|
|
# pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
#endif
|