decoder/OpusReader: use std::string_view

This commit is contained in:
Max Kellermann 2022-07-01 11:16:35 +02:00
parent e10b15010c
commit 671b7e079f
2 changed files with 8 additions and 8 deletions
src/decoder/plugins

@ -20,10 +20,9 @@
#ifndef MPD_OPUS_READER_HXX #ifndef MPD_OPUS_READER_HXX
#define MPD_OPUS_READER_HXX #define MPD_OPUS_READER_HXX
#include "util/StringView.hxx"
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <string_view>
#include <string.h> #include <string.h>
@ -83,14 +82,14 @@ public:
return ReadWord(length) && Skip(length); return ReadWord(length) && Skip(length);
} }
constexpr StringView ReadString() noexcept { constexpr std::string_view ReadString() noexcept {
uint32_t length; uint32_t length;
if (!ReadWord(length)) if (!ReadWord(length))
return nullptr; return {};
const char *src = (const char *)Read(length); const char *src = (const char *)Read(length);
if (src == nullptr) if (src == nullptr)
return nullptr; return {};
return {src, length}; return {src, length};
} }

@ -26,6 +26,7 @@
#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/StringSplit.hxx"
#include "util/StringView.hxx" #include "util/StringView.hxx"
#include <cstdint> #include <cstdint>
@ -104,11 +105,11 @@ ScanOpusTags(const void *data, size_t size,
while (n-- > 0) { while (n-- > 0) {
const auto s = r.ReadString(); const auto s = r.ReadString();
if (s == nullptr) if (s.data() == nullptr)
return false; return false;
const auto split = s.Split('='); const auto split = Split(s, '=');
if (split.first.empty() || split.second.IsNull()) if (split.first.empty() || split.second.data() == nullptr)
continue; continue;
ScanOneOpusTag(split.first, split.second, rgi, handler); ScanOneOpusTag(split.first, split.second, rgi, handler);