Skip to content

Commit

Permalink
Change os::getFilename to return the input string when there's no sla…
Browse files Browse the repository at this point in the history
…sh to be found
  • Loading branch information
codereader committed Jan 6, 2020
1 parent a907dea commit a34bcc7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions libs/os/path.h
Expand Up @@ -146,17 +146,15 @@ namespace os
/**
* greebo: Get the filename contained in the given path (the part after the last slash).
* If there is no filename, an empty string is returned.
* If there's no slash, the input string is returned as is.
*
* Note: The input string is expected to be standardised (forward slashes).
*/
inline std::string getFilename(const std::string& path) {
inline std::string getFilename(const std::string& path)
{
std::size_t slashPos = path.rfind('/');
if (slashPos == std::string::npos) {
return "";
}
else {
return path.substr(slashPos + 1);
}

return slashPos == std::string::npos ? path : path.substr(slashPos + 1);
}

/**
Expand Down

0 comments on commit a34bcc7

Please sign in to comment.