Function nom::bytes::complete::take_until[][src]

pub fn take_until<T, Input, Error: ParseError<Input>>(
    tag: T
) -> impl Fn(Input) -> IResult<Input, Input, Error> where
    Input: InputTake + FindSubstring<T>,
    T: InputLength + Clone
Expand description

Returns the input slice up to the first occurrence of the pattern.

It doesn’t consume the pattern. It will return Err(Err::Error((_, ErrorKind::TakeUntil))) if the pattern wasn’t met.


use nom::bytes::complete::take_until;

fn until_eof(s: &str) -> IResult<&str, &str> {

assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
assert_eq!(until_eof("hello, world"), Err(Err::Error(Error::new("hello, world", ErrorKind::TakeUntil))));
assert_eq!(until_eof(""), Err(Err::Error(Error::new("", ErrorKind::TakeUntil))));
assert_eq!(until_eof("1eof2eof"), Ok(("eof2eof", "1")));