decoder/OpusTags: use std::string_view

This commit is contained in:
Max Kellermann 2022-07-01 11:18:17 +02:00
parent f32d752ccb
commit ed7263ee3e

View File

@ -26,14 +26,16 @@
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "tag/ReplayGainInfo.hxx" #include "tag/ReplayGainInfo.hxx"
#include "util/NumberParser.hxx" #include "util/NumberParser.hxx"
#include "util/StringCompare.hxx"
#include "util/StringSplit.hxx" #include "util/StringSplit.hxx"
#include "util/StringView.hxx"
#include <cstdint> #include <cstdint>
using std::string_view_literals::operator""sv;
gcc_pure gcc_pure
static TagType static TagType
ParseOpusTagName(StringView name) noexcept ParseOpusTagName(std::string_view name) noexcept
{ {
TagType type = tag_name_parse_i(name); TagType type = tag_name_parse_i(name);
if (type != TAG_NUM_OF_ITEM_TYPES) if (type != TAG_NUM_OF_ITEM_TYPES)
@ -43,19 +45,20 @@ ParseOpusTagName(StringView name) noexcept
} }
static void static void
ScanOneOpusTag(StringView name, StringView value, ScanOneOpusTag(std::string_view name, std::string_view value,
ReplayGainInfo *rgi, ReplayGainInfo *rgi,
TagHandler &handler) noexcept TagHandler &handler) noexcept
{ {
if (handler.WantPicture() && if (handler.WantPicture() &&
name.EqualsIgnoreCase("METADATA_BLOCK_PICTURE")) StringIsEqualIgnoreCase(name, "METADATA_BLOCK_PICTURE"sv))
return ScanVorbisPicture(value, handler); return ScanVorbisPicture(value, handler);
if (value.size >= 4096) if (value.size() >= 4096)
/* ignore large values */ /* ignore large values */
return; return;
if (rgi != nullptr && name.EqualsIgnoreCase("R128_TRACK_GAIN")) { if (rgi != nullptr &&
StringIsEqualIgnoreCase(name, "R128_TRACK_GAIN"sv)) {
/* R128_TRACK_GAIN is a Q7.8 fixed point number in /* R128_TRACK_GAIN is a Q7.8 fixed point number in
dB */ dB */
@ -64,7 +67,7 @@ ScanOneOpusTag(StringView name, StringView value,
if (endptr > value.begin() && endptr == value.end()) if (endptr > value.begin() && endptr == value.end())
rgi->track.gain = float(l) / 256.0f; rgi->track.gain = float(l) / 256.0f;
} else if (rgi != nullptr && } else if (rgi != nullptr &&
name.EqualsIgnoreCase("R128_ALBUM_GAIN")) { StringIsEqualIgnoreCase(name, "R128_ALBUM_GAIN"sv)) {
/* R128_ALBUM_GAIN is a Q7.8 fixed point number in /* R128_ALBUM_GAIN is a Q7.8 fixed point number in
dB */ dB */