tag/VorbisComment: use std::string_view

This commit is contained in:
Max Kellermann
2022-06-30 10:53:54 +02:00
parent 455a412aaa
commit 4765726bda
5 changed files with 19 additions and 21 deletions
+3 -3
View File
@@ -75,11 +75,11 @@ bool
ParseReplayGainVorbis(ReplayGainInfo &info, StringView entry) noexcept
{
struct VorbisCommentEntry {
StringView entry;
std::string_view entry;
gcc_pure
const char *operator[](StringView n) const noexcept {
return GetVorbisCommentValue(entry, n).data;
const char *operator[](std::string_view n) const noexcept {
return GetVorbisCommentValue(entry, n).data();
}
};
+8 -10
View File
@@ -18,21 +18,19 @@
*/
#include "VorbisComment.hxx"
#include "util/StringView.hxx"
#include "util/StringCompare.hxx"
#include <cassert>
StringView
GetVorbisCommentValue(StringView entry, StringView name) noexcept
std::string_view
GetVorbisCommentValue(std::string_view entry, std::string_view name) noexcept
{
assert(!name.empty());
if (entry.StartsWithIgnoreCase(name) &&
entry.size > name.size &&
entry[name.size] == '=') {
entry.skip_front(name.size + 1);
return entry;
}
if (StringStartsWithIgnoreCase(entry, name) &&
entry.size() > name.size() &&
entry[name.size()] == '=')
return entry.substr(name.size() + 1);
return nullptr;
return {};
}
+3 -3
View File
@@ -20,14 +20,14 @@
#ifndef MPD_TAG_VORBIS_COMMENT_HXX
#define MPD_TAG_VORBIS_COMMENT_HXX
struct StringView;
#include <string_view>
/**
* Checks if the specified name matches the entry's name, and if yes,
* returns the comment value.
*/
[[gnu::pure]]
StringView
GetVorbisCommentValue(StringView entry, StringView name) noexcept;
std::string_view
GetVorbisCommentValue(std::string_view entry, std::string_view name) noexcept;
#endif