mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-31 00:32:40 +00:00
Make get_path_string more portable
This commit is contained in:
parent
1c023c0087
commit
050d41e857
@ -64,7 +64,11 @@ FMT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template <typename Char> auto get_path_string(const std::filesystem::path& p) {
|
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>();
|
return p.string<Char>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +79,6 @@ void write_escaped_path(basic_memory_buffer<Char>& quoted,
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ifdef _WIN32
|
# 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 <>
|
template <>
|
||||||
inline void write_escaped_path<char>(memory_buffer& quoted,
|
inline void write_escaped_path<char>(memory_buffer& quoted,
|
||||||
const std::filesystem::path& p) {
|
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_,
|
detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_,
|
||||||
ctx);
|
ctx);
|
||||||
if (!debug_) {
|
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);
|
return detail::write(ctx.out(), basic_string_view<Char>(s), specs);
|
||||||
}
|
}
|
||||||
auto quoted = basic_memory_buffer<Char>();
|
auto quoted = basic_memory_buffer<Char>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user