Function winnow::ascii::till_line_ending
source · pub fn till_line_ending<Input, Error>(
input: &mut Input
) -> PResult<<Input as Stream>::Slice, Error>
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][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 till_line_ending<'i>(input: &mut &'i str) -> PResult<&'i str>
Example
fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
till_line_ending.parse_next(input)
}
assert_eq!(parser.parse_peek("ab\r\nc"), Ok(("\r\nc", "ab")));
assert_eq!(parser.parse_peek("ab\nc"), Ok(("\nc", "ab")));
assert_eq!(parser.parse_peek("abc"), Ok(("", "abc")));
assert_eq!(parser.parse_peek(""), Ok(("", "")));
assert_eq!(parser.parse_peek("a\rb\nc"), Err(ErrMode::Backtrack(InputError::new("\rb\nc", ErrorKind::Tag ))));
assert_eq!(parser.parse_peek("a\rbc"), Err(ErrMode::Backtrack(InputError::new("\rbc", ErrorKind::Tag ))));
assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Ok((Partial::new("\r\nc"), "ab")));
assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("abc")), Err(ErrMode::Incomplete(Needed::Unknown)));
assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rb\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rb\nc"), ErrorKind::Tag ))));
assert_eq!(till_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rbc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rbc"), ErrorKind::Tag ))));