diff options
author | Victor Zverovich <viz@meta.com> | 2023-11-06 14:28:46 -1000 |
---|---|---|
committer | Victor Zverovich <viz@meta.com> | 2023-11-06 14:34:53 -1000 |
commit | 050d41e85760ea7d21de1d4d9fae16219365aa8e (patch) | |
tree | 940ab1ad461f2eaa61cf230a68558bf26f2bac7d | |
parent | 1c023c00876abdfd9d0149d73a152675dca72c34 (diff) | |
download | fmtlib-050d41e85760ea7d21de1d4d9fae16219365aa8e.tar.gz |
Make get_path_string more portable
-rw-r--r-- | include/fmt/std.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/include/fmt/std.h b/include/fmt/std.h index ff8b7fd3..4095a387 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -64,8 +64,12 @@ FMT_BEGIN_NAMESPACE namespace detail { -template <typename Char> auto get_path_string(const std::filesystem::path& p) { - return p.string<Char>(); +template <typename Char, typename PathChar> auto get_path_string( + const std::filesystem::path& p, const std::basic_string<PathChar>& native) { + if constexpr (std::is_same_v<Char, char> && std::is_same_v<PathChar, wchar_t>) + return to_utf8<wchar_t>(native, to_utf8_error_policy::replace); + else + return p.string<Char>(); } template <typename Char> @@ -75,10 +79,6 @@ void write_escaped_path(basic_memory_buffer<Char>& quoted, } # ifdef _WIN32 -template <> inline auto get_path_string<char>(const std::filesystem::path& p) { - return to_utf8<wchar_t>(p.native(), to_utf8_error_policy::replace); -} - template <> inline void write_escaped_path<char>(memory_buffer& quoted, const std::filesystem::path& p) { @@ -130,7 +130,7 @@ template <typename Char> struct formatter<std::filesystem::path, Char> { detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_, ctx); if (!debug_) { - auto s = detail::get_path_string<Char>(p); + auto s = detail::get_path_string<Char>(p, p.native()); return detail::write(ctx.out(), basic_string_view<Char>(s), specs); } auto quoted = basic_memory_buffer<Char>(); |