db/simple/Directory: GetName() returns std::string_view

This commit is contained in:
Max Kellermann 2023-09-06 14:28:11 +02:00
parent ad854e9867
commit 851136e6fd
2 changed files with 6 additions and 6 deletions

View File

@ -53,20 +53,20 @@ Directory::Delete() noexcept
DeleteDisposer());
}
const char *
std::string_view
Directory::GetName() const noexcept
{
assert(!IsRoot());
if (parent->IsRoot())
return path.c_str();
return path;
assert(StringAfterPrefix(path.c_str(), parent->path.c_str()) != nullptr);
assert(*StringAfterPrefix(path.c_str(), parent->path.c_str()) == PathTraitsUTF8::SEPARATOR);
assert(path.starts_with(parent->path));
assert(path[parent->path.length()] == PathTraitsUTF8::SEPARATOR);
/* strip the parent directory path and the slash separator
from this directory's path, and the base name remains */
return path.c_str() + parent->path.length() + 1;
return std::string_view{path}.substr(parent->path.length() + 1);
}
Directory *

View File

@ -208,7 +208,7 @@ public:
* Returns the base name of the directory.
*/
[[gnu::pure]]
const char *GetName() const noexcept;
std::string_view GetName() const noexcept;
/**
* Is this the root directory of the music database?