add utils::path_dirname() to complement utils::path_basename()
This commit is contained in:
@ -772,6 +772,22 @@ std::string utils::path_basename(const std::string &path) {
|
||||
return path.substr(start);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Return only the leading part of a path, return just the directory
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::path_dirname(const std::string &path) {
|
||||
#if defined(_WIN32)
|
||||
size_t start = path.find_last_of("/\\");
|
||||
#else
|
||||
size_t start = path.find_last_of("/");
|
||||
#endif
|
||||
|
||||
if (start == std::string::npos) return ".";
|
||||
|
||||
return path.substr(0,start);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
join two paths
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user