From: Joel Rosdahl Date: Sat, 16 Aug 2025 19:06:39 +0000 (+0200) Subject: enhance: Implement util::to_string(const fs::path&) X-Git-Tag: v4.12~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=daa18e53d4dc0347d3cdc820761e97dff2415e2f;p=thirdparty%2Fccache.git enhance: Implement util::to_string(const fs::path&) --- diff --git a/src/ccache/util/conversion.hpp b/src/ccache/util/conversion.hpp index 276f36e8..7258df92 100644 --- a/src/ccache/util/conversion.hpp +++ b/src/ccache/util/conversion.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2023-2024 Joel Rosdahl and other contributors +// Copyright (C) 2023-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -156,6 +157,13 @@ to_string(const Bytes& bytes) return std::string(to_string_view(bytes)); } +template<> +inline std::string +to_string(const std::filesystem::path& path) +{ + return path.string(); +} + inline std::string_view to_string_view(nonstd::span data) { diff --git a/unittest/test_util_conversion.cpp b/unittest/test_util_conversion.cpp index 335ac158..2ca1d1bb 100644 --- a/unittest/test_util_conversion.cpp +++ b/unittest/test_util_conversion.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2024 Joel Rosdahl and other contributors +// Copyright (C) 2021-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -17,12 +17,15 @@ // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include +#include #include #include // https://github.com/doctest/doctest/issues/618 #include +namespace fs = util::filesystem; + TEST_SUITE_BEGIN("util"); TEST_CASE("util::big_endian_to_int") @@ -131,6 +134,7 @@ TEST_CASE("util::to_string") CHECK(util::to_string(nonstd::span(bytes)) == std::string(str)); CHECK(util::to_string(util::Bytes(bytes, 3)) == std::string(str)); + CHECK(util::to_string(fs::path("foo/bar")) == std::string("foo/bar")); } TEST_CASE("util::to_string_view")