song/Filter: use std::span instead of ConstBuffer

This commit is contained in:
Max Kellermann 2022-07-04 18:21:44 +02:00
parent 6c107443d3
commit 4fb8b45111
3 changed files with 10 additions and 10 deletions

View File

@ -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<const char *> args, bool fold_case)
SongFilter::Parse(std::span<const char *const> 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<const char *> 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());
}

View File

@ -23,6 +23,7 @@
#include "AndSongFilter.hxx"
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
@ -36,7 +37,6 @@
*/
#define SORT_TAG_PRIO (TAG_NUM_OF_ITEM_TYPES + 4)
template<typename T> struct ConstBuffer;
enum TagType : uint8_t;
struct LightSong;
@ -68,7 +68,7 @@ public:
/**
* Throws on error.
*/
void Parse(ConstBuffer<const char *> args, bool fold_case=false);
void Parse(std::span<const char *const> args, bool fold_case=false);
void Optimize() noexcept;

View File

@ -23,7 +23,6 @@
*/
#include "song/Filter.hxx"
#include "util/ConstBuffer.hxx"
#include "util/PrintException.hxx"
#include <stdexcept>
@ -39,7 +38,7 @@ try {
}
SongFilter filter;
filter.Parse(ConstBuffer<const char *>(argv + 1, argc - 1));
filter.Parse({argv + 1, std::size_t(argc - 1)});
filter.Optimize();
puts(filter.ToExpression().c_str());