From d8e0283ddbd8d9531e1ddaae55b1129a96c7dcd1 Mon Sep 17 00:00:00 2001 From: Vadim Getmanshchuk Date: Thu, 30 Nov 2023 21:55:10 -0600 Subject: [PATCH] allowing empty comments --- src/parser.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index eef540a..9ee8eb2 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -218,7 +218,7 @@ enum MasterPlaylistTag { SessionKey(SessionKey), Start(Start), IndependentSegments, - Comment(String), + Comment(Option), Uri(String), Unknown(ExtTag), } @@ -487,7 +487,7 @@ enum SegmentTag { ProgramDateTime(chrono::DateTime), DateRange(DateRange), Unknown(ExtTag), - Comment(String), + Comment(Option), Uri(String), } @@ -609,10 +609,10 @@ fn ext_tag(i: &[u8]) -> IResult<&[u8], ExtTag> { )(i) } -fn comment_tag(i: &[u8]) -> IResult<&[u8], String> { +fn comment_tag(i: &[u8]) -> IResult<&[u8], Option> { map( pair( - preceded(char('#'), map_res(is_not("\r\n"), from_utf8_slice)), + preceded(char('#'), opt(map_res(is_not("\r\n"), from_utf8_slice))), take(1usize), ), |(text, _)| text, @@ -929,7 +929,7 @@ mod tests { fn comment() { assert_eq!( comment_tag(b"#Hello\nxxx"), - Result::Ok(("xxx".as_bytes(), "Hello".to_string())) + Result::Ok(("xxx".as_bytes(), Some("Hello".to_string()))) ); }