1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-04-01 02:42:41 +08:00

Refactored padding handling in formatter using templates

This commit is contained in:
gabime 2019-07-15 01:17:22 +03:00
parent 54456aee9e
commit 4b0267910c
2 changed files with 11 additions and 17 deletions

View File

@ -85,8 +85,7 @@ private:
struct null_scoped_padder struct null_scoped_padder
{ {
null_scoped_padder(size_t /*wrapped_size*/, const padding_info &/*padinfo*/, fmt::memory_buffer &/*dest*/) null_scoped_padder(size_t /*wrapped_size*/, const padding_info & /*padinfo*/, fmt::memory_buffer & /*dest*/) {}
{}
}; };
template<typename ScopedPadder> template<typename ScopedPadder>
@ -434,7 +433,6 @@ public:
const size_t field_size = 3; const size_t field_size = 3;
ScopedPadder p(field_size, padinfo_, dest); ScopedPadder p(field_size, padinfo_, dest);
fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest); fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest);
} }
}; };
@ -454,7 +452,6 @@ public:
const size_t field_size = 6; const size_t field_size = 6;
ScopedPadder p(field_size, padinfo_, dest); ScopedPadder p(field_size, padinfo_, dest);
fmt_helper::pad6(static_cast<size_t>(micros.count()), dest); fmt_helper::pad6(static_cast<size_t>(micros.count()), dest);
} }
}; };
@ -766,9 +763,8 @@ public:
return; return;
} }
size_t text_size = padinfo_.enabled() ? size_t text_size =
std::char_traits<char>::length(msg.source.filename) + fmt_helper::count_digits(msg.source.line) + 1: padinfo_.enabled() ? std::char_traits<char>::length(msg.source.filename) + fmt_helper::count_digits(msg.source.line) + 1 : 0;
0;
ScopedPadder p(text_size, padinfo_, dest); ScopedPadder p(text_size, padinfo_, dest);
fmt_helper::append_string_view(msg.source.filename, dest); fmt_helper::append_string_view(msg.source.filename, dest);
@ -1043,7 +1039,6 @@ SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg)
return details::os::gmtime(log_clock::to_time_t(msg.time)); return details::os::gmtime(log_clock::to_time_t(msg.time));
} }
template<typename Padder> template<typename Padder>
SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding) SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding)
{ {
@ -1299,7 +1294,6 @@ SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &patter
{ {
handle_flag_<details::null_scoped_padder>(*it, padding); handle_flag_<details::null_scoped_padder>(*it, padding);
} }
} }
else else
{ {