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