14#ifndef OPENVPN_COMMON_PATH_H
15#define OPENVPN_COMMON_PATH_H
29#if defined(OPENVPN_PLATFORM_WIN) || defined(OPENVPN_PATH_SIMULATE_WINDOWS)
31const char dirsep[] =
"\\/";
34const char dirsep[] =
"/\\";
41 for (
const char *p = dirsep; *p !=
'\0'; ++p)
47inline bool win_dev(
const std::string &path,
const bool fully_qualified)
49#if defined(OPENVPN_PLATFORM_WIN) || defined(OPENVPN_PATH_SIMULATE_WINDOWS)
51 return path.length() >= 3
52 && ((path[0] >=
'a' && path[0] <=
'z') || (path[0] >=
'A' && path[0] <=
'Z'))
54 && (!fully_qualified ||
is_dirsep(path[2]));
67inline bool is_flat(
const std::string &path)
69 return path.length() > 0
72 && path.find_first_of(dirsep) == std::string::npos
76inline std::string
basename(
const std::string &path)
78 const size_t pos = path.find_last_of(dirsep);
79 if (pos != std::string::npos)
81 const size_t p = pos + 1;
82 if (p >= path.length())
85 return path.substr(p);
91inline std::string
dirname(
const std::string &path)
93 const size_t pos = path.find_last_of(dirsep);
94 if (pos != std::string::npos)
99 return path.substr(0, pos);
124 for (
const auto c : path)
153 return state != POST_DOT_2;
158 const size_t pos =
basename.find_last_of(
'.');
159 if (pos != std::string::npos)
161 const size_t p = pos + 1;
173 const size_t pos =
basename.find_last_of(
'.');
174 if (pos != std::string::npos)
180inline std::string
join(
const std::string &p1,
const std::string &p2)
188template <
typename... Args>
189inline std::string
join(
const std::string &p1,
const std::string &p2, Args... args)
std::string ext(const std::string &basename)
bool is_contained(const std::string &path)
std::string dirname(const std::string &path)
std::string root(const std::string &basename)
bool win_dev(const std::string &path, const bool fully_qualified)
std::string basename(const std::string &path)
std::string join(const std::string &p1, const std::string &p2)
bool is_fully_qualified(const std::string &path)
bool is_dirsep(const char c)
bool is_flat(const std::string &path)
std::string add_trailing_copy(const std::string &str, const char c)