7 #include "../logging.h"
12 inline std::filesystem::path
common_prefix(
const std::filesystem::path& p1,
const std::filesystem::path& p2) {
13 std::filesystem::path
result;
15 auto it1 = p1.begin(), it2 = p2.begin();
16 it1 != p1.end() && it2 != p2.end();
19 if (*it1 != *it2)
break;
29 inline std::filesystem::path
common_prefix(
const std::vector<std::filesystem::path>& s,
bool skip_last =
true) {
30 if (s.empty())
return std::filesystem::path();
33 cur = cur.parent_path();
35 for (std::size_t i = 1; i < s.size(); i++) {
45 inline std::filesystem::path
common_prefix(
const std::initializer_list<std::vector<std::filesystem::path>>& s,
bool skip_last =
true) {
46 std::vector<std::filesystem::path> all;
47 for (
const auto& sv: s) {
48 all.insert(all.end(), sv.begin(), sv.end());
54 inline std::filesystem::path
remove_prefix(
const std::filesystem::path& s,
const std::filesystem::path&
prefix) {
55 return std::filesystem::relative(s,
prefix);
60 inline bool is_extension(
const std::filesystem::path& path,
const std::string& extension) {
61 if (!std::filesystem::is_regular_file(path))
return false;
62 return path.extension() == extension;
std::filesystem::path remove_prefix(const std::filesystem::path &s, const std::filesystem::path &prefix)
Remove a prefix from a path.
std::filesystem::path common_prefix(const std::filesystem::path &p1, const std::filesystem::path &p2)
Computes the common prefix of two paths.
bool is_extension(const std::filesystem::path &path, const std::string &extension)
Checks whether the extension of the filename is as specified.
std::vector< T > prefix(const std::vector< T > vars, std::size_t prefixSize)