diff --git a/src/tag/ApeReplayGain.cxx b/src/tag/ApeReplayGain.cxx index 986f66e69..e89f285fd 100644 --- a/src/tag/ApeReplayGain.cxx +++ b/src/tag/ApeReplayGain.cxx @@ -20,13 +20,15 @@ #include "ApeReplayGain.hxx" #include "ApeLoader.hxx" #include "ReplayGainParser.hxx" -#include "util/StringView.hxx" + +#include +#include #include 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); diff --git a/src/tag/ApeTag.cxx b/src/tag/ApeTag.cxx index 6acc6ab9d..d1b7ad17d 100644 --- a/src/tag/ApeTag.cxx +++ b/src/tag/ApeTag.cxx @@ -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; }; diff --git a/src/tag/Config.cxx b/src/tag/Config.cxx index ae11872e6..d00de6e73 100644 --- a/src/tag/Config.cxx +++ b/src/tag/Config.cxx @@ -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; } diff --git a/src/tag/Handler.cxx b/src/tag/Handler.cxx index 07b81e2ea..a031b90ae 100644 --- a/src/tag/Handler.cxx +++ b/src/tag/Handler.cxx @@ -22,7 +22,6 @@ #include "pcm/AudioFormat.hxx" #include "util/CharUtil.hxx" #include "util/StringCompare.hxx" -#include "util/StringView.hxx" #include @@ -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 diff --git a/src/tag/IcyMetaDataParser.cxx b/src/tag/IcyMetaDataParser.cxx index b3e92c073..22be24797 100644 --- a/src/tag/IcyMetaDataParser.cxx +++ b/src/tag/IcyMetaDataParser.cxx @@ -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 #include @@ -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); } diff --git a/src/tag/Id3Picture.cxx b/src/tag/Id3Picture.cxx index 2ce607f36..953daa726 100644 --- a/src/tag/Id3Picture.cxx +++ b/src/tag/Id3Picture.cxx @@ -20,22 +20,21 @@ #include "Id3Picture.hxx" #include "Handler.hxx" #include "util/ByteOrder.hxx" -#include "util/StringView.hxx" #include #include -static StringView +static std::string_view ReadString(std::span &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 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 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); } diff --git a/test/ReadApeTags.cxx b/test/ReadApeTags.cxx index 14bd10f83..f60be44b8 100644 --- a/test/ReadApeTags.cxx +++ b/test/ReadApeTags.cxx @@ -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 @@ -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; diff --git a/test/fuzzer/FuzzCueParser.cxx b/test/fuzzer/FuzzCueParser.cxx index c0d286b87..04f28f2af 100644 --- a/test/fuzzer/FuzzCueParser.cxx +++ b/test/fuzzer/FuzzCueParser.cxx @@ -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); diff --git a/test/read_tags.cxx b/test/read_tags.cxx index c2dd180c8..c97a5a77f 100644 --- a/test/read_tags.cxx +++ b/test/read_tags.cxx @@ -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 diff --git a/test/tag/TestMixRampParser.cxx b/test/tag/TestMixRampParser.cxx index d9101e616..49a8479b5 100644 --- a/test/tag/TestMixRampParser.cxx +++ b/test/tag/TestMixRampParser.cxx @@ -19,7 +19,6 @@ #include "tag/MixRampParser.cxx" #include "tag/MixRampInfo.hxx" -#include "util/StringView.hxx" #include