mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 10:29:02 +08:00
clang format
This commit is contained in:
@@ -9,13 +9,13 @@
|
||||
#include <spdlog/common.h>
|
||||
|
||||
#if defined(__has_include)
|
||||
# if __has_include(<version>)
|
||||
# include <version>
|
||||
# endif
|
||||
#if __has_include(<version>)
|
||||
#include <version>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __cpp_lib_span >= 202002L
|
||||
# include <span>
|
||||
#include <span>
|
||||
#endif
|
||||
|
||||
//
|
||||
@@ -39,29 +39,18 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
template<typename It>
|
||||
class dump_info
|
||||
{
|
||||
template <typename It>
|
||||
class dump_info {
|
||||
public:
|
||||
dump_info(It range_begin, It range_end, size_t size_per_line)
|
||||
: begin_(range_begin)
|
||||
, end_(range_end)
|
||||
, size_per_line_(size_per_line)
|
||||
{}
|
||||
: begin_(range_begin),
|
||||
end_(range_end),
|
||||
size_per_line_(size_per_line) {}
|
||||
|
||||
// do not use begin() and end() to avoid collision with fmt/ranges
|
||||
It get_begin() const
|
||||
{
|
||||
return begin_;
|
||||
}
|
||||
It get_end() const
|
||||
{
|
||||
return end_;
|
||||
}
|
||||
size_t size_per_line() const
|
||||
{
|
||||
return size_per_line_;
|
||||
}
|
||||
It get_begin() const { return begin_; }
|
||||
It get_end() const { return end_; }
|
||||
size_t size_per_line() const { return size_per_line_; }
|
||||
|
||||
private:
|
||||
It begin_, end_;
|
||||
@@ -70,9 +59,9 @@ private:
|
||||
} // namespace details
|
||||
|
||||
// create a dump_info that wraps the given container
|
||||
template<typename Container>
|
||||
inline details::dump_info<typename Container::const_iterator> to_hex(const Container &container, size_t size_per_line = 32)
|
||||
{
|
||||
template <typename Container>
|
||||
inline details::dump_info<typename Container::const_iterator> to_hex(const Container &container,
|
||||
size_t size_per_line = 32) {
|
||||
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
|
||||
using Iter = typename Container::const_iterator;
|
||||
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
|
||||
@@ -80,10 +69,9 @@ inline details::dump_info<typename Container::const_iterator> to_hex(const Conta
|
||||
|
||||
#if __cpp_lib_span >= 202002L
|
||||
|
||||
template<typename Value, size_t Extent>
|
||||
inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(
|
||||
const std::span<Value, Extent> &container, size_t size_per_line = 32)
|
||||
{
|
||||
template <typename Value, size_t Extent>
|
||||
inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(const std::span<Value, Extent> &container,
|
||||
size_t size_per_line = 32) {
|
||||
using Container = std::span<Value, Extent>;
|
||||
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
|
||||
using Iter = typename Container::iterator;
|
||||
@@ -93,9 +81,8 @@ inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(
|
||||
#endif
|
||||
|
||||
// create dump_info from ranges
|
||||
template<typename It>
|
||||
inline details::dump_info<It> to_hex(const It range_begin, const It range_end, size_t size_per_line = 32)
|
||||
{
|
||||
template <typename It>
|
||||
inline details::dump_info<It> to_hex(const It range_begin, const It range_end, size_t size_per_line = 32) {
|
||||
return details::dump_info<It>(range_begin, range_end, size_per_line);
|
||||
}
|
||||
|
||||
@@ -109,9 +96,8 @@ namespace
|
||||
#endif
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct formatter<spdlog::details::dump_info<T>, char>
|
||||
{
|
||||
template <typename T>
|
||||
struct formatter<spdlog::details::dump_info<T>, char> {
|
||||
const char delimiter = ' ';
|
||||
bool put_newlines = true;
|
||||
bool put_delimiters = true;
|
||||
@@ -120,14 +106,11 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
bool show_ascii = false;
|
||||
|
||||
// parse the format string flags
|
||||
template<typename ParseContext>
|
||||
SPDLOG_CONSTEXPR_FUNC auto parse(ParseContext &ctx) -> decltype(ctx.begin())
|
||||
{
|
||||
template <typename ParseContext>
|
||||
SPDLOG_CONSTEXPR_FUNC auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
|
||||
auto it = ctx.begin();
|
||||
while (it != ctx.end() && *it != '}')
|
||||
{
|
||||
switch (*it)
|
||||
{
|
||||
while (it != ctx.end() && *it != '}') {
|
||||
switch (*it) {
|
||||
case 'X':
|
||||
use_uppercase = true;
|
||||
break;
|
||||
@@ -142,8 +125,7 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
show_ascii = false;
|
||||
break;
|
||||
case 'a':
|
||||
if (put_newlines)
|
||||
{
|
||||
if (put_newlines) {
|
||||
show_ascii = true;
|
||||
}
|
||||
break;
|
||||
@@ -155,9 +137,9 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
}
|
||||
|
||||
// format the given bytes range as hex
|
||||
template<typename FormatContext, typename Container>
|
||||
auto format(const spdlog::details::dump_info<Container> &the_range, FormatContext &ctx) const -> decltype(ctx.out())
|
||||
{
|
||||
template <typename FormatContext, typename Container>
|
||||
auto format(const spdlog::details::dump_info<Container> &the_range, FormatContext &ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
SPDLOG_CONSTEXPR const char *hex_upper = "0123456789ABCDEF";
|
||||
SPDLOG_CONSTEXPR const char *hex_lower = "0123456789abcdef";
|
||||
const char *hex_chars = use_uppercase ? hex_upper : hex_lower;
|
||||
@@ -170,18 +152,14 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
|
||||
int size_per_line = static_cast<int>(the_range.size_per_line());
|
||||
auto start_of_line = the_range.get_begin();
|
||||
for (auto i = the_range.get_begin(); i != the_range.get_end(); i++)
|
||||
{
|
||||
for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) {
|
||||
auto ch = static_cast<unsigned char>(*i);
|
||||
|
||||
if (put_newlines && (i == the_range.get_begin() || i - start_of_line >= size_per_line))
|
||||
{
|
||||
if (show_ascii && i != the_range.get_begin())
|
||||
{
|
||||
if (put_newlines && (i == the_range.get_begin() || i - start_of_line >= size_per_line)) {
|
||||
if (show_ascii && i != the_range.get_begin()) {
|
||||
*inserter++ = delimiter;
|
||||
*inserter++ = delimiter;
|
||||
for (auto j = start_of_line; j < i; j++)
|
||||
{
|
||||
for (auto j = start_of_line; j < i; j++) {
|
||||
auto pc = static_cast<unsigned char>(*j);
|
||||
*inserter++ = std::isprint(pc) ? static_cast<char>(*j) : '.';
|
||||
}
|
||||
@@ -196,8 +174,7 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
continue;
|
||||
}
|
||||
|
||||
if (put_delimiters && i != the_range.get_begin())
|
||||
{
|
||||
if (put_delimiters && i != the_range.get_begin()) {
|
||||
*inserter++ = delimiter;
|
||||
}
|
||||
|
||||
@@ -206,23 +183,19 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
}
|
||||
if (show_ascii) // add ascii to last line
|
||||
{
|
||||
if (the_range.get_end() - the_range.get_begin() > size_per_line)
|
||||
{
|
||||
if (the_range.get_end() - the_range.get_begin() > size_per_line) {
|
||||
auto blank_num = size_per_line - (the_range.get_end() - start_of_line);
|
||||
while (blank_num-- > 0)
|
||||
{
|
||||
while (blank_num-- > 0) {
|
||||
*inserter++ = delimiter;
|
||||
*inserter++ = delimiter;
|
||||
if (put_delimiters)
|
||||
{
|
||||
if (put_delimiters) {
|
||||
*inserter++ = delimiter;
|
||||
}
|
||||
}
|
||||
}
|
||||
*inserter++ = delimiter;
|
||||
*inserter++ = delimiter;
|
||||
for (auto j = start_of_line; j != the_range.get_end(); j++)
|
||||
{
|
||||
for (auto j = start_of_line; j != the_range.get_end(); j++) {
|
||||
auto pc = static_cast<unsigned char>(*j);
|
||||
*inserter++ = std::isprint(pc) ? static_cast<char>(*j) : '.';
|
||||
}
|
||||
@@ -231,16 +204,14 @@ struct formatter<spdlog::details::dump_info<T>, char>
|
||||
}
|
||||
|
||||
// put newline(and position header)
|
||||
template<typename It>
|
||||
void put_newline(It inserter, std::size_t pos) const
|
||||
{
|
||||
template <typename It>
|
||||
void put_newline(It inserter, std::size_t pos) const {
|
||||
#ifdef _WIN32
|
||||
*inserter++ = '\r';
|
||||
#endif
|
||||
*inserter++ = '\n';
|
||||
|
||||
if (put_positions)
|
||||
{
|
||||
if (put_positions) {
|
||||
spdlog::fmt_lib::format_to(inserter, SPDLOG_FMT_STRING("{:04X}: "), pos);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user