add generic and native path format spec
This commit is contained in:
parent
4b4f314527
commit
e5dd88b0e9
@ -141,7 +141,12 @@ template <typename Char> struct formatter<std::filesystem::path, Char> {
|
|||||||
auto format(const std::filesystem::path& p, FormatContext& ctx) const {
|
auto format(const std::filesystem::path& p, FormatContext& ctx) const {
|
||||||
auto specs = specs_;
|
auto specs = specs_;
|
||||||
auto path_type = path_type_;
|
auto path_type = path_type_;
|
||||||
|
# ifdef _WIN32
|
||||||
|
auto path_string = (path_type == 'n') ? p.native() : p.generic_wstring();
|
||||||
|
# else
|
||||||
auto path_string = (path_type == 'n') ? p.native() : p.generic_string();
|
auto path_string = (path_type == 'n') ? p.native() : p.generic_string();
|
||||||
|
# endif
|
||||||
|
|
||||||
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_) {
|
||||||
|
|||||||
@ -25,15 +25,20 @@ TEST(std_test, path) {
|
|||||||
|
|
||||||
EXPECT_EQ(fmt::format("{}", path("foo\"bar")), "foo\"bar");
|
EXPECT_EQ(fmt::format("{}", path("foo\"bar")), "foo\"bar");
|
||||||
EXPECT_EQ(fmt::format("{:?}", path("foo\"bar")), "\"foo\\\"bar\"");
|
EXPECT_EQ(fmt::format("{:?}", path("foo\"bar")), "\"foo\\\"bar\"");
|
||||||
|
|
||||||
|
EXPECT_EQ(fmt::format("{:n}", path("/usr/bin")), "/usr/bin");
|
||||||
|
EXPECT_EQ(fmt::format("{:g}", path("/usr/bin")), "/usr/bin");
|
||||||
|
# ifdef _WIN32
|
||||||
|
EXPECT_EQ(fmt::format("{:n}", path("C:\\foo")), "C:\\foo");
|
||||||
|
EXPECT_EQ(fmt::format("{:g}", path("C:\\foo")), "C:/foo");
|
||||||
|
|
||||||
# ifdef _WIN32
|
|
||||||
EXPECT_EQ(fmt::format("{}", path(
|
EXPECT_EQ(fmt::format("{}", path(
|
||||||
L"\x0428\x0447\x0443\x0447\x044B\x043D\x0448"
|
L"\x0428\x0447\x0443\x0447\x044B\x043D\x0448"
|
||||||
L"\x0447\x044B\x043D\x0430")),
|
L"\x0447\x044B\x043D\x0430")),
|
||||||
"Шчучыншчына");
|
"Шчучыншчына");
|
||||||
EXPECT_EQ(fmt::format("{}", path(L"\xd800")), "<EFBFBD>");
|
EXPECT_EQ(fmt::format("{}", path(L"\xd800")), "<EFBFBD>");
|
||||||
EXPECT_EQ(fmt::format("{:?}", path(L"\xd800")), "\"\\ud800\"");
|
EXPECT_EQ(fmt::format("{:?}", path(L"\xd800")), "\"\\ud800\"");
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test ambiguity problem described in #2954.
|
// Test ambiguity problem described in #2954.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user