From dffa25c55ebe1d1b66355f545b7fdf4e30955e96 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 6 Jun 2019 13:07:06 +0200 Subject: [PATCH] decoder/opus: use StringView::Split() --- src/decoder/plugins/OpusTags.cxx | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/decoder/plugins/OpusTags.cxx b/src/decoder/plugins/OpusTags.cxx index c0a14fa89..d5abe1c46 100644 --- a/src/decoder/plugins/OpusTags.cxx +++ b/src/decoder/plugins/OpusTags.cxx @@ -27,12 +27,11 @@ #include #include -#include #include gcc_pure static TagType -ParseOpusTagName(const char *name) noexcept +ParseOpusTagName(StringView name) noexcept { TagType type = tag_name_parse_i(name); if (type != TAG_NUM_OF_ITEM_TYPES) @@ -42,11 +41,11 @@ ParseOpusTagName(const char *name) noexcept } static void -ScanOneOpusTag(const char *name, const char *value, +ScanOneOpusTag(StringView name, const char *value, ReplayGainInfo *rgi, TagHandler &handler) noexcept { - if (rgi != nullptr && strcmp(name, "R128_TRACK_GAIN") == 0) { + if (rgi != nullptr && name.Equals("R128_TRACK_GAIN")) { /* R128_TRACK_GAIN is a Q7.8 fixed point number in dB */ @@ -54,7 +53,7 @@ ScanOneOpusTag(const char *name, const char *value, long l = strtol(value, &endptr, 10); if (endptr > value && *endptr == 0) rgi->track.gain = double(l) / 256.; - } else if (rgi != nullptr && strcmp(name, "R128_ALBUM_GAIN") == 0) { + } else if (rgi != nullptr && name.Equals("R128_ALBUM_GAIN")) { /* R128_ALBUM_GAIN is a Q7.8 fixed point number in dB */ @@ -100,18 +99,13 @@ ScanOpusTags(const void *data, size_t size, if (s.size >= 4096) continue; - const auto eq = s.Find('='); - if (eq == nullptr || eq == s.data) + const auto split = s.Split('='); + if (split.first.empty() || split.second.IsNull()) continue; - auto name = s, value = s; - name.SetEnd(eq); - value.MoveFront(eq + 1); + const std::string value2(split.second.data, split.second.size); - const std::string name2(name.data, name.size); - const std::string value2(value.data, value.size); - - ScanOneOpusTag(name2.c_str(), value2.c_str(), rgi, handler); + ScanOneOpusTag(split.first, value2.c_str(), rgi, handler); } return true;