aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-04-24 09:43:08 +0200
committerMax Kellermann <max@duempel.org>2014-04-24 09:59:59 +0200
commitb999e16406ca7cdf38b1364cee48be50e2f1d756 (patch)
tree7d5cbe3e11ac724fbc5e2cb2ced802c930b5cb0d
parent7fb9bebd463afc67909ae9220e38a6d3ca938c12 (diff)
downloadmpd-b999e16406ca7cdf38b1364cee48be50e2f1d756.tar.gz
mpd-b999e16406ca7cdf38b1364cee48be50e2f1d756.tar.xz
mpd-b999e16406ca7cdf38b1364cee48be50e2f1d756.zip
SongFilter: convert argv to ConstBuffer
-rw-r--r--src/SongFilter.cxx9
-rw-r--r--src/SongFilter.hxx4
-rw-r--r--src/command/DatabaseCommands.cxx22
-rw-r--r--src/command/QueueCommands.cxx5
4 files changed, 27 insertions, 13 deletions
diff --git a/src/SongFilter.cxx b/src/SongFilter.cxx
index 7bd0857c2..432280e4e 100644
--- a/src/SongFilter.cxx
+++ b/src/SongFilter.cxx
@@ -22,6 +22,7 @@
#include "db/LightSong.hxx"
#include "DetachedSong.hxx"
#include "tag/Tag.hxx"
+#include "util/ConstBuffer.hxx"
#include "util/ASCII.hxx"
#include "util/UriUtil.hxx"
#include "lib/icu/Collate.hxx"
@@ -181,13 +182,13 @@ SongFilter::Parse(const char *tag_string, const char *value, bool fold_case)
}
bool
-SongFilter::Parse(unsigned argc, char *argv[], bool fold_case)
+SongFilter::Parse(ConstBuffer<const char *> args, bool fold_case)
{
- if (argc == 0 || argc % 2 != 0)
+ if (args.size == 0 || args.size % 2 != 0)
return false;
- for (unsigned i = 0; i < argc; i += 2)
- if (!Parse(argv[i], argv[i + 1], fold_case))
+ for (unsigned i = 0; i < args.size; i += 2)
+ if (!Parse(args[i], args[i + 1], fold_case))
return false;
return true;
diff --git a/src/SongFilter.hxx b/src/SongFilter.hxx
index 74d7187c9..852220f29 100644
--- a/src/SongFilter.hxx
+++ b/src/SongFilter.hxx
@@ -35,6 +35,7 @@
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
+template<typename T> struct ConstBuffer;
struct Tag;
struct TagItem;
struct Song;
@@ -101,8 +102,7 @@ public:
gcc_nonnull(2,3)
bool Parse(const char *tag, const char *value, bool fold_case=false);
- gcc_nonnull(3)
- bool Parse(unsigned argc, char *argv[], bool fold_case=false);
+ bool Parse(ConstBuffer<const char *> args, bool fold_case=false);
gcc_pure
bool Match(const Tag &tag) const;
diff --git a/src/command/DatabaseCommands.cxx b/src/command/DatabaseCommands.cxx
index 7126fc855..6b541db14 100644
--- a/src/command/DatabaseCommands.cxx
+++ b/src/command/DatabaseCommands.cxx
@@ -27,6 +27,7 @@
#include "CommandError.hxx"
#include "client/Client.hxx"
#include "tag/Tag.hxx"
+#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "SongFilter.hxx"
#include "protocol/Result.hxx"
@@ -63,8 +64,10 @@ handle_lsinfo2(Client &client, int argc, char *argv[])
static CommandResult
handle_match(Client &client, int argc, char *argv[], bool fold_case)
{
+ ConstBuffer<const char *> args(argv + 1, argc - 1);
+
SongFilter filter;
- if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
+ if (!filter.Parse(args, fold_case)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
@@ -92,8 +95,10 @@ handle_search(Client &client, int argc, char *argv[])
static CommandResult
handle_match_add(Client &client, int argc, char *argv[], bool fold_case)
{
+ ConstBuffer<const char *> args(argv + 1, argc - 1);
+
SongFilter filter;
- if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
+ if (!filter.Parse(args, fold_case)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
@@ -120,10 +125,11 @@ handle_searchadd(Client &client, int argc, char *argv[])
CommandResult
handle_searchaddpl(Client &client, int argc, char *argv[])
{
- const char *playlist = argv[1];
+ ConstBuffer<const char *> args(argv + 1, argc - 1);
+ const char *playlist = args.shift();
SongFilter filter;
- if (!filter.Parse(argc - 2, argv + 2, true)) {
+ if (!filter.Parse(args, true)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
@@ -142,8 +148,10 @@ handle_searchaddpl(Client &client, int argc, char *argv[])
CommandResult
handle_count(Client &client, int argc, char *argv[])
{
+ ConstBuffer<const char *> args(argv + 1, argc - 1);
+
SongFilter filter;
- if (!filter.Parse(argc - 1, argv + 1, false)) {
+ if (!filter.Parse(args, false)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
@@ -191,8 +199,10 @@ handle_list(Client &client, int argc, char *argv[])
filter = new SongFilter((unsigned)TAG_ARTIST, argv[2]);
} else if (argc > 2) {
+ ConstBuffer<const char *> args(argv + 2, argc - 2);
+
filter = new SongFilter();
- if (!filter->Parse(argc - 2, argv + 2, false)) {
+ if (!filter->Parse(args, false)) {
delete filter;
command_error(client, ACK_ERROR_ARG,
"not able to parse args");
diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx
index 81e5098bb..fbcd0e8ba 100644
--- a/src/command/QueueCommands.cxx
+++ b/src/command/QueueCommands.cxx
@@ -31,6 +31,7 @@
#include "protocol/ArgParser.hxx"
#include "protocol/Result.hxx"
#include "ls.hxx"
+#include "util/ConstBuffer.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "fs/AllocatedPath.hxx"
@@ -231,8 +232,10 @@ static CommandResult
handle_playlist_match(Client &client, int argc, char *argv[],
bool fold_case)
{
+ ConstBuffer<const char *> args(argv + 1, argc - 1);
+
SongFilter filter;
- if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
+ if (!filter.Parse(args, fold_case)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}