From 4fb8b45111497775727cc85e84d845276f9788df Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 4 Jul 2022 18:21:44 +0200 Subject: [PATCH] song/Filter: use std::span instead of ConstBuffer --- src/song/Filter.cxx | 13 +++++++------ src/song/Filter.hxx | 4 ++-- test/ParseSongFilter.cxx | 3 +-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/song/Filter.cxx b/src/song/Filter.cxx index 04c8bea3b..024004e63 100644 --- a/src/song/Filter.cxx +++ b/src/song/Filter.cxx @@ -30,7 +30,6 @@ #include "tag/ParseName.hxx" #include "time/ISO8601.hxx" #include "util/CharUtil.hxx" -#include "util/ConstBuffer.hxx" #include "util/RuntimeError.hxx" #include "util/StringCompare.hxx" #include "util/StringStrip.hxx" @@ -410,14 +409,15 @@ SongFilter::Parse(const char *tag_string, const char *value, bool fold_case) } void -SongFilter::Parse(ConstBuffer args, bool fold_case) +SongFilter::Parse(std::span args, bool fold_case) { if (args.empty()) throw std::runtime_error("Incorrect number of filter arguments"); do { if (*args.front() == '(') { - const char *s = args.shift(); + const char *s = args.front(); + args = args.subspan(1); const char *end = s; auto f = ParseExpression(end, fold_case); if (*end != 0) @@ -427,11 +427,12 @@ SongFilter::Parse(ConstBuffer args, bool fold_case) continue; } - if (args.size < 2) + if (args.size() < 2) throw std::runtime_error("Incorrect number of filter arguments"); - const char *tag = args.shift(); - const char *value = args.shift(); + const char *tag = args[0]; + const char *value = args[1]; + args = args.subspan(2); Parse(tag, value, fold_case); } while (!args.empty()); } diff --git a/src/song/Filter.hxx b/src/song/Filter.hxx index 09738d668..28aa559a4 100644 --- a/src/song/Filter.hxx +++ b/src/song/Filter.hxx @@ -23,6 +23,7 @@ #include "AndSongFilter.hxx" #include +#include #include #include @@ -36,7 +37,6 @@ */ #define SORT_TAG_PRIO (TAG_NUM_OF_ITEM_TYPES + 4) -template struct ConstBuffer; enum TagType : uint8_t; struct LightSong; @@ -68,7 +68,7 @@ public: /** * Throws on error. */ - void Parse(ConstBuffer args, bool fold_case=false); + void Parse(std::span args, bool fold_case=false); void Optimize() noexcept; diff --git a/test/ParseSongFilter.cxx b/test/ParseSongFilter.cxx index 9cd314a5f..b68464180 100644 --- a/test/ParseSongFilter.cxx +++ b/test/ParseSongFilter.cxx @@ -23,7 +23,6 @@ */ #include "song/Filter.hxx" -#include "util/ConstBuffer.hxx" #include "util/PrintException.hxx" #include @@ -39,7 +38,7 @@ try { } SongFilter filter; - filter.Parse(ConstBuffer(argv + 1, argc - 1)); + filter.Parse({argv + 1, std::size_t(argc - 1)}); filter.Optimize(); puts(filter.ToExpression().c_str());