mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-01 02:49:03 +08:00
Better support for / separators on Windows, improve wchar filename coverage
This commit is contained in:
@@ -13,11 +13,13 @@
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <spdlog/formatter.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@@ -814,11 +816,31 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4127) // consider using 'if constexpr' instead
|
||||
#endif // _MSC_VER
|
||||
static const char *basename(const char *filename)
|
||||
{
|
||||
const char *rv = std::strrchr(filename, os::folder_sep);
|
||||
return rv != nullptr ? rv + 1 : filename;
|
||||
// if the size is 2 (1 character + null terminator) we can use the more efficient strrchr
|
||||
// the branch will be elided by optimizations
|
||||
if (sizeof(os::folder_seps) == 2)
|
||||
{
|
||||
const char *rv = std::strrchr(filename, os::folder_seps[0]);
|
||||
return rv != nullptr ? rv + 1 : filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::reverse_iterator<const char*> begin(filename + std::strlen(filename));
|
||||
const std::reverse_iterator<const char*> end(filename);
|
||||
|
||||
const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), std::end(os::folder_seps) - 1);
|
||||
return it != end ? it.base() : filename;
|
||||
}
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif // _MSC_VER
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
|
Reference in New Issue
Block a user