25 #ifndef COMMON_UTILS_PATHS_HPP
26 #define COMMON_UTILS_PATHS_HPP
38 std::vector<std::string> pathVec = {paths...};
39 std::string retPath =
"";
41 if (pathVec.empty()) {
45 for (std::string& p : pathVec) {
47 if (retPath.empty() || p.empty()) {
53 if (retPath.back() !=
'/' && p.front() !=
'/' && p.front() !=
'.') {
59 if (retPath.back() ==
'/' && p.front() ==
'/') {
60 retPath += p.substr(1);
72 inline void removeDuplicateSlashes(std::string& path)
74 auto it = std::unique(path.begin(), path.end(),
76 return (a ==
'/' && a == b);
78 path.erase(it, path.end());
81 inline void removeTrailingSlash(std::string& path)
83 size_t size = path.size();
85 if (size > 1 && path[size - 1] ==
'/') {
86 path.resize(size - 1);
95 inline std::string
dirName(std::string path)
97 removeDuplicateSlashes(path);
98 removeTrailingSlash(path);
99 path.erase(std::find(path.rbegin(), path.rend(),
'/').base(), path.end());
100 removeTrailingSlash(path);
114 if (path[0] ==
'/') {
124 #endif // COMMON_UTILS_PATHS_HPP
std::string createFilePath(const Paths &...paths)
Definition: paths.hpp:36
std::string dirName(std::string path)
Definition: paths.hpp:95
std::string getAbsolutePath(const std::string &path, const std::string &base)
Definition: paths.hpp:112