Remove redundant specifier

This commit is contained in:
Victor Zverovich 2023-12-28 07:27:33 -08:00
parent 76e8f10403
commit 47c8f63d02
2 changed files with 5 additions and 6 deletions

View File

@ -120,7 +120,7 @@ template <typename Char> struct formatter<std::filesystem::path, Char> {
format_specs<Char> specs_; format_specs<Char> specs_;
detail::arg_ref<Char> width_ref_; detail::arg_ref<Char> width_ref_;
bool debug_ = false; bool debug_ = false;
char path_type_ = 'n'; char path_type_ = 0;
public: public:
FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; } FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; }
@ -137,7 +137,7 @@ template <typename Char> struct formatter<std::filesystem::path, Char> {
debug_ = true; debug_ = true;
++it; ++it;
} }
if (it != end && (*it == 'g' || *it == 'n')) path_type_ = *it++; if (it != end && (*it == 'g')) path_type_ = *it++;
return it; return it;
} }
@ -145,9 +145,9 @@ 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_;
# ifdef _WIN32 # ifdef _WIN32
auto path_string = path_type_ == 'n' ? p.native() : p.generic_wstring(); auto path_string = !path_type_ ? p.native() : p.generic_wstring();
# else # else
auto path_string = path_type_ == 'n' ? p.native() : p.generic_string(); auto path_string = !path_type_ ? p.native() : p.generic_string();
# endif # endif
detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_, detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_,

View File

@ -26,10 +26,9 @@ 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"); EXPECT_EQ(fmt::format("{:g}", path("/usr/bin")), "/usr/bin");
# ifdef _WIN32 # ifdef _WIN32
EXPECT_EQ(fmt::format("{:n}", path("C:\\foo")), "C:\\foo"); EXPECT_EQ(fmt::format("{}", path("C:\\foo")), "C:\\foo");
EXPECT_EQ(fmt::format("{:g}", path("C:\\foo")), "C:/foo"); EXPECT_EQ(fmt::format("{:g}", path("C:\\foo")), "C:/foo");
EXPECT_EQ(fmt::format("{}", path(L"\x0428\x0447\x0443\x0447\x044B\x043D\x0448" EXPECT_EQ(fmt::format("{}", path(L"\x0428\x0447\x0443\x0447\x044B\x043D\x0448"