Function winnow::ascii::line_ending
source · pub fn line_ending<Input, Error>(
input: &mut Input,
) -> PResult<<Input as Stream>::Slice, Error>
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][crate::_topic::partial]: Will return Err(winnow::error::ErrMode::Incomplete(_))
if there’s not enough input data.
§Effective Signature
Assuming you are parsing a &str
Stream:
pub fn line_ending<'i>(input: &mut &'i str) -> PResult<&'i str>
§Example
fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
line_ending.parse_next(input)
}
assert_eq!(parser.parse_peek("\r\nc"), Ok(("c", "\r\n")));
assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Tag))));
assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));