Function winnow::character::not_line_ending
source · pub fn not_line_ending<I, E: ParseError<I>>(
input: I
) -> IResult<I, <I as Stream>::Slice, E>where
I: StreamIsPartial + Stream + AsBStr + Compare<&'static str>,
<I as Stream>::Token: AsChar,
Expand description
Recognizes a string of any char except ‘\r\n’ or ‘\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> {
not_line_ending(input)
}
assert_eq!(parser("ab\r\nc"), Ok(("\r\nc", "ab")));
assert_eq!(parser("ab\nc"), Ok(("\nc", "ab")));
assert_eq!(parser("abc"), Ok(("", "abc")));
assert_eq!(parser(""), Ok(("", "")));
assert_eq!(parser("a\rb\nc"), Err(ErrMode::Backtrack(Error { input: "a\rb\nc", kind: ErrorKind::Tag })));
assert_eq!(parser("a\rbc"), Err(ErrMode::Backtrack(Error { input: "a\rbc", kind: ErrorKind::Tag })));
assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("ab\r\nc")), Ok((Partial::new("\r\nc"), "ab")));
assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("abc")), Err(ErrMode::Incomplete(Needed::Unknown)));
assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("a\rb\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("a\rb\nc"), ErrorKind::Tag ))));
assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("a\rbc")), Err(ErrMode::Backtrack(Error::new(Partial::new("a\rbc"), ErrorKind::Tag ))));