Skip to content

Commit

Permalink
Make get_path_string more portable
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Nov 7, 2023
1 parent 1c023c0 commit 050d41e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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) {
Expand Down Expand Up @@ -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>();
Expand Down

0 comments on commit 050d41e

Please sign in to comment.