Filesystem: added optional remove_extension parameter to base_name
This commit is contained in:
parent
b2fcc8d862
commit
04175cddc6
2 changed files with 12 additions and 3 deletions
|
@ -180,8 +180,11 @@ bool ends_with(const std::string& str, const std::string& suffix);
|
|||
/**
|
||||
* Returns the base filename of a file, with directory name stripped.
|
||||
* Equivalent to a portable basename() function.
|
||||
*
|
||||
* If @a remove_extension is true, the filename extension will be stripped
|
||||
* from the returned value.
|
||||
*/
|
||||
std::string base_name(const std::string& file);
|
||||
std::string base_name(const std::string& file, const bool remove_extension = false);
|
||||
|
||||
/**
|
||||
* Returns the directory name of a file, with filename stripped.
|
||||
|
|
|
@ -908,9 +908,15 @@ int dir_size(const std::string& pname)
|
|||
return size_sum;
|
||||
}
|
||||
|
||||
std::string base_name(const std::string& file)
|
||||
std::string base_name(const std::string& file, const bool remove_extension)
|
||||
{
|
||||
return path(file).filename().string();
|
||||
std::string res = path(file).filename().string();
|
||||
|
||||
if(remove_extension) {
|
||||
return res.substr(0, res.rfind("."));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string directory_name(const std::string& file)
|
||||
|
|
Loading…
Add table
Reference in a new issue