16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 12:49:18 +02:00

Optimize substr_path implementation and change return type to sd::string

This commit is contained in:
docentYT
2026-05-07 12:59:57 +02:00
parent f4f4897798
commit 6542021253
2 changed files with 6 additions and 3 deletions

View File

@@ -392,9 +392,12 @@ void replace_slashes(std::string &Filename)
}
// returns potential path part from provided file name
std::string_view substr_path(std::string const &Filename)
std::string substr_path(std::string const &Filename)
{
return (Filename.rfind('/') != std::string::npos ? Filename.substr(0, Filename.rfind('/') + 1) : "");
// String::substr returns new string so substr_path has to return std::string
if (auto pos = Filename.rfind('/'); pos != std::string::npos)
return Filename.substr(0, pos + 1);
return {};
}
// returns length of common prefix between two provided strings