Function winnow::bytes::take_until0
source · pub fn take_until0<T, I, Error: ParseError<I>>(
tag: T
) -> impl Parser<I, <I as Stream>::Slice, Error>where
I: StreamIsPartial + Stream + FindSlice<T>,
T: SliceLen + Clone,
Expand description
Recognize the input slice up to the first occurrence of the literal.
It doesn’t consume the pattern.
Complete version: It will return Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))
if the pattern wasn’t met.
Partial version: will return a ErrMode::Incomplete(Needed::new(N))
if the input doesn’t
contain the pattern or if the input is smaller than the pattern.
Example
use winnow::bytes::take_until0;
fn until_eof(s: &str) -> IResult<&str, &str> {
take_until0("eof").parse_next(s)
}
assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(Error::new("hello, world", ErrorKind::Slice))));
assert_eq!(until_eof(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
assert_eq!(until_eof("1eof2eof"), Ok(("eof2eof", "1")));
use winnow::bytes::take_until0;
fn until_eof(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
take_until0("eof").parse_next(s)
}
assert_eq!(until_eof(Partial::new("hello, worldeof")), Ok((Partial::new("eof"), "hello, world")));
assert_eq!(until_eof(Partial::new("hello, world")), Err(ErrMode::Incomplete(Needed::Unknown)));
assert_eq!(until_eof(Partial::new("hello, worldeo")), Err(ErrMode::Incomplete(Needed::Unknown)));
assert_eq!(until_eof(Partial::new("1eof2eof")), Ok((Partial::new("eof2eof"), "1")));