mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 11:29:01 +08:00
clang-format
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -13,14 +13,11 @@
|
||||
#include "format.h"
|
||||
#include <ostream>
|
||||
|
||||
namespace fmt
|
||||
{
|
||||
namespace fmt {
|
||||
|
||||
namespace internal
|
||||
{
|
||||
namespace internal {
|
||||
|
||||
template <class Char>
|
||||
class FormatBuf : public std::basic_streambuf<Char>
|
||||
template <class Char> class FormatBuf : public std::basic_streambuf<Char>
|
||||
{
|
||||
private:
|
||||
typedef typename std::basic_streambuf<Char>::int_type int_type;
|
||||
@@ -29,7 +26,10 @@ private:
|
||||
Buffer<Char> &buffer_;
|
||||
|
||||
public:
|
||||
FormatBuf(Buffer<Char> &buffer) : buffer_(buffer) {}
|
||||
FormatBuf(Buffer<Char> &buffer)
|
||||
: buffer_(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
// The put-area is actually always empty. This makes the implementation
|
||||
@@ -57,17 +57,15 @@ Yes &convert(std::ostream &);
|
||||
|
||||
struct DummyStream : std::ostream
|
||||
{
|
||||
DummyStream(); // Suppress a bogus warning in MSVC.
|
||||
DummyStream(); // Suppress a bogus warning in MSVC.
|
||||
|
||||
// Hide all operator<< overloads from std::ostream.
|
||||
template <typename T>
|
||||
typename EnableIf<sizeof(T) == 0>::type operator<<(const T &);
|
||||
template <typename T> typename EnableIf<sizeof(T) == 0>::type operator<<(const T &);
|
||||
};
|
||||
|
||||
No &operator<<(std::ostream &, int);
|
||||
|
||||
template <typename T>
|
||||
struct ConvertToIntImpl<T, true>
|
||||
template <typename T> struct ConvertToIntImpl<T, true>
|
||||
{
|
||||
// Convert to int only if T doesn't have an overloaded operator<<.
|
||||
enum
|
||||
@@ -78,12 +76,11 @@ struct ConvertToIntImpl<T, true>
|
||||
|
||||
// Write the content of w to os.
|
||||
FMT_API void write(std::ostream &os, Writer &w);
|
||||
} // namespace internal
|
||||
} // namespace internal
|
||||
|
||||
// Formats a value.
|
||||
template <typename Char, typename ArgFormatter_, typename T>
|
||||
void format_arg(BasicFormatter<Char, ArgFormatter_> &f,
|
||||
const Char *&format_str, const T &value)
|
||||
void format_arg(BasicFormatter<Char, ArgFormatter_> &f, const Char *&format_str, const T &value)
|
||||
{
|
||||
internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;
|
||||
|
||||
@@ -93,7 +90,7 @@ void format_arg(BasicFormatter<Char, ArgFormatter_> &f,
|
||||
output << value;
|
||||
|
||||
BasicStringRef<Char> str(&buffer[0], buffer.size());
|
||||
typedef internal::MakeArg< BasicFormatter<Char> > MakeArg;
|
||||
typedef internal::MakeArg<BasicFormatter<Char>> MakeArg;
|
||||
format_str = f.format(format_str, MakeArg(str));
|
||||
}
|
||||
|
||||
@@ -108,10 +105,10 @@ void format_arg(BasicFormatter<Char, ArgFormatter_> &f,
|
||||
*/
|
||||
FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args);
|
||||
FMT_VARIADIC(void, print, std::ostream &, CStringRef)
|
||||
} // namespace fmt
|
||||
} // namespace fmt
|
||||
|
||||
#ifdef FMT_HEADER_ONLY
|
||||
# include "ostream.cc"
|
||||
#include "ostream.cc"
|
||||
#endif
|
||||
|
||||
#endif // FMT_OSTREAM_H_
|
||||
#endif // FMT_OSTREAM_H_
|
||||
|
@@ -12,60 +12,60 @@
|
||||
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
// Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/.
|
||||
# undef __STRICT_ANSI__
|
||||
#undef __STRICT_ANSI__
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> // for O_RDONLY
|
||||
#include <locale.h> // for locale_t
|
||||
#include <fcntl.h> // for O_RDONLY
|
||||
#include <locale.h> // for locale_t
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // for strtod_l
|
||||
#include <stdlib.h> // for strtod_l
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#if defined __APPLE__ || defined(__FreeBSD__)
|
||||
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
|
||||
#include <xlocale.h> // for LC_NUMERIC_MASK on OS X
|
||||
#endif
|
||||
|
||||
#include "format.h"
|
||||
|
||||
#ifndef FMT_POSIX
|
||||
# if defined(_WIN32) && !defined(__MINGW32__)
|
||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||
// Fix warnings about deprecated symbols.
|
||||
# define FMT_POSIX(call) _##call
|
||||
# else
|
||||
# define FMT_POSIX(call) call
|
||||
# endif
|
||||
#define FMT_POSIX(call) _##call
|
||||
#else
|
||||
#define FMT_POSIX(call) call
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Calls to system functions are wrapped in FMT_SYSTEM for testability.
|
||||
#ifdef FMT_SYSTEM
|
||||
# define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
|
||||
#define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
|
||||
#else
|
||||
# define FMT_SYSTEM(call) call
|
||||
# ifdef _WIN32
|
||||
#define FMT_SYSTEM(call) call
|
||||
#ifdef _WIN32
|
||||
// Fix warnings about deprecated symbols.
|
||||
# define FMT_POSIX_CALL(call) ::_##call
|
||||
# else
|
||||
# define FMT_POSIX_CALL(call) ::call
|
||||
# endif
|
||||
#define FMT_POSIX_CALL(call) ::_##call
|
||||
#else
|
||||
#define FMT_POSIX_CALL(call) ::call
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Retries the expression while it evaluates to error_result and errno
|
||||
// equals to EINTR.
|
||||
#ifndef _WIN32
|
||||
# define FMT_RETRY_VAL(result, expression, error_result) \
|
||||
do { \
|
||||
result = (expression); \
|
||||
} while (result == error_result && errno == EINTR)
|
||||
#define FMT_RETRY_VAL(result, expression, error_result) \
|
||||
do \
|
||||
{ \
|
||||
result = (expression); \
|
||||
} while (result == error_result && errno == EINTR)
|
||||
#else
|
||||
# define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
|
||||
#define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
|
||||
#endif
|
||||
|
||||
#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
|
||||
|
||||
namespace fmt
|
||||
{
|
||||
namespace fmt {
|
||||
|
||||
// An error code.
|
||||
class ErrorCode
|
||||
@@ -74,8 +74,7 @@ private:
|
||||
int value_;
|
||||
|
||||
public:
|
||||
explicit ErrorCode(int value = 0) FMT_NOEXCEPT :
|
||||
value_(value) {}
|
||||
explicit ErrorCode(int value = 0) FMT_NOEXCEPT : value_(value) {}
|
||||
|
||||
int get() const FMT_NOEXCEPT
|
||||
{
|
||||
@@ -91,12 +90,14 @@ private:
|
||||
|
||||
friend class File;
|
||||
|
||||
explicit BufferedFile(FILE *f) : file_(f) {}
|
||||
explicit BufferedFile(FILE *f)
|
||||
: file_(f)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
// Constructs a BufferedFile object which doesn't represent any file.
|
||||
BufferedFile() FMT_NOEXCEPT :
|
||||
file_(FMT_NULL) {}
|
||||
BufferedFile() FMT_NOEXCEPT : file_(FMT_NULL) {}
|
||||
|
||||
// Destroys the object closing the file it represents if any.
|
||||
FMT_API ~BufferedFile() FMT_NOEXCEPT;
|
||||
@@ -115,12 +116,10 @@ private:
|
||||
|
||||
public:
|
||||
// A "move constructor" for moving from a temporary.
|
||||
BufferedFile(Proxy p) FMT_NOEXCEPT :
|
||||
file_(p.file) {}
|
||||
BufferedFile(Proxy p) FMT_NOEXCEPT : file_(p.file) {}
|
||||
|
||||
// A "move constructor" for moving from an lvalue.
|
||||
BufferedFile(BufferedFile &f) FMT_NOEXCEPT :
|
||||
file_(f.file_)
|
||||
BufferedFile(BufferedFile &f) FMT_NOEXCEPT : file_(f.file_)
|
||||
{
|
||||
f.file_ = FMT_NULL;
|
||||
}
|
||||
@@ -156,13 +155,12 @@ private:
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(BufferedFile);
|
||||
|
||||
public:
|
||||
BufferedFile(BufferedFile &&other) FMT_NOEXCEPT :
|
||||
file_(other.file_)
|
||||
BufferedFile(BufferedFile &&other) FMT_NOEXCEPT : file_(other.file_)
|
||||
{
|
||||
other.file_ = FMT_NULL;
|
||||
}
|
||||
|
||||
BufferedFile& operator=(BufferedFile &&other)
|
||||
BufferedFile &operator=(BufferedFile &&other)
|
||||
{
|
||||
close();
|
||||
file_ = other.file_;
|
||||
@@ -185,7 +183,7 @@ BufferedFile(BufferedFile &&other) FMT_NOEXCEPT :
|
||||
|
||||
// We place parentheses around fileno to workaround a bug in some versions
|
||||
// of MinGW that define fileno as a macro.
|
||||
FMT_API int (fileno)() const;
|
||||
FMT_API int(fileno)() const;
|
||||
|
||||
void print(CStringRef format_str, const ArgList &args)
|
||||
{
|
||||
@@ -203,10 +201,13 @@ BufferedFile(BufferedFile &&other) FMT_NOEXCEPT :
|
||||
class File
|
||||
{
|
||||
private:
|
||||
int fd_; // File descriptor.
|
||||
int fd_; // File descriptor.
|
||||
|
||||
// Constructs a File object with a given descriptor.
|
||||
explicit File(int fd) : fd_(fd) {}
|
||||
explicit File(int fd)
|
||||
: fd_(fd)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
// Possible values for the oflag argument to the constructor.
|
||||
@@ -214,12 +215,11 @@ public:
|
||||
{
|
||||
RDONLY = FMT_POSIX(O_RDONLY), // Open for reading only.
|
||||
WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only.
|
||||
RDWR = FMT_POSIX(O_RDWR) // Open for reading and writing.
|
||||
RDWR = FMT_POSIX(O_RDWR) // Open for reading and writing.
|
||||
};
|
||||
|
||||
// Constructs a File object which doesn't represent any file.
|
||||
File() FMT_NOEXCEPT :
|
||||
fd_(-1) {}
|
||||
File() FMT_NOEXCEPT : fd_(-1) {}
|
||||
|
||||
// Opens a file and constructs a File object representing this file.
|
||||
FMT_API File(CStringRef path, int oflag);
|
||||
@@ -238,12 +238,10 @@ private:
|
||||
|
||||
public:
|
||||
// A "move constructor" for moving from a temporary.
|
||||
File(Proxy p) FMT_NOEXCEPT :
|
||||
fd_(p.fd) {}
|
||||
File(Proxy p) FMT_NOEXCEPT : fd_(p.fd) {}
|
||||
|
||||
// A "move constructor" for moving from an lvalue.
|
||||
File(File &other) FMT_NOEXCEPT :
|
||||
fd_(other.fd_)
|
||||
File(File &other) FMT_NOEXCEPT : fd_(other.fd_)
|
||||
{
|
||||
other.fd_ = -1;
|
||||
}
|
||||
@@ -279,13 +277,12 @@ private:
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(File);
|
||||
|
||||
public:
|
||||
File(File &&other) FMT_NOEXCEPT :
|
||||
fd_(other.fd_)
|
||||
File(File &&other) FMT_NOEXCEPT : fd_(other.fd_)
|
||||
{
|
||||
other.fd_ = -1;
|
||||
}
|
||||
|
||||
File& operator=(File &&other)
|
||||
File &operator=(File &&other)
|
||||
{
|
||||
close();
|
||||
fd_ = other.fd_;
|
||||
@@ -340,9 +337,8 @@ File(File &&other) FMT_NOEXCEPT :
|
||||
// Returns the memory page size.
|
||||
long getpagesize();
|
||||
|
||||
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \
|
||||
!defined(__ANDROID__) && !defined(__CYGWIN__)
|
||||
# define FMT_LOCALE
|
||||
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && !defined(__ANDROID__) && !defined(__CYGWIN__)
|
||||
#define FMT_LOCALE
|
||||
#endif
|
||||
|
||||
#ifdef FMT_LOCALE
|
||||
@@ -350,10 +346,13 @@ long getpagesize();
|
||||
class Locale
|
||||
{
|
||||
private:
|
||||
# ifdef _MSC_VER
|
||||
#ifdef _MSC_VER
|
||||
typedef _locale_t locale_t;
|
||||
|
||||
enum { LC_NUMERIC_MASK = LC_NUMERIC };
|
||||
enum
|
||||
{
|
||||
LC_NUMERIC_MASK = LC_NUMERIC
|
||||
};
|
||||
|
||||
static locale_t newlocale(int category_mask, const char *locale, locale_t)
|
||||
{
|
||||
@@ -369,7 +368,7 @@ private:
|
||||
{
|
||||
return _strtod_l(nptr, endptr, locale);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
locale_t locale_;
|
||||
|
||||
@@ -378,7 +377,8 @@ private:
|
||||
public:
|
||||
typedef locale_t Type;
|
||||
|
||||
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL))
|
||||
Locale()
|
||||
: locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL))
|
||||
{
|
||||
if (!locale_)
|
||||
FMT_THROW(fmt::SystemError(errno, "cannot create locale"));
|
||||
@@ -403,12 +403,11 @@ public:
|
||||
return result;
|
||||
}
|
||||
};
|
||||
#endif // FMT_LOCALE
|
||||
} // namespace fmt
|
||||
#endif // FMT_LOCALE
|
||||
} // namespace fmt
|
||||
|
||||
#if !FMT_USE_RVALUE_REFERENCES
|
||||
namespace std
|
||||
{
|
||||
namespace std {
|
||||
// For compatibility with C++98.
|
||||
inline fmt::BufferedFile &move(fmt::BufferedFile &f)
|
||||
{
|
||||
@@ -418,7 +417,7 @@ inline fmt::File &move(fmt::File &f)
|
||||
{
|
||||
return f;
|
||||
}
|
||||
}
|
||||
} // namespace std
|
||||
#endif
|
||||
|
||||
#endif // FMT_POSIX_H_
|
||||
#endif // FMT_POSIX_H_
|
||||
|
@@ -10,23 +10,19 @@
|
||||
#ifndef FMT_PRINTF_H_
|
||||
#define FMT_PRINTF_H_
|
||||
|
||||
#include <algorithm> // std::fill_n
|
||||
#include <limits> // std::numeric_limits
|
||||
#include <algorithm> // std::fill_n
|
||||
#include <limits> // std::numeric_limits
|
||||
|
||||
#include "ostream.h"
|
||||
|
||||
namespace fmt
|
||||
{
|
||||
namespace internal
|
||||
{
|
||||
namespace fmt {
|
||||
namespace internal {
|
||||
|
||||
// Checks if a value fits in int - used to avoid warnings about comparing
|
||||
// signed and unsigned integers.
|
||||
template <bool IsSigned>
|
||||
struct IntChecker
|
||||
template <bool IsSigned> struct IntChecker
|
||||
{
|
||||
template <typename T>
|
||||
static bool fits_in_int(T value)
|
||||
template <typename T> static bool fits_in_int(T value)
|
||||
{
|
||||
unsigned max = std::numeric_limits<int>::max();
|
||||
return value <= max;
|
||||
@@ -37,14 +33,11 @@ struct IntChecker
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IntChecker<true>
|
||||
template <> struct IntChecker<true>
|
||||
{
|
||||
template <typename T>
|
||||
static bool fits_in_int(T value)
|
||||
template <typename T> static bool fits_in_int(T value)
|
||||
{
|
||||
return value >= std::numeric_limits<int>::min() &&
|
||||
value <= std::numeric_limits<int>::max();
|
||||
return value >= std::numeric_limits<int>::min() && value <= std::numeric_limits<int>::max();
|
||||
}
|
||||
static bool fits_in_int(int)
|
||||
{
|
||||
@@ -60,8 +53,7 @@ public:
|
||||
FMT_THROW(FormatError("precision is not integer"));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int visit_any_int(T value)
|
||||
template <typename T> int visit_any_int(T value)
|
||||
{
|
||||
if (!IntChecker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
|
||||
FMT_THROW(FormatError("number is too big"));
|
||||
@@ -73,8 +65,7 @@ public:
|
||||
class IsZeroInt : public ArgVisitor<IsZeroInt, bool>
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
bool visit_any_int(T value)
|
||||
template <typename T> bool visit_any_int(T value)
|
||||
{
|
||||
return value == 0;
|
||||
}
|
||||
@@ -99,14 +90,12 @@ public:
|
||||
return 'p';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
char visit_any_int(T)
|
||||
template <typename T> char visit_any_int(T)
|
||||
{
|
||||
return 'd';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
char visit_any_double(T)
|
||||
template <typename T> char visit_any_double(T)
|
||||
{
|
||||
return 'g';
|
||||
}
|
||||
@@ -117,24 +106,27 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct is_same
|
||||
template <typename T, typename U> struct is_same
|
||||
{
|
||||
enum { value = 0 };
|
||||
enum
|
||||
{
|
||||
value = 0
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct is_same<T, T>
|
||||
template <typename T> struct is_same<T, T>
|
||||
{
|
||||
enum { value = 1 };
|
||||
enum
|
||||
{
|
||||
value = 1
|
||||
};
|
||||
};
|
||||
|
||||
// An argument visitor that converts an integer argument to T for printf,
|
||||
// if T is an integral type. If T is void, the argument is converted to
|
||||
// corresponding signed or unsigned type depending on the type specifier:
|
||||
// 'd' and 'i' - signed, other - unsigned)
|
||||
template <typename T = void>
|
||||
class ArgConverter : public ArgVisitor<ArgConverter<T>, void>
|
||||
template <typename T = void> class ArgConverter : public ArgVisitor<ArgConverter<T>, void>
|
||||
{
|
||||
private:
|
||||
internal::Arg &arg_;
|
||||
@@ -144,7 +136,10 @@ private:
|
||||
|
||||
public:
|
||||
ArgConverter(internal::Arg &arg, wchar_t type)
|
||||
: arg_(arg), type_(type) {}
|
||||
: arg_(arg)
|
||||
, type_(type)
|
||||
{
|
||||
}
|
||||
|
||||
void visit_bool(bool value)
|
||||
{
|
||||
@@ -158,8 +153,7 @@ public:
|
||||
visit_any_int(value);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void visit_any_int(U value)
|
||||
template <typename U> void visit_any_int(U value)
|
||||
{
|
||||
bool is_signed = type_ == 'd' || type_ == 'i';
|
||||
if (type_ == 's')
|
||||
@@ -168,8 +162,7 @@ public:
|
||||
}
|
||||
|
||||
using internal::Arg;
|
||||
typedef typename internal::Conditional<
|
||||
is_same<T, void>::value, U, T>::type TargetType;
|
||||
typedef typename internal::Conditional<is_same<T, void>::value, U, T>::type TargetType;
|
||||
if (const_check(sizeof(TargetType) <= sizeof(int)))
|
||||
{
|
||||
// Extra casts are used to silence warnings.
|
||||
@@ -198,8 +191,7 @@ public:
|
||||
else
|
||||
{
|
||||
arg_.type = Arg::ULONG_LONG;
|
||||
arg_.ulong_long_value =
|
||||
static_cast<typename internal::MakeUnsigned<U>::Type>(value);
|
||||
arg_.ulong_long_value = static_cast<typename internal::MakeUnsigned<U>::Type>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,10 +206,12 @@ private:
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(CharConverter);
|
||||
|
||||
public:
|
||||
explicit CharConverter(internal::Arg &arg) : arg_(arg) {}
|
||||
explicit CharConverter(internal::Arg &arg)
|
||||
: arg_(arg)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void visit_any_int(T value)
|
||||
template <typename T> void visit_any_int(T value)
|
||||
{
|
||||
arg_.type = internal::Arg::CHAR;
|
||||
arg_.int_value = static_cast<char>(value);
|
||||
@@ -234,15 +228,17 @@ private:
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(WidthHandler);
|
||||
|
||||
public:
|
||||
explicit WidthHandler(FormatSpec &spec) : spec_(spec) {}
|
||||
explicit WidthHandler(FormatSpec &spec)
|
||||
: spec_(spec)
|
||||
{
|
||||
}
|
||||
|
||||
void report_unhandled_arg()
|
||||
{
|
||||
FMT_THROW(FormatError("width is not integer"));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
unsigned visit_any_int(T value)
|
||||
template <typename T> unsigned visit_any_int(T value)
|
||||
{
|
||||
typedef typename internal::IntTraits<T>::MainType UnsignedType;
|
||||
UnsignedType width = static_cast<UnsignedType>(value);
|
||||
@@ -257,7 +253,7 @@ public:
|
||||
return static_cast<unsigned>(width);
|
||||
}
|
||||
};
|
||||
} // namespace internal
|
||||
} // namespace internal
|
||||
|
||||
/**
|
||||
\rst
|
||||
@@ -276,9 +272,7 @@ public:
|
||||
superclass will be called.
|
||||
\endrst
|
||||
*/
|
||||
template <typename Impl, typename Char, typename Spec>
|
||||
class BasicPrintfArgFormatter :
|
||||
public internal::ArgFormatterBase<Impl, Char, Spec>
|
||||
template <typename Impl, typename Char, typename Spec> class BasicPrintfArgFormatter : public internal::ArgFormatterBase<Impl, Char, Spec>
|
||||
{
|
||||
private:
|
||||
void write_null_pointer()
|
||||
@@ -298,7 +292,9 @@ public:
|
||||
\endrst
|
||||
*/
|
||||
BasicPrintfArgFormatter(BasicWriter<Char> &w, Spec &s)
|
||||
: internal::ArgFormatterBase<Impl, Char, Spec>(w, s) {}
|
||||
: internal::ArgFormatterBase<Impl, Char, Spec>(w, s)
|
||||
{
|
||||
}
|
||||
|
||||
/** Formats an argument of type ``bool``. */
|
||||
void visit_bool(bool value)
|
||||
@@ -371,19 +367,18 @@ public:
|
||||
};
|
||||
|
||||
/** The default printf argument formatter. */
|
||||
template <typename Char>
|
||||
class PrintfArgFormatter :
|
||||
public BasicPrintfArgFormatter<PrintfArgFormatter<Char>, Char, FormatSpec>
|
||||
template <typename Char> class PrintfArgFormatter : public BasicPrintfArgFormatter<PrintfArgFormatter<Char>, Char, FormatSpec>
|
||||
{
|
||||
public:
|
||||
/** Constructs an argument formatter object. */
|
||||
PrintfArgFormatter(BasicWriter<Char> &w, FormatSpec &s)
|
||||
: BasicPrintfArgFormatter<PrintfArgFormatter<Char>, Char, FormatSpec>(w, s) {}
|
||||
: BasicPrintfArgFormatter<PrintfArgFormatter<Char>, Char, FormatSpec>(w, s)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/** This template formats data and writes the output to a writer. */
|
||||
template <typename Char, typename ArgFormatter = PrintfArgFormatter<Char> >
|
||||
class PrintfFormatter : private internal::FormatterBase
|
||||
template <typename Char, typename ArgFormatter = PrintfArgFormatter<Char>> class PrintfFormatter : private internal::FormatterBase
|
||||
{
|
||||
private:
|
||||
BasicWriter<Char> &writer_;
|
||||
@@ -392,9 +387,7 @@ private:
|
||||
|
||||
// Returns the argument with specified index or, if arg_index is equal
|
||||
// to the maximum unsigned value, the next argument.
|
||||
internal::Arg get_arg(
|
||||
const Char *s,
|
||||
unsigned arg_index = (std::numeric_limits<unsigned>::max)());
|
||||
internal::Arg get_arg(const Char *s, unsigned arg_index = (std::numeric_limits<unsigned>::max)());
|
||||
|
||||
// Parses argument index, flags and width and returns the argument index.
|
||||
unsigned parse_header(const Char *&s, FormatSpec &spec);
|
||||
@@ -408,14 +401,16 @@ public:
|
||||
\endrst
|
||||
*/
|
||||
explicit PrintfFormatter(const ArgList &al, BasicWriter<Char> &w)
|
||||
: FormatterBase(al), writer_(w) {}
|
||||
: FormatterBase(al)
|
||||
, writer_(w)
|
||||
{
|
||||
}
|
||||
|
||||
/** Formats stored arguments and writes the output to the writer. */
|
||||
void format(BasicCStringRef<Char> format_str);
|
||||
};
|
||||
|
||||
template <typename Char, typename AF>
|
||||
void PrintfFormatter<Char, AF>::parse_flags(FormatSpec &spec, const Char *&s)
|
||||
template <typename Char, typename AF> void PrintfFormatter<Char, AF>::parse_flags(FormatSpec &spec, const Char *&s)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
@@ -443,22 +438,17 @@ void PrintfFormatter<Char, AF>::parse_flags(FormatSpec &spec, const Char *&s)
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Char, typename AF>
|
||||
internal::Arg PrintfFormatter<Char, AF>::get_arg(const Char *s,
|
||||
unsigned arg_index)
|
||||
template <typename Char, typename AF> internal::Arg PrintfFormatter<Char, AF>::get_arg(const Char *s, unsigned arg_index)
|
||||
{
|
||||
(void)s;
|
||||
const char *error = FMT_NULL;
|
||||
internal::Arg arg = arg_index == std::numeric_limits<unsigned>::max() ?
|
||||
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
||||
internal::Arg arg = arg_index == std::numeric_limits<unsigned>::max() ? next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
||||
if (error)
|
||||
FMT_THROW(FormatError(!*s ? "invalid format string" : error));
|
||||
return arg;
|
||||
}
|
||||
|
||||
template <typename Char, typename AF>
|
||||
unsigned PrintfFormatter<Char, AF>::parse_header(
|
||||
const Char *&s, FormatSpec &spec)
|
||||
template <typename Char, typename AF> unsigned PrintfFormatter<Char, AF>::parse_header(const Char *&s, FormatSpec &spec)
|
||||
{
|
||||
unsigned arg_index = std::numeric_limits<unsigned>::max();
|
||||
Char c = *s;
|
||||
@@ -467,7 +457,7 @@ unsigned PrintfFormatter<Char, AF>::parse_header(
|
||||
// Parse an argument index (if followed by '$') or a width possibly
|
||||
// preceded with '0' flag(s).
|
||||
unsigned value = internal::parse_nonnegative_int(s);
|
||||
if (*s == '$') // value is an argument index
|
||||
if (*s == '$') // value is an argument index
|
||||
{
|
||||
++s;
|
||||
arg_index = value;
|
||||
@@ -499,15 +489,15 @@ unsigned PrintfFormatter<Char, AF>::parse_header(
|
||||
return arg_index;
|
||||
}
|
||||
|
||||
template <typename Char, typename AF>
|
||||
void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str)
|
||||
template <typename Char, typename AF> void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str)
|
||||
{
|
||||
const Char *start = format_str.c_str();
|
||||
const Char *s = start;
|
||||
while (*s)
|
||||
{
|
||||
Char c = *s++;
|
||||
if (c != '%') continue;
|
||||
if (c != '%')
|
||||
continue;
|
||||
if (*s == c)
|
||||
{
|
||||
write(writer_, start, s);
|
||||
@@ -550,7 +540,7 @@ void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str)
|
||||
if (arg.type <= Arg::LAST_NUMERIC_TYPE)
|
||||
spec.align_ = ALIGN_NUMERIC;
|
||||
else
|
||||
spec.fill_ = ' '; // Ignore '0' flag for non-numeric types.
|
||||
spec.fill_ = ' '; // Ignore '0' flag for non-numeric types.
|
||||
}
|
||||
|
||||
// Parse length and convert the argument to the required type.
|
||||
@@ -703,10 +693,10 @@ inline int fprintf(std::ostream &os, CStringRef format_str, ArgList args)
|
||||
return static_cast<int>(w.size());
|
||||
}
|
||||
FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef)
|
||||
} // namespace fmt
|
||||
} // namespace fmt
|
||||
|
||||
#ifdef FMT_HEADER_ONLY
|
||||
# include "printf.cc"
|
||||
#include "printf.cc"
|
||||
#endif
|
||||
|
||||
#endif // FMT_PRINTF_H_
|
||||
#endif // FMT_PRINTF_H_
|
||||
|
@@ -14,16 +14,13 @@
|
||||
#include <ctime>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4702) // unreachable code
|
||||
# pragma warning(disable: 4996) // "deprecated" functions
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4702) // unreachable code
|
||||
#pragma warning(disable : 4996) // "deprecated" functions
|
||||
#endif
|
||||
|
||||
namespace fmt
|
||||
{
|
||||
template <typename ArgFormatter>
|
||||
void format_arg(BasicFormatter<char, ArgFormatter> &f,
|
||||
const char *&format_str, const std::tm &tm)
|
||||
namespace fmt {
|
||||
template <typename ArgFormatter> void format_arg(BasicFormatter<char, ArgFormatter> &f, const char *&format_str, const std::tm &tm)
|
||||
{
|
||||
if (*format_str == ':')
|
||||
++format_str;
|
||||
@@ -60,8 +57,7 @@ void format_arg(BasicFormatter<char, ArgFormatter> &f,
|
||||
format_str = end + 1;
|
||||
}
|
||||
|
||||
namespace internal
|
||||
{
|
||||
namespace internal {
|
||||
inline Null<> localtime_r(...)
|
||||
{
|
||||
return Null<>();
|
||||
@@ -78,7 +74,7 @@ inline Null<> gmtime_s(...)
|
||||
{
|
||||
return Null<>();
|
||||
}
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
// Thread-safe replacement for std::localtime
|
||||
inline std::tm localtime(std::time_t time)
|
||||
@@ -88,7 +84,10 @@ inline std::tm localtime(std::time_t time)
|
||||
std::time_t time_;
|
||||
std::tm tm_;
|
||||
|
||||
LocalTime(std::time_t t): time_(t) {}
|
||||
LocalTime(std::time_t t)
|
||||
: time_(t)
|
||||
{
|
||||
}
|
||||
|
||||
bool run()
|
||||
{
|
||||
@@ -116,7 +115,8 @@ inline std::tm localtime(std::time_t time)
|
||||
{
|
||||
using namespace fmt::internal;
|
||||
std::tm *tm = std::localtime(&time_);
|
||||
if (tm) tm_ = *tm;
|
||||
if (tm)
|
||||
tm_ = *tm;
|
||||
return tm != FMT_NULL;
|
||||
}
|
||||
};
|
||||
@@ -136,7 +136,10 @@ inline std::tm gmtime(std::time_t time)
|
||||
std::time_t time_;
|
||||
std::tm tm_;
|
||||
|
||||
GMTime(std::time_t t): time_(t) {}
|
||||
GMTime(std::time_t t)
|
||||
: time_(t)
|
||||
{
|
||||
}
|
||||
|
||||
bool run()
|
||||
{
|
||||
@@ -163,7 +166,8 @@ inline std::tm gmtime(std::time_t time)
|
||||
bool fallback(internal::Null<>)
|
||||
{
|
||||
std::tm *tm = std::gmtime(&time_);
|
||||
if (tm != FMT_NULL) tm_ = *tm;
|
||||
if (tm != FMT_NULL)
|
||||
tm_ = *tm;
|
||||
return tm != FMT_NULL;
|
||||
}
|
||||
};
|
||||
@@ -174,10 +178,10 @@ inline std::tm gmtime(std::time_t time)
|
||||
FMT_THROW(fmt::FormatError("time_t value out of range"));
|
||||
return std::tm();
|
||||
}
|
||||
} //namespace fmt
|
||||
} // namespace fmt
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // FMT_TIME_H_
|
||||
#endif // FMT_TIME_H_
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include "bundled/printf.h"
|
||||
#endif
|
||||
|
||||
#else //external fmtlib
|
||||
#else // external fmtlib
|
||||
|
||||
#include <fmt/format.h>
|
||||
#if defined(SPDLOG_FMT_PRINTF)
|
||||
@@ -31,4 +31,3 @@
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -8,10 +8,8 @@
|
||||
// include external or bundled copy of fmtlib's ostream support
|
||||
//
|
||||
#if !defined(SPDLOG_FMT_EXTERNAL)
|
||||
#include "fmt.h"
|
||||
#include "bundled/ostream.h"
|
||||
#include "fmt.h"
|
||||
#else
|
||||
#include <fmt/ostream.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user