tag/VorbisComment: use std::string_view
This commit is contained in:
parent
455a412aaa
commit
4765726bda
@ -29,12 +29,12 @@
|
|||||||
* the comment value into the tag.
|
* the comment value into the tag.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
vorbis_copy_comment(StringView comment,
|
vorbis_copy_comment(std::string_view comment,
|
||||||
StringView name, TagType tag_type,
|
std::string_view name, TagType tag_type,
|
||||||
TagHandler &handler) noexcept
|
TagHandler &handler) noexcept
|
||||||
{
|
{
|
||||||
const auto value = GetVorbisCommentValue(comment, name);
|
const auto value = GetVorbisCommentValue(comment, name);
|
||||||
if (!value.IsNull()) {
|
if (value.data() != nullptr) {
|
||||||
handler.OnTag(tag_type, value);
|
handler.OnTag(tag_type, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ vorbis_scan_comment(StringView comment, TagHandler &handler) noexcept
|
|||||||
{
|
{
|
||||||
const auto picture_b64 = handler.WantPicture()
|
const auto picture_b64 = handler.WantPicture()
|
||||||
? GetVorbisCommentValue(comment, "METADATA_BLOCK_PICTURE")
|
? GetVorbisCommentValue(comment, "METADATA_BLOCK_PICTURE")
|
||||||
: nullptr;
|
: std::string_view{};
|
||||||
if (!picture_b64.IsNull())
|
if (picture_b64.data() != nullptr)
|
||||||
return ScanVorbisPicture(picture_b64, handler);
|
return ScanVorbisPicture(picture_b64, handler);
|
||||||
|
|
||||||
ScanVorbisComment(comment, handler);
|
ScanVorbisComment(comment, handler);
|
||||||
|
@ -75,11 +75,11 @@ bool
|
|||||||
ParseReplayGainVorbis(ReplayGainInfo &info, StringView entry) noexcept
|
ParseReplayGainVorbis(ReplayGainInfo &info, StringView entry) noexcept
|
||||||
{
|
{
|
||||||
struct VorbisCommentEntry {
|
struct VorbisCommentEntry {
|
||||||
StringView entry;
|
std::string_view entry;
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
const char *operator[](StringView n) const noexcept {
|
const char *operator[](std::string_view n) const noexcept {
|
||||||
return GetVorbisCommentValue(entry, n).data;
|
return GetVorbisCommentValue(entry, n).data();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,21 +18,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "VorbisComment.hxx"
|
#include "VorbisComment.hxx"
|
||||||
#include "util/StringView.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
StringView
|
std::string_view
|
||||||
GetVorbisCommentValue(StringView entry, StringView name) noexcept
|
GetVorbisCommentValue(std::string_view entry, std::string_view name) noexcept
|
||||||
{
|
{
|
||||||
assert(!name.empty());
|
assert(!name.empty());
|
||||||
|
|
||||||
if (entry.StartsWithIgnoreCase(name) &&
|
if (StringStartsWithIgnoreCase(entry, name) &&
|
||||||
entry.size > name.size &&
|
entry.size() > name.size() &&
|
||||||
entry[name.size] == '=') {
|
entry[name.size()] == '=')
|
||||||
entry.skip_front(name.size + 1);
|
return entry.substr(name.size() + 1);
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,14 @@
|
|||||||
#ifndef MPD_TAG_VORBIS_COMMENT_HXX
|
#ifndef MPD_TAG_VORBIS_COMMENT_HXX
|
||||||
#define 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,
|
* Checks if the specified name matches the entry's name, and if yes,
|
||||||
* returns the comment value.
|
* returns the comment value.
|
||||||
*/
|
*/
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
StringView
|
std::string_view
|
||||||
GetVorbisCommentValue(StringView entry, StringView name) noexcept;
|
GetVorbisCommentValue(std::string_view entry, std::string_view name) noexcept;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user