oni_comb_parser/text/
take_while0.rs1use crate::error::ParseError;
2use crate::fail::PResult;
3use crate::parser::Parser;
4use crate::str_input::StrInput;
5
6pub struct TakeWhile0<F>(F);
7
8pub fn take_while0<F: FnMut(char) -> bool>(f: F) -> TakeWhile0<F> {
9 TakeWhile0(f)
10}
11
12impl<'a, F> Parser<StrInput<'a>> for TakeWhile0<F>
13where
14 F: FnMut(char) -> bool,
15{
16 type Error = ParseError;
17 type Output = &'a str;
18
19 #[inline]
20 fn parse_next(&mut self, input: &mut StrInput<'a>) -> PResult<&'a str, ParseError> {
21 let remaining = input.as_str();
22 let mut consumed = 0;
23 for c in remaining.chars() {
24 if (self.0)(c) {
25 consumed += c.len_utf8();
26 } else {
27 break;
28 }
29 }
30 input.advance(consumed);
31 Ok(&remaining[..consumed])
32 }
33}