tag/Handler: use std::string_view instead of StringView

This commit is contained in:
Max Kellermann
2022-06-29 16:44:23 +02:00
parent ca9dd74fbf
commit ec66ee3bfb
7 changed files with 38 additions and 30 deletions

View File

@@ -25,13 +25,15 @@
#include <algorithm>
using std::string_view_literals::operator""sv;
void
NullTagHandler::OnTag(TagType, StringView) noexcept
NullTagHandler::OnTag(TagType, std::string_view) noexcept
{
}
void
NullTagHandler::OnPair(StringView, StringView) noexcept
NullTagHandler::OnPair(std::string_view, std::string_view) noexcept
{
}
@@ -54,18 +56,18 @@ AddTagHandler::OnDuration(SongTime duration) noexcept
/**
* Skip leading zeroes and a non-decimal suffix.
*/
static StringView
NormalizeDecimal(StringView s)
static std::string_view
NormalizeDecimal(std::string_view s)
{
auto start = std::find_if(s.begin(), s.end(),
[](char ch){ return ch != '0'; });
auto end = std::find_if(start, s.end(),
[](char ch){ return !IsDigitASCII(ch); });
return {start, end};
return StringView{start, end};
}
void
AddTagHandler::OnTag(TagType type, StringView value) noexcept
AddTagHandler::OnTag(TagType type, std::string_view value) noexcept
{
if (type == TAG_TRACK || type == TAG_DISC) {
/* filter out this extra data and leading zeroes */
@@ -77,9 +79,9 @@ AddTagHandler::OnTag(TagType type, StringView value) noexcept
}
void
FullTagHandler::OnPair(StringView name, StringView) noexcept
FullTagHandler::OnPair(std::string_view name, std::string_view) noexcept
{
if (name.EqualsIgnoreCase("cuesheet"))
if (StringView{name}.EqualsIgnoreCase("cuesheet"sv))
tag.SetHasPlaylist(true);
}

View File

@@ -26,8 +26,8 @@
#include <cstddef>
#include <span>
#include <string_view>
struct StringView;
struct AudioFormat;
class TagBuilder;
@@ -83,13 +83,14 @@ public:
* @param the value of the tag; the pointer will become
* invalid after returning
*/
virtual void OnTag(TagType type, StringView value) noexcept = 0;
virtual void OnTag(TagType type, std::string_view value) noexcept = 0;
/**
* A name-value pair has been read. It is the codec specific
* representation of tags.
*/
virtual void OnPair(StringView key, StringView value) noexcept = 0;
virtual void OnPair(std::string_view key,
std::string_view value) noexcept = 0;
/**
* Declare the audio format of a song.
@@ -127,8 +128,9 @@ public:
:TagHandler(_want_mask) {}
void OnDuration([[maybe_unused]] SongTime duration) noexcept override {}
void OnTag(TagType type, StringView value) noexcept override;
void OnPair(StringView key, StringView value) noexcept override;
void OnTag(TagType type, std::string_view value) noexcept override;
void OnPair(std::string_view key,
std::string_view value) noexcept override;
void OnAudioFormat(AudioFormat af) noexcept override;
void OnPicture(const char *mime_type,
std::span<const std::byte> buffer) noexcept override;
@@ -151,7 +153,7 @@ public:
:AddTagHandler(0, _builder) {}
void OnDuration(SongTime duration) noexcept override;
void OnTag(TagType type, StringView value) noexcept override;
void OnTag(TagType type, std::string_view value) noexcept override;
};
/**
@@ -175,7 +177,8 @@ public:
AudioFormat *_audio_format=nullptr) noexcept
:FullTagHandler(0, _builder, _audio_format) {}
void OnPair(StringView key, StringView value) noexcept override;
void OnPair(std::string_view key,
std::string_view value) noexcept override;
void OnAudioFormat(AudioFormat af) noexcept override;
};