From e565528b3365396ea70042f54cb350cf9553e302 Mon Sep 17 00:00:00 2001 From: Petr Kracik Date: Mon, 6 Jan 2020 13:01:28 +0100 Subject: [PATCH] Implement find filter list --- .../MpcNET/Commands/Database/FindCommand.cs | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Sources/MpcNET/Commands/Database/FindCommand.cs b/Sources/MpcNET/Commands/Database/FindCommand.cs index 3d15c9a..954c14e 100644 --- a/Sources/MpcNET/Commands/Database/FindCommand.cs +++ b/Sources/MpcNET/Commands/Database/FindCommand.cs @@ -7,6 +7,7 @@ namespace MpcNET.Commands.Database { using System.Collections.Generic; + using System.Linq; using MpcNET.Tags; using MpcNET.Types; @@ -16,8 +17,7 @@ namespace MpcNET.Commands.Database /// public class FindCommand : IMpcCommand> { - private readonly ITag tag; - private readonly string searchText; + private readonly List> filters; /// /// Initializes a new instance of the class. @@ -26,8 +26,17 @@ namespace MpcNET.Commands.Database /// The search text. public FindCommand(ITag tag, string searchText) { - this.tag = tag; - this.searchText = searchText; + this.filters = new List>(); + this.filters.Add(new KeyValuePair(tag, searchText)); + } + + /// + /// Initializes a new instance of the class. + /// + /// List of key/value filters + public FindCommand(List> filters) + { + this.filters = filters; } /// @@ -36,7 +45,14 @@ namespace MpcNET.Commands.Database /// /// The serialize command. /// - public string Serialize() => string.Join(" ", "find", this.tag.Value, this.searchText); + public string Serialize() => + string.Join(" ", + "find", + string.Join(" ", + this.filters + .Select(x => string.Join(" ", + x.Key.Value, escape(x.Value))) + .ToArray())); /// /// Deserializes the specified response text pairs. @@ -49,7 +65,8 @@ namespace MpcNET.Commands.Database { return MpdFile.CreateList(response); } - } + private string escape(string value) => string.Format("\"{0}\"", value.Replace("\\", "\\\\").Replace("\"", "\\\"")); + } // TODO: rescan }