1
use crate::{
2
    commands::{
3
        Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
4
        ResponseParserError,
5
    },
6
    common::{SeekMode, TimeWithFractions},
7
};
8

            
9
pub struct SeekCur;
10

            
11
impl Command for SeekCur {
12
    type Response = ();
13
    const COMMAND: &'static str = "seekcur";
14

            
15
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
16
        let time_raw = match parts.next() {
17
            Some(t) => t,
18
            None => return Err(RequestParserError::UnexpectedEOF),
19
        };
20

            
21
        // TODO: DRY
22
        let (mode, time) = match time_raw {
23
            t if t.starts_with('+') => (
24
                SeekMode::Relative,
25
                t[1..]
26
                    .parse::<TimeWithFractions>()
27
                    .map_err(|_| RequestParserError::SyntaxError(0, t.to_owned()))?,
28
            ),
29
            t if t.starts_with('-') => (
30
                SeekMode::Relative,
31
                -t[1..]
32
                    .parse::<TimeWithFractions>()
33
                    .map_err(|_| RequestParserError::SyntaxError(0, t.to_owned()))?,
34
            ),
35
            t => (
36
                SeekMode::Absolute,
37
                t.parse::<TimeWithFractions>()
38
                    .map_err(|_| RequestParserError::SyntaxError(0, t.to_owned()))?,
39
            ),
40
        };
41

            
42
        debug_assert!(parts.next().is_none());
43

            
44
        Ok((Request::SeekCur(mode, time), ""))
45
    }
46

            
47
    fn parse_response(
48
        parts: ResponseAttributes<'_>,
49
    ) -> Result<Self::Response, ResponseParserError> {
50
        debug_assert!(parts.is_empty());
51
        Ok(())
52
    }
53
}