From e9d42e059f4381ce9402191293378adc5bdf2d2c Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 25 Oct 2019 12:52:39 +0300 Subject: [PATCH] // support forward slash in windows --- include/spdlog/details/os-inl.h | 18 +++++++----------- include/spdlog/details/os.h | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index b237adeb..590e35a1 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -488,14 +488,13 @@ SPDLOG_INLINE bool create_dir(filename_t path) using char_type = filename_t::value_type; std::basic_istringstream istream(path); filename_t token; - filename_t cur_dir; - char_type sep = '/'; + filename_t cur_dir; #ifdef _WIN32 // support forward slash in windows - std::replace(path.begin(), path.end(), char_type('\\'), sep); + std::replace(path.begin(), path.end(), '/', folder_sep); #endif - while (std::getline(istream, token, sep)) + while (std::getline(istream, token, folder_sep)) { if (!token.empty()) { @@ -505,7 +504,7 @@ SPDLOG_INLINE bool create_dir(filename_t path) return false; } } - cur_dir += sep; + cur_dir += folder_sep; } return true; @@ -517,15 +516,12 @@ SPDLOG_INLINE bool create_dir(filename_t path) // "abc" => "" // "abc///" => "abc//" SPDLOG_INLINE filename_t dir_name(filename_t path) -{ - using char_type = filename_t::value_type; - char_type sep = '/'; - +{ #ifdef _WIN32 // support forward slash in windows - std::replace(path.begin(), path.end(), char_type('\\'), sep); + std::replace(path.begin(), path.end(), '/', folder_sep); #endif - auto pos = path.find_last_of(sep); + auto pos = path.find_last_of(folder_sep); return pos != filename_t::npos ? path.substr(0, pos) : filename_t{}; } diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 352b063f..2ab828ba 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -33,7 +33,7 @@ SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL; // folder separator #ifdef _WIN32 -const char folder_sep = '\\'; +static const char folder_sep = '\\'; #else SPDLOG_CONSTEXPR static const char folder_sep = '/'; #endif