diff --git a/src/commands/queue/playlistfind.rs b/src/commands/queue/playlistfind.rs index d91ef30..f469158 100644 --- a/src/commands/queue/playlistfind.rs +++ b/src/commands/queue/playlistfind.rs @@ -2,6 +2,7 @@ use crate::{ commands::{ Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError, }, + filter::parse_filter, Request, }; @@ -12,8 +13,7 @@ impl Command for PlaylistFind { const COMMAND: &'static str = "playlistfind"; fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { - let filter = parts.next().ok_or(RequestParserError::UnexpectedEOF)?; - let filter = filter.to_string(); + let filter = parse_filter(&mut parts)?; let mut sort_or_window = parts.next(); let mut sort = None; diff --git a/src/commands/queue/playlistsearch.rs b/src/commands/queue/playlistsearch.rs index fac05d4..9400b15 100644 --- a/src/commands/queue/playlistsearch.rs +++ b/src/commands/queue/playlistsearch.rs @@ -2,6 +2,7 @@ use crate::{ commands::{ Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError, }, + filter::parse_filter, Request, }; @@ -12,10 +13,7 @@ impl Command for PlaylistSearch { const COMMAND: &'static str = "playlistsearch"; fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { - let filter = parts.next().ok_or(RequestParserError::UnexpectedEOF)?; - let filter = filter - .parse() - .map_err(|_| RequestParserError::SyntaxError(0, filter.to_string()))?; + let filter = parse_filter(&mut parts)?; let mut sort_or_window = parts.next(); let mut sort = None; diff --git a/src/commands/stored_playlists/searchplaylist.rs b/src/commands/stored_playlists/searchplaylist.rs index 69f56cf..0d8c898 100644 --- a/src/commands/stored_playlists/searchplaylist.rs +++ b/src/commands/stored_playlists/searchplaylist.rs @@ -3,7 +3,8 @@ use crate::{ Command, Request, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError, }, - common::{Filter, PlaylistName}, + common::PlaylistName, + filter::parse_filter, }; pub struct SearchPlaylist; @@ -18,10 +19,7 @@ impl Command for SearchPlaylist { .parse::() .map_err(|_| RequestParserError::SyntaxError(0, name.to_owned()))?; - let filter = parts.next().ok_or(RequestParserError::UnexpectedEOF)?; - let filter = filter - .parse::() - .map_err(|_| RequestParserError::SyntaxError(0, filter.to_owned()))?; + let filter = parse_filter(&mut parts)?; let range = parts .next() diff --git a/src/common.rs b/src/common.rs index 32890cf..4c147c2 100644 --- a/src/common.rs +++ b/src/common.rs @@ -95,7 +95,6 @@ pub type TagName = String; pub type TagValue = String; pub type Uri = String; pub type Path = String; -pub type Filter = String; pub type Sort = String; pub type Version = String; pub type Feature = String; diff --git a/src/filter.rs b/src/filter.rs index f0fb72c..d030c31 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -1,11 +1,20 @@ -use crate::common::{Priority, Tag}; +use std::str::SplitWhitespace; +use serde::{Deserialize, Serialize}; + +use crate::{ + commands::RequestParserError, + common::{Priority, Tag}, +}; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum CaseSensitivity { CaseSensitive, CaseInsensitive, CommandDependent, } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum Filter { Not(Box), And(Box, Box), @@ -30,3 +39,7 @@ pub enum Filter { }, PrioCmp(Priority), } + +pub fn parse_filter(parts: &mut SplitWhitespace<'_>) -> Result { + todo!() +} diff --git a/src/request.rs b/src/request.rs index c82b617..825b11b 100644 --- a/src/request.rs +++ b/src/request.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::common::*; use crate::commands::*; +use crate::filter::Filter; // TODO: SingleLineString