From 851136e6fdead1a75b939e8e174575582dc837fc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 6 Sep 2023 14:28:11 +0200 Subject: [PATCH] db/simple/Directory: GetName() returns std::string_view --- src/db/plugins/simple/Directory.cxx | 10 +++++----- src/db/plugins/simple/Directory.hxx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/db/plugins/simple/Directory.cxx b/src/db/plugins/simple/Directory.cxx index 7f58d1429..fd014f96c 100644 --- a/src/db/plugins/simple/Directory.cxx +++ b/src/db/plugins/simple/Directory.cxx @@ -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 * diff --git a/src/db/plugins/simple/Directory.hxx b/src/db/plugins/simple/Directory.hxx index 7500d194b..dacc9e064 100644 --- a/src/db/plugins/simple/Directory.hxx +++ b/src/db/plugins/simple/Directory.hxx @@ -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?