diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 3d2007bb..9b4f9d4e 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -444,14 +444,14 @@ template < FMT_ENABLE_IF(is_same_arithmetic_type::value)> To fmt_duration_cast(std::chrono::duration from) { #if FMT_SAFE_DURATION_CAST - // throwing version of safe_duration_cast - // only available for integer<->integer or float<->float casts + // Throwing version of safe_duration_cast is only available for + // integer to integer or float to float casts. int ec; To to = safe_duration_cast::safe_duration_cast(from, ec); if (ec) FMT_THROW(format_error("cannot format duration")); return to; #else - // standard duration cast, may overflow and invoke undefined behavior + // Standard duration cast, may overflow. return std::chrono::duration_cast(from); #endif } @@ -460,15 +460,14 @@ template < typename To, typename FromRep, typename FromPeriod, FMT_ENABLE_IF(!is_same_arithmetic_type::value)> To fmt_duration_cast(std::chrono::duration from) { - // mixed integer<->float cast is not supported with safe_duration_cast - // fallback to standard duration cast in this case + // Mixed integer <-> float cast is not supported by safe_duration_cast. return std::chrono::duration_cast(from); } template std::time_t to_time_t( std::chrono::time_point time_point) { - // cannot use std::chrono::system_clock::to_time_t() since this would first + // Cannot use std::chrono::system_clock::to_time_t since this would first // require a cast to std::chrono::system_clock::time_point, which could // overflow. return fmt_duration_cast>( diff --git a/include/fmt/std.h b/include/fmt/std.h index 7b92cea5..61fe0cac 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -65,7 +65,7 @@ # define FMT_CPP_LIB_FILESYSTEM __cpp_lib_filesystem # else # define FMT_CPP_LIB_FILESYSTEM 0 -# endif +# endif #endif #ifndef FMT_CPP_LIB_VARIANT @@ -81,8 +81,9 @@ FMT_BEGIN_NAMESPACE namespace detail { -template auto get_path_string( - const std::filesystem::path& p, const std::basic_string& native) { +template +auto get_path_string(const std::filesystem::path& p, + const std::basic_string& native) { if constexpr (std::is_same_v && std::is_same_v) return to_utf8(native, to_utf8_error_policy::replace); else @@ -93,7 +94,8 @@ template void write_escaped_path(basic_memory_buffer& quoted, const std::filesystem::path& p, const std::basic_string& native) { - if constexpr (std::is_same_v && std::is_same_v) { + if constexpr (std::is_same_v && + std::is_same_v) { auto buf = basic_memory_buffer(); write_escaped_string(std::back_inserter(buf), native); bool valid = to_utf8::convert(quoted, {buf.data(), buf.size()}); @@ -131,21 +133,19 @@ template struct formatter { debug_ = true; ++it; } - if (it != end && (*it == 'g' || *it == 'n')) { + 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_; - # 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(); - # endif +# 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(); +# endif detail::handle_dynamic_spec(specs.width, width_ref_, ctx); @@ -161,7 +161,7 @@ template struct formatter { } }; FMT_END_NAMESPACE -#endif // FMT_CPP_LIB_FILESYSTEM +#endif // FMT_CPP_LIB_FILESYSTEM FMT_BEGIN_NAMESPACE FMT_EXPORT diff --git a/test/std-test.cc b/test/std-test.cc index 7a81aaf9..55a48810 100644 --- a/test/std-test.cc +++ b/test/std-test.cc @@ -25,20 +25,19 @@ 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("{:n}", 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("{:g}", path("C:\\foo")), "C:/foo"); - EXPECT_EQ(fmt::format("{}", path( - L"\x0428\x0447\x0443\x0447\x044B\x043D\x0448" - L"\x0447\x044B\x043D\x0430")), + EXPECT_EQ(fmt::format("{}", path(L"\x0428\x0447\x0443\x0447\x044B\x043D\x0448" + L"\x0447\x044B\x043D\x0430")), "Шчучыншчына"); EXPECT_EQ(fmt::format("{}", path(L"\xd800")), "�"); EXPECT_EQ(fmt::format("{:?}", path(L"\xd800")), "\"\\ud800\""); -# endif +# endif } // Test ambiguity problem described in #2954. @@ -290,10 +289,10 @@ TEST(std_test, format_atomic) { #ifdef __cpp_lib_atomic_flag_test TEST(std_test, format_atomic_flag) { std::atomic_flag f = ATOMIC_FLAG_INIT; - (void) f.test_and_set(); + (void)f.test_and_set(); EXPECT_EQ(fmt::format("{}", f), "true"); const std::atomic_flag cf = ATOMIC_FLAG_INIT; EXPECT_EQ(fmt::format("{}", cf), "false"); } -#endif // __cpp_lib_atomic_flag_test +#endif // __cpp_lib_atomic_flag_test