tag/*: use std::string_view instead of StringView
This commit is contained in:
parent
c7a8fc91c0
commit
683f0da2e7
|
@ -20,13 +20,15 @@
|
||||||
#include "ApeReplayGain.hxx"
|
#include "ApeReplayGain.hxx"
|
||||||
#include "ApeLoader.hxx"
|
#include "ApeLoader.hxx"
|
||||||
#include "ReplayGainParser.hxx"
|
#include "ReplayGainParser.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
replay_gain_ape_callback(unsigned long flags, const char *key,
|
replay_gain_ape_callback(unsigned long flags, const char *key,
|
||||||
StringView _value,
|
std::string_view _value,
|
||||||
ReplayGainInfo &info)
|
ReplayGainInfo &info)
|
||||||
{
|
{
|
||||||
/* we only care about utf-8 text tags */
|
/* we only care about utf-8 text tags */
|
||||||
|
@ -34,11 +36,10 @@ replay_gain_ape_callback(unsigned long flags, const char *key,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char value[16];
|
char value[16];
|
||||||
if (_value.size >= sizeof(value))
|
if (_value.size() >= sizeof(value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
memcpy(value, _value.data, _value.size);
|
*std::copy(_value.begin(), _value.end(), value) = 0;
|
||||||
value[_value.size] = 0;
|
|
||||||
|
|
||||||
return ParseReplayGainTag(info, key, value);
|
return ParseReplayGainTag(info, key, value);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +51,7 @@ replay_gain_ape_read(InputStream &is, ReplayGainInfo &info)
|
||||||
|
|
||||||
auto callback = [&info, &found]
|
auto callback = [&info, &found]
|
||||||
(unsigned long flags, const char *key,
|
(unsigned long flags, const char *key,
|
||||||
StringView value) {
|
std::string_view value) {
|
||||||
found |= replay_gain_ape_callback(flags, key,
|
found |= replay_gain_ape_callback(flags, key,
|
||||||
value,
|
value,
|
||||||
info);
|
info);
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "ParseName.hxx"
|
#include "ParseName.hxx"
|
||||||
#include "Table.hxx"
|
#include "Table.hxx"
|
||||||
#include "Handler.hxx"
|
#include "Handler.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
#include "util/IterableSplitString.hxx"
|
#include "util/IterableSplitString.hxx"
|
||||||
|
|
||||||
static constexpr struct tag_table ape_tags[] = {
|
static constexpr struct tag_table ape_tags[] = {
|
||||||
|
@ -46,7 +45,7 @@ tag_ape_name_parse(const char *name)
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
tag_ape_import_item(unsigned long flags,
|
tag_ape_import_item(unsigned long flags,
|
||||||
const char *key, StringView value,
|
const char *key, std::string_view value,
|
||||||
TagHandler &handler) noexcept
|
TagHandler &handler) noexcept
|
||||||
{
|
{
|
||||||
/* we only care about utf-8 text tags */
|
/* we only care about utf-8 text tags */
|
||||||
|
@ -74,7 +73,7 @@ tag_ape_scan2(InputStream &is, TagHandler &handler)
|
||||||
|
|
||||||
auto callback = [&handler, &recognized]
|
auto callback = [&handler, &recognized]
|
||||||
(unsigned long flags, const char *key,
|
(unsigned long flags, const char *key,
|
||||||
StringView value) {
|
std::string_view value) {
|
||||||
recognized |= tag_ape_import_item(flags, key, value, handler);
|
recognized |= tag_ape_import_item(flags, key, value, handler);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,10 @@
|
||||||
#include "util/ASCII.hxx"
|
#include "util/ASCII.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "util/IterableSplitString.hxx"
|
#include "util/IterableSplitString.hxx"
|
||||||
#include "util/StringView.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
|
#include "util/StringStrip.hxx"
|
||||||
|
|
||||||
|
using std::string_view_literals::operator""sv;
|
||||||
|
|
||||||
void
|
void
|
||||||
TagLoadConfig(const ConfigData &config)
|
TagLoadConfig(const ConfigData &config)
|
||||||
|
@ -45,12 +48,12 @@ TagLoadConfig(const ConfigData &config)
|
||||||
/* no "+-": not incremental */
|
/* no "+-": not incremental */
|
||||||
global_tag_mask = TagMask::None();
|
global_tag_mask = TagMask::None();
|
||||||
|
|
||||||
for (StringView name : IterableSplitString(value, ',')) {
|
for (std::string_view name : IterableSplitString(value, ',')) {
|
||||||
name.Strip();
|
name = Strip(name);
|
||||||
|
|
||||||
if (name.SkipPrefix("+")) {
|
if (SkipPrefix(name, "+"sv)) {
|
||||||
plus = true;
|
plus = true;
|
||||||
} else if (name.SkipPrefix("-")) {
|
} else if (SkipPrefix(name, "-"sv)) {
|
||||||
plus = false;
|
plus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "pcm/AudioFormat.hxx"
|
#include "pcm/AudioFormat.hxx"
|
||||||
#include "util/CharUtil.hxx"
|
#include "util/CharUtil.hxx"
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ NormalizeDecimal(std::string_view s)
|
||||||
[](char ch){ return ch != '0'; });
|
[](char ch){ return ch != '0'; });
|
||||||
auto end = std::find_if(start, s.end(),
|
auto end = std::find_if(start, s.end(),
|
||||||
[](char ch){ return !IsDigitASCII(ch); });
|
[](char ch){ return !IsDigitASCII(ch); });
|
||||||
return StringView{start, end};
|
return std::string_view{start, std::size_t(std::distance(start, end))};
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/*
|
/*yes
|
||||||
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
* Copyright 2003-2021 The Music Player Daemon Project
|
||||||
* http://www.musicpd.org
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
|
@ -20,7 +21,6 @@
|
||||||
#include "IcyMetaDataParser.hxx"
|
#include "IcyMetaDataParser.hxx"
|
||||||
#include "tag/Builder.hxx"
|
#include "tag/Builder.hxx"
|
||||||
#include "util/AllocatedString.hxx"
|
#include "util/AllocatedString.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -73,15 +73,14 @@ IcyMetaDataParser::Data(size_t length) noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
icy_add_item(TagBuilder &tag, TagType type, StringView value) noexcept
|
icy_add_item(TagBuilder &tag, TagType type, std::string_view value) noexcept
|
||||||
{
|
{
|
||||||
if (value.size >= 2 && value.front() == '\'' && value.back() == '\'') {
|
if (value.size() >= 2 && value.front() == '\'' && value.back() == '\'') {
|
||||||
/* strip the single quotes */
|
/* strip the single quotes */
|
||||||
++value.data;
|
value = value.substr(1, value.size() - 2);
|
||||||
value.size -= 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.size > 0)
|
if (!value.empty())
|
||||||
tag.AddItem(type, value);
|
tag.AddItem(type, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,22 +20,21 @@
|
||||||
#include "Id3Picture.hxx"
|
#include "Id3Picture.hxx"
|
||||||
#include "Handler.hxx"
|
#include "Handler.hxx"
|
||||||
#include "util/ByteOrder.hxx"
|
#include "util/ByteOrder.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
static StringView
|
static std::string_view
|
||||||
ReadString(std::span<const std::byte> &src) noexcept
|
ReadString(std::span<const std::byte> &src) noexcept
|
||||||
{
|
{
|
||||||
if (src.size() < 4)
|
if (src.size() < 4)
|
||||||
return nullptr;
|
return {};
|
||||||
|
|
||||||
const size_t length = *(const PackedBE32 *)(const void *)src.data();
|
const size_t length = *(const PackedBE32 *)(const void *)src.data();
|
||||||
src = src.subspan(4);
|
src = src.subspan(4);
|
||||||
|
|
||||||
if (src.size() < length)
|
if (src.size() < length)
|
||||||
return nullptr;
|
return {};
|
||||||
|
|
||||||
const std::string_view result{(const char *)src.data(), length};
|
const std::string_view result{(const char *)src.data(), length};
|
||||||
src = src.subspan(length);
|
src = src.subspan(length);
|
||||||
|
@ -51,11 +50,11 @@ ScanId3Apic(std::span<const std::byte> buffer, TagHandler &handler) noexcept
|
||||||
buffer = buffer.subspan(4); /* picture type */
|
buffer = buffer.subspan(4); /* picture type */
|
||||||
|
|
||||||
const auto mime_type = ReadString(buffer);
|
const auto mime_type = ReadString(buffer);
|
||||||
if (mime_type.IsNull())
|
if (mime_type.data() == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* description */
|
/* description */
|
||||||
if (ReadString(buffer).IsNull())
|
if (ReadString(buffer).data() == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (buffer.size() < 20)
|
if (buffer.size() < 20)
|
||||||
|
@ -71,7 +70,7 @@ ScanId3Apic(std::span<const std::byte> buffer, TagHandler &handler) noexcept
|
||||||
|
|
||||||
const auto image = buffer.first(image_size);
|
const auto image = buffer.first(image_size);
|
||||||
|
|
||||||
// TODO: don't copy MIME type, pass StringView to TagHandler::OnPicture()
|
// TODO: don't copy MIME type, pass std::string_view to TagHandler::OnPicture()
|
||||||
handler.OnPicture(std::string(mime_type.data, mime_type.size).c_str(),
|
handler.OnPicture(std::string{mime_type}.c_str(),
|
||||||
image);
|
image);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "fs/NarrowPath.hxx"
|
#include "fs/NarrowPath.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "input/LocalOpen.hxx"
|
#include "input/LocalOpen.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
#include "util/PrintException.hxx"
|
#include "util/PrintException.hxx"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -36,11 +35,12 @@
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
MyApeTagCallback([[maybe_unused]] unsigned long flags,
|
MyApeTagCallback([[maybe_unused]] unsigned long flags,
|
||||||
const char *key, StringView value)
|
const char *key, std::string_view value)
|
||||||
{
|
{
|
||||||
if ((flags & (0x3 << 1)) == 0)
|
if ((flags & (0x3 << 1)) == 0)
|
||||||
// UTF-8
|
// UTF-8
|
||||||
printf("\"%s\"=\"%.*s\"\n", key, (int)value.size, value.data);
|
printf("\"%s\"=\"%.*s\"\n", key,
|
||||||
|
(int)value.size(), value.data());
|
||||||
else
|
else
|
||||||
printf("\"%s\"=0x%lx\n", key, flags);
|
printf("\"%s\"=0x%lx\n", key, flags);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "playlist/cue/CueParser.hxx"
|
#include "playlist/cue/CueParser.hxx"
|
||||||
#include "util/IterableSplitString.hxx"
|
#include "util/IterableSplitString.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "pcm/AudioFormat.hxx"
|
#include "pcm/AudioFormat.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "util/StringBuffer.hxx"
|
#include "util/StringBuffer.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
#include "util/PrintException.hxx"
|
#include "util/PrintException.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
#include "tag/MixRampParser.cxx"
|
#include "tag/MixRampParser.cxx"
|
||||||
#include "tag/MixRampInfo.hxx"
|
#include "tag/MixRampInfo.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue