diff options
author | Max Kellermann <max@musicpd.org> | 2019-03-25 18:58:22 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-03-25 19:02:11 +0100 |
commit | de4fd4c0596ba41c6fd1bc7ff617bcf807854562 (patch) | |
tree | 51ad27035e238c766d27b7d2916581b70cfbaec6 /src/command/DatabaseCommands.cxx | |
parent | 95d8b30864ce08bed7920ab0c790986c8eba4c88 (diff) |
command/database: move code to ParseDatabaseSelection()
Diffstat (limited to 'src/command/DatabaseCommands.cxx')
-rw-r--r-- | src/command/DatabaseCommands.cxx | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/command/DatabaseCommands.cxx b/src/command/DatabaseCommands.cxx index 6fc9fa8ac..3f0bc4f51 100644 --- a/src/command/DatabaseCommands.cxx +++ b/src/command/DatabaseCommands.cxx @@ -70,8 +70,13 @@ ParseSortTag(const char *s) return tag; } -static CommandResult -handle_match(Client &client, Request args, Response &r, bool fold_case) +/** + * Convert all remaining arguments to a #DatabaseSelection. + * + * @param filter a buffer to be used for DatabaseSelection::filter + */ +static DatabaseSelection +ParseDatabaseSelection(Request args, bool fold_case, SongFilter &filter) { RangeArg window = RangeArg::All(); if (args.size >= 2 && StringIsEqual(args[args.size - 2], "window")) { @@ -96,13 +101,11 @@ handle_match(Client &client, Request args, Response &r, bool fold_case) args.pop_back(); } - SongFilter filter; try { filter.Parse(args, fold_case); } catch (...) { - r.Error(ACK_ERROR_ARG, - GetFullMessage(std::current_exception()).c_str()); - return CommandResult::ERROR; + throw ProtocolError(ACK_ERROR_ARG, + GetFullMessage(std::current_exception()).c_str()); } filter.Optimize(); @@ -110,6 +113,14 @@ handle_match(Client &client, Request args, Response &r, bool fold_case) selection.window = window; selection.sort = sort; selection.descending = descending; + return selection; +} + +static CommandResult +handle_match(Client &client, Request args, Response &r, bool fold_case) +{ + SongFilter filter; + const auto selection = ParseDatabaseSelection(args, fold_case, filter); db_selection_print(r, client.GetPartition(), selection, true, false); |