From 60ca12e4bdc8a58fbef0ed97f3849a3ec72e9d9f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 30 Jun 2022 21:02:33 +0200 Subject: [PATCH] db/simple/Song: use std::string_view --- src/db/plugins/simple/Song.cxx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/db/plugins/simple/Song.cxx b/src/db/plugins/simple/Song.cxx index e1d6290dd..38d6e21c3 100644 --- a/src/db/plugins/simple/Song.cxx +++ b/src/db/plugins/simple/Song.cxx @@ -28,6 +28,8 @@ #include "time/ChronoUtil.hxx" #include "util/IterableSplitString.hxx" +using std::string_view_literals::operator""sv; + Song::Song(DetachedSong &&other, Directory &_parent) noexcept :parent(_parent), filename(other.GetURI()), @@ -63,14 +65,14 @@ Song::GetURI() const noexcept */ gcc_pure static const Directory * -FindTargetDirectory(const Directory &base, StringView path) noexcept +FindTargetDirectory(const Directory &base, std::string_view path) noexcept { const auto *directory = &base; - for (const StringView name : IterableSplitString(path, '/')) { - if (name.empty() || name.Equals(".")) + for (const std::string_view name : IterableSplitString(path, '/')) { + if (name.empty() || name == "."sv) continue; - directory = name.Equals("..") + directory = name == ".."sv ? directory->parent : directory->FindChild(name); if (directory == nullptr) @@ -85,12 +87,12 @@ FindTargetDirectory(const Directory &base, StringView path) noexcept */ gcc_pure static const Song * -FindTargetSong(const Directory &_directory, StringView target) noexcept +FindTargetSong(const Directory &_directory, std::string_view target) noexcept { - auto [path, last] = target.SplitLast('/'); - if (last == nullptr) { + auto [path, last] = SplitLast(target, '/'); + if (last.data() == nullptr) { last = path; - path = nullptr; + path = {}; } if (last.empty()) @@ -107,7 +109,7 @@ ExportedSong Song::Export() const noexcept { const auto *target_song = !target.empty() - ? FindTargetSong(parent, (std::string_view)target) + ? FindTargetSong(parent, target) : nullptr; Tag merged_tag;