summaryrefslogtreecommitdiff
path: root/src/utils/cpp/path.hpp
blob: aa2c8350e3491422153f15d9c48b4f6cf0e9b162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef INCLUDED_SRC_UTILS_CPP_PATH_HPP
#define INCLUDED_SRC_UTILS_CPP_PATH_HPP

#include <filesystem>

[[nodiscard]] static inline auto ToNormalPath(std::filesystem::path const& p)
    -> std::filesystem::path {
    auto n = p.lexically_normal();
    if (not n.has_filename()) {
        n = n.parent_path();
    }
    if (n.empty()) {
        return std::filesystem::path{"."};
    }
    return n;
}

#endif