db/simple/Song: use std::string_view

This commit is contained in:
Max Kellermann 2022-06-30 21:02:33 +02:00
parent 67fcf7d7c5
commit 60ca12e4bd

View File

@ -28,6 +28,8 @@
#include "time/ChronoUtil.hxx" #include "time/ChronoUtil.hxx"
#include "util/IterableSplitString.hxx" #include "util/IterableSplitString.hxx"
using std::string_view_literals::operator""sv;
Song::Song(DetachedSong &&other, Directory &_parent) noexcept Song::Song(DetachedSong &&other, Directory &_parent) noexcept
:parent(_parent), :parent(_parent),
filename(other.GetURI()), filename(other.GetURI()),
@ -63,14 +65,14 @@ Song::GetURI() const noexcept
*/ */
gcc_pure gcc_pure
static const Directory * static const Directory *
FindTargetDirectory(const Directory &base, StringView path) noexcept FindTargetDirectory(const Directory &base, std::string_view path) noexcept
{ {
const auto *directory = &base; const auto *directory = &base;
for (const StringView name : IterableSplitString(path, '/')) { for (const std::string_view name : IterableSplitString(path, '/')) {
if (name.empty() || name.Equals(".")) if (name.empty() || name == "."sv)
continue; continue;
directory = name.Equals("..") directory = name == ".."sv
? directory->parent ? directory->parent
: directory->FindChild(name); : directory->FindChild(name);
if (directory == nullptr) if (directory == nullptr)
@ -85,12 +87,12 @@ FindTargetDirectory(const Directory &base, StringView path) noexcept
*/ */
gcc_pure gcc_pure
static const Song * static const Song *
FindTargetSong(const Directory &_directory, StringView target) noexcept FindTargetSong(const Directory &_directory, std::string_view target) noexcept
{ {
auto [path, last] = target.SplitLast('/'); auto [path, last] = SplitLast(target, '/');
if (last == nullptr) { if (last.data() == nullptr) {
last = path; last = path;
path = nullptr; path = {};
} }
if (last.empty()) if (last.empty())
@ -107,7 +109,7 @@ ExportedSong
Song::Export() const noexcept Song::Export() const noexcept
{ {
const auto *target_song = !target.empty() const auto *target_song = !target.empty()
? FindTargetSong(parent, (std::string_view)target) ? FindTargetSong(parent, target)
: nullptr; : nullptr;
Tag merged_tag; Tag merged_tag;