pub fn take_till<T, Input, Error: ParseError<Input>, const STREAMING: bool>(
list: T
) -> impl Fn(Input) -> IResult<Input, <Input as IntoOutput>::Output, Error>where
Input: InputTakeAtPosition + InputIsStreaming<STREAMING> + IntoOutput,
T: FindToken<<Input as InputTakeAtPosition>::Item>,
Expand description
Returns the longest input slice (if any) till a pattern is met.
Streaming version will return a Err::Incomplete(Needed::new(1))
if the match reaches the
end of input or if there was not match.
Example
use nom8::bytes::take_till;
fn till_colon(s: &str) -> IResult<&str, &str> {
take_till(|c| c == ':')(s)
}
assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
assert_eq!(till_colon(":empty matched"), Ok((":empty matched", ""))); //allowed
assert_eq!(till_colon("12345"), Ok(("", "12345")));
assert_eq!(till_colon(""), Ok(("", "")));
use nom8::bytes::take_till;
fn till_colon(s: Streaming<&str>) -> IResult<Streaming<&str>, &str> {
take_till(|c| c == ':')(s)
}
assert_eq!(till_colon(Streaming("latin:123")), Ok((Streaming(":123"), "latin")));
assert_eq!(till_colon(Streaming(":empty matched")), Ok((Streaming(":empty matched"), ""))); //allowed
assert_eq!(till_colon(Streaming("12345")), Err(Err::Incomplete(Needed::new(1))));
assert_eq!(till_colon(Streaming("")), Err(Err::Incomplete(Needed::new(1))));