Function winnow::character::line_ending
source · pub fn line_ending<I, E: ParseError<I>>(
input: I
) -> IResult<I, <I as Stream>::Slice, E>where
I: StreamIsPartial + Stream + Compare<&'static str>,
Expand description
Recognizes an end of line (both ‘\n’ and ‘\r\n’).
Complete version: Will return an error if there’s not enough input data.
Partial version: Will return Err(winnow::error::ErrMode::Incomplete(_))
if there’s not enough input data.
Example
fn parser(input: &str) -> IResult<&str, &str> {
line_ending(input)
}
assert_eq!(parser("\r\nc"), Ok(("c", "\r\n")));
assert_eq!(parser("ab\r\nc"), Err(ErrMode::Backtrack(Error::new("ab\r\nc", ErrorKind::Tag))));
assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
assert_eq!(line_ending::<_, Error<_>>(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
assert_eq!(line_ending::<_, Error<_>>(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
assert_eq!(line_ending::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));