Add helper functions to get last path segment

This commit is contained in:
Jonathan G Rennison
2024-01-05 22:13:17 +00:00
parent 7fdcbced09
commit 0ab4b8ea31
5 changed files with 22 additions and 15 deletions

View File

@@ -420,6 +420,17 @@ void StrTrimInPlace(std::string &str)
StrRightTrimInPlace(str);
}
const char *StrLastPathSegment(const char *path)
{
const char *best = path;
for (; *path != '\0'; path++) {
if (*path == PATHSEPCHAR || *path == '/') {
if (*(path + 1) != '\0') best = path + 1;
}
}
return best;
}
/**
* Check whether the given string starts with the given prefix.
* @param str The string to look at.