From 9bbb53ffcd6eaee9f263c63cd135c5a3ef50928b Mon Sep 17 00:00:00 2001 From: Jin S Date: Sat, 25 Nov 2023 19:19:13 -0500 Subject: [PATCH] add generic and native of path --- include/fmt/std.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/fmt/std.h b/include/fmt/std.h index 4799df1a..82380546 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -78,7 +78,7 @@ #if FMT_CPP_LIB_FILESYSTEM FMT_BEGIN_NAMESPACE - + namespace detail { template auto get_path_string( @@ -114,6 +114,7 @@ template struct formatter { format_specs specs_; detail::arg_ref width_ref_; bool debug_ = false; + char path_type_ = 'n'; public: FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; } @@ -130,20 +131,25 @@ template struct formatter { debug_ = true; ++it; } + if (it != end && (*it == 'g' || *it == 'n')) { + path_type_ = *it++; + } return it; } template auto format(const std::filesystem::path& p, FormatContext& ctx) const { auto specs = specs_; + auto path_type = path_type_; + auto path_string = (path_type == 'n') ? p.native() : p.generic_string(); detail::handle_dynamic_spec(specs.width, width_ref_, ctx); if (!debug_) { - auto s = detail::get_path_string(p, p.native()); + auto s = detail::get_path_string(p, path_string); return detail::write(ctx.out(), basic_string_view(s), specs); } auto quoted = basic_memory_buffer(); - detail::write_escaped_path(quoted, p, p.native()); + detail::write_escaped_path(quoted, p, path_string); return detail::write(ctx.out(), basic_string_view(quoted.data(), quoted.size()), specs);