13 #ifndef __STOUT_PATH_HPP__
14 #define __STOUT_PATH_HPP__
41 inline std::string
from_uri(
const std::string& uri)
57 const std::string& path1,
58 const std::string& path2,
61 const std::string separator =
stringify(_separator);
68 template <
typename... Paths>
70 const std::string& path1,
71 const std::string& path2,
74 return join(path1,
join(path2, std::forward<Paths>(
paths)...));
78 inline std::string
join(
const std::vector<std::string>&
paths)
84 std::string result = paths[0];
85 for (
size_t i = 1; i < paths.size(); ++i) {
86 result =
join(result, paths[i]);
121 if (path.length() < 3) {
125 const char letter = path[0];
126 if (!((letter >=
'A' && letter <=
'Z') ||
127 (letter >=
'a' && letter <=
'z'))) {
131 std::string colon = path.substr(1, 2);
132 return colon ==
":\\" || colon ==
":/";
133 #endif // __WINDOWS__
150 explicit Path(
const std::string& path)
151 : value(strings::
remove(path,
"file://", strings::
PREFIX)) {}
182 return std::string(
".");
185 size_t end = value.size() - 1;
192 if (end == std::string::npos) {
201 if (start == std::string::npos) {
207 return value.substr(start, end + 1 - start);
241 return std::string(
".");
244 size_t end = value.size() - 1;
255 if (end == std::string::npos) {
256 return std::string(
".");
269 if (end == std::string::npos) {
273 return value.substr(0, end + 1);
296 size_t index = _basename.rfind(
'.');
298 if (_basename ==
"." || _basename ==
".." || index == std::string::npos) {
302 return _basename.substr(index);
312 operator std::string()
const
335 return !(left == right);
353 return !(left > right);
359 return !(left < right);
364 std::ostream& stream,
367 return stream << path.
string();
370 #endif // __STOUT_PATH_HPP__
Path(const std::string &path)
Definition: path.hpp:150
std::string paths()
Definition: os.hpp:136
std::string join(const std::string &path1, const std::string &path2, const char _separator=os::PATH_SEPARATOR)
Definition: path.hpp:56
Try< Nothing > start(const std::string &name)
Starts the slice with the given name (via 'systemctl start <name>').
bool absolute(const std::string &path)
Returns whether the given path is an absolute path.
Definition: path.hpp:96
std::string remove(const std::string &from, const std::string &substring, Mode mode=ANY)
Definition: strings.hpp:40
bool operator>=(const Path &left, const Path &right)
Definition: path.hpp:357
Try< Nothing > remove(const std::string &hierarchy, const std::string &cgroup)
Result< int > index(const std::string &link)
bool operator>(const Path &left, const Path &right)
Definition: path.hpp:345
Definition: strings.hpp:35
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:145
std::string from_uri(const std::string &uri)
Definition: path.hpp:41
std::string replace(const std::string &s, const std::string &from, const std::string &to)
Definition: strings.hpp:112
bool absolute() const
Definition: path.hpp:306
std::string dirname() const
Extracts the component up to, but not including, the final '/'.
Definition: path.hpp:238
Option< std::string > extension() const
Returns the file extension of the path, including the dot.
Definition: path.hpp:293
bool operator==(const Path &left, const Path &right)
Definition: path.hpp:327
std::ostream & operator<<(std::ostream &stream, const Call::Type &type)
Definition: agent.hpp:28
bool operator<=(const Path &left, const Path &right)
Definition: path.hpp:351
bool operator<(const Path &left, const Path &right)
Definition: path.hpp:339
std::string basename() const
Extracts the component following the final '/'.
Definition: path.hpp:179
std::string stringify(int flags)
bool startsWith(const std::string &s, const std::string &prefix)
Definition: strings.hpp:380
const std::string & string() const
Definition: path.hpp:317
Path()
Definition: path.hpp:148
bool operator!=(const Path &left, const Path &right)
Definition: path.hpp:333
constexpr char PATH_SEPARATOR
Definition: constants.hpp:24
Definition: strings.hpp:34