lib/xiph/FlacStreamMetadata: properly convert entries to StringView

This commit is contained in:
Max Kellermann 2019-08-14 19:41:12 +02:00
parent 07fcf091a2
commit 7a89b1656c
1 changed files with 10 additions and 7 deletions

View File

@ -34,6 +34,12 @@
#include <assert.h> #include <assert.h>
static StringView
ToStringView(const FLAC__StreamMetadata_VorbisComment_Entry &entry) noexcept
{
return {(const char *)entry.entry, entry.length};
}
bool bool
flac_parse_replay_gain(ReplayGainInfo &rgi, flac_parse_replay_gain(ReplayGainInfo &rgi,
const FLAC__StreamMetadata_VorbisComment &vc) const FLAC__StreamMetadata_VorbisComment &vc)
@ -44,8 +50,7 @@ flac_parse_replay_gain(ReplayGainInfo &rgi,
const auto *comments = vc.comments; const auto *comments = vc.comments;
for (FLAC__uint32 i = 0, n = vc.num_comments; i < n; ++i) for (FLAC__uint32 i = 0, n = vc.num_comments; i < n; ++i)
if (ParseReplayGainVorbis(rgi, if (ParseReplayGainVorbis(rgi, ToStringView(comments[i])))
(const char *)comments[i].entry))
found = true; found = true;
return found; return found;
@ -58,8 +63,7 @@ flac_parse_mixramp(const FLAC__StreamMetadata_VorbisComment &vc)
const auto *comments = vc.comments; const auto *comments = vc.comments;
for (FLAC__uint32 i = 0, n = vc.num_comments; i < n; ++i) for (FLAC__uint32 i = 0, n = vc.num_comments; i < n; ++i)
ParseMixRampVorbis(mix_ramp, ParseMixRampVorbis(mix_ramp, ToStringView(comments[i]));
(const char *)comments[i].entry);
return mix_ramp; return mix_ramp;
} }
@ -72,8 +76,7 @@ static StringView
GetFlacCommentValue(const FLAC__StreamMetadata_VorbisComment_Entry *entry, GetFlacCommentValue(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
StringView name) noexcept StringView name) noexcept
{ {
return GetVorbisCommentValue({(const char *)entry->entry, entry->length}, return GetVorbisCommentValue(ToStringView(*entry), name);
name);
} }
/** /**
@ -99,7 +102,7 @@ flac_scan_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
TagHandler &handler) noexcept TagHandler &handler) noexcept
{ {
if (handler.WantPair()) { if (handler.WantPair()) {
const StringView comment((const char *)entry->entry); const auto comment = ToStringView(*entry);
const auto split = StringView(comment).Split('='); const auto split = StringView(comment).Split('=');
if (!split.first.empty() && !split.second.IsNull()) if (!split.first.empty() && !split.second.IsNull())
handler.OnPair(split.first, split.second); handler.OnPair(split.first, split.second);