]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
enhance: Implement util::to_string(const fs::path&)
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Aug 2025 19:06:39 +0000 (21:06 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Aug 2025 19:10:28 +0000 (21:10 +0200)
src/ccache/util/conversion.hpp
unittest/test_util_conversion.cpp

index 276f36e8083caaa1bacaebbb74e11305c98142b4..7258df925583ad48c915d3702ab2d2c46ca0f10c 100644 (file)
@@ -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 <nonstd/span.hpp>
 
 #include <cstdint>
+#include <filesystem>
 #include <string>
 #include <string_view>
 
@@ -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<const uint8_t> data)
 {
index 335ac158a3a3d891e049c7abcd26de6fdef5f9f8..2ca1d1bbe4e280c6e4c9af6cfbb6cc5fc3a4b82b 100644 (file)
@@ -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.
 //
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 #include <ccache/util/conversion.hpp>
+#include <ccache/util/filesystem.hpp>
 
 #include <doctest/doctest.h>
 
 #include <ostream> // https://github.com/doctest/doctest/issues/618
 #include <vector>
 
+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<const uint8_t>(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")