From 8a136b79e5107bf7b027cd07c293b40fa6d47cd9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 6 Jun 2019 13:19:46 +0200 Subject: [PATCH] decoder/opus: pass StringView to ScanOneOpusTag() --- src/decoder/plugins/OpusTags.cxx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/decoder/plugins/OpusTags.cxx b/src/decoder/plugins/OpusTags.cxx index d5abe1c46..17a8b93da 100644 --- a/src/decoder/plugins/OpusTags.cxx +++ b/src/decoder/plugins/OpusTags.cxx @@ -23,11 +23,12 @@ #include "tag/Handler.hxx" #include "tag/ParseName.hxx" #include "ReplayGainInfo.hxx" +#include "util/NumberParser.hxx" +#include "util/StringView.hxx" #include #include -#include gcc_pure static TagType @@ -41,7 +42,7 @@ ParseOpusTagName(StringView name) noexcept } static void -ScanOneOpusTag(StringView name, const char *value, +ScanOneOpusTag(StringView name, StringView value, ReplayGainInfo *rgi, TagHandler &handler) noexcept { @@ -49,17 +50,17 @@ ScanOneOpusTag(StringView name, const char *value, /* R128_TRACK_GAIN is a Q7.8 fixed point number in dB */ - char *endptr; - long l = strtol(value, &endptr, 10); - if (endptr > value && *endptr == 0) + const char *endptr; + const auto l = ParseInt64(value, &endptr, 10); + if (endptr > value.begin() && endptr == value.end()) rgi->track.gain = double(l) / 256.; } else if (rgi != nullptr && name.Equals("R128_ALBUM_GAIN")) { /* R128_ALBUM_GAIN is a Q7.8 fixed point number in dB */ - char *endptr; - long l = strtol(value, &endptr, 10); - if (endptr > value && *endptr == 0) + const char *endptr; + const auto l = ParseInt64(value, &endptr, 10); + if (endptr > value.begin() && endptr == value.end()) rgi->album.gain = double(l) / 256.; } @@ -103,9 +104,7 @@ ScanOpusTags(const void *data, size_t size, if (split.first.empty() || split.second.IsNull()) continue; - const std::string value2(split.second.data, split.second.size); - - ScanOneOpusTag(split.first, value2.c_str(), rgi, handler); + ScanOneOpusTag(split.first, split.second, rgi, handler); } return true;