db/simple/Directory: GetName() returns std::string_view
This commit is contained in:
parent
ad854e9867
commit
851136e6fd
|
@ -53,20 +53,20 @@ Directory::Delete() noexcept
|
||||||
DeleteDisposer());
|
DeleteDisposer());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
std::string_view
|
||||||
Directory::GetName() const noexcept
|
Directory::GetName() const noexcept
|
||||||
{
|
{
|
||||||
assert(!IsRoot());
|
assert(!IsRoot());
|
||||||
|
|
||||||
if (parent->IsRoot())
|
if (parent->IsRoot())
|
||||||
return path.c_str();
|
return path;
|
||||||
|
|
||||||
assert(StringAfterPrefix(path.c_str(), parent->path.c_str()) != nullptr);
|
assert(path.starts_with(parent->path));
|
||||||
assert(*StringAfterPrefix(path.c_str(), parent->path.c_str()) == PathTraitsUTF8::SEPARATOR);
|
assert(path[parent->path.length()] == PathTraitsUTF8::SEPARATOR);
|
||||||
|
|
||||||
/* strip the parent directory path and the slash separator
|
/* strip the parent directory path and the slash separator
|
||||||
from this directory's path, and the base name remains */
|
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 *
|
Directory *
|
||||||
|
|
|
@ -208,7 +208,7 @@ public:
|
||||||
* Returns the base name of the directory.
|
* Returns the base name of the directory.
|
||||||
*/
|
*/
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
const char *GetName() const noexcept;
|
std::string_view GetName() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this the root directory of the music database?
|
* Is this the root directory of the music database?
|
||||||
|
|
Loading…
Reference in New Issue