decoder/opus: use StringView::Split()

This commit is contained in:
Max Kellermann 2019-06-06 13:07:06 +02:00
parent 72a0aeb265
commit dffa25c55e

View File

@ -27,12 +27,11 @@
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
gcc_pure gcc_pure
static TagType static TagType
ParseOpusTagName(const char *name) noexcept ParseOpusTagName(StringView 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)
@ -42,11 +41,11 @@ ParseOpusTagName(const char *name) noexcept
} }
static void static void
ScanOneOpusTag(const char *name, const char *value, ScanOneOpusTag(StringView name, const char *value,
ReplayGainInfo *rgi, ReplayGainInfo *rgi,
TagHandler &handler) noexcept 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 /* R128_TRACK_GAIN is a Q7.8 fixed point number in
dB */ dB */
@ -54,7 +53,7 @@ ScanOneOpusTag(const char *name, const char *value,
long l = strtol(value, &endptr, 10); long l = strtol(value, &endptr, 10);
if (endptr > value && *endptr == 0) if (endptr > value && *endptr == 0)
rgi->track.gain = double(l) / 256.; 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 /* R128_ALBUM_GAIN is a Q7.8 fixed point number in
dB */ dB */
@ -100,18 +99,13 @@ ScanOpusTags(const void *data, size_t size,
if (s.size >= 4096) if (s.size >= 4096)
continue; continue;
const auto eq = s.Find('='); const auto split = s.Split('=');
if (eq == nullptr || eq == s.data) if (split.first.empty() || split.second.IsNull())
continue; continue;
auto name = s, value = s; const std::string value2(split.second.data, split.second.size);
name.SetEnd(eq);
value.MoveFront(eq + 1);
const std::string name2(name.data, name.size); ScanOneOpusTag(split.first, value2.c_str(), rgi, handler);
const std::string value2(value.data, value.size);
ScanOneOpusTag(name2.c_str(), value2.c_str(), rgi, handler);
} }
return true; return true;