// std::filesystem::path::value_type is char (that is, not wchar_t).
using pstr = PathString;
+// Return a new path with `extension` added to `path` (removing any existing
+// extension).
+std::filesystem::path with_extension(const std::filesystem::path& path,
+ std::string_view extension);
+
// --- Inline implementations ---
inline std::filesystem::path
return path.find('/') != std::string_view::npos;
}
+inline std::filesystem::path
+with_extension(const std::filesystem::path& path, std::string_view extension)
+{
+ std::filesystem::path result(path);
+ result.replace_extension(extension);
+ return result;
+}
+
} // namespace util
CHECK(!util::path_starts_with("C:\\beh\\foo", "C:/foo"));
#endif
}
+
+TEST_CASE("util::with_extension")
+{
+ CHECK(util::with_extension("foo.x", "") == "foo");
+ CHECK(util::with_extension("foo.x", ".y") == "foo.y");
+}