Function take_while1

fn take_while1<F, I, Error: ParseError<I>>(cond: F) -> impl FnMut(I) -> crate::internal::IResult<I, I, Error>
where
    I: Input,
    F: Fn(<I as Input>::Item) -> bool

Returns the longest (at least 1) input slice that matches the predicate.

The parser will return the longest slice that matches the given predicate (a function that takes the input and returns a bool).

It will return an Err(Err::Error((_, ErrorKind::TakeWhile1))) if the pattern wasn't met.

Streaming Specific

Streaming version will return a Err::Incomplete(Needed::new(1)) or if the pattern reaches the end of the input.

Example

# use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
use nom::bytes::streaming::take_while1;
use nom::AsChar;

fn alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
  take_while1(AsChar::is_alpha)(s)
}

assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
assert_eq!(alpha(b"latin"), Err(Err::Incomplete(Needed::new(1))));
assert_eq!(alpha(b"12345"), Err(Err::Error(Error::new(&b"12345"[..], ErrorKind::TakeWhile1))));