Function nom8::character::line_ending
source · pub fn line_ending<T, E: ParseError<T>, const STREAMING: bool>(
input: T
) -> IResult<T, <T as IntoOutput>::Output, E>where
T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + InputIter + InputLength + InputIsStreaming<STREAMING> + IntoOutput + 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.
Streaming version: Will return Err(nom8::Err::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(Err::Error(Error::new("ab\r\nc", ErrorKind::CrLf))));
assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::CrLf))));
assert_eq!(line_ending::<_, (_, ErrorKind), true>(Streaming("\r\nc")), Ok((Streaming("c"), "\r\n")));
assert_eq!(line_ending::<_, (_, ErrorKind), true>(Streaming("ab\r\nc")), Err(Err::Error((Streaming("ab\r\nc"), ErrorKind::CrLf))));
assert_eq!(line_ending::<_, (_, ErrorKind), true>(Streaming("")), Err(Err::Incomplete(Needed::new(1))));