nom::filter!
[−]
[src]
macro_rules! filter( ($input:expr, $submac:ident!( $($args:tt)* )) => ( { let mut index = 0; let mut found = false; for idx in 0..$input.len() { index = idx; if !$submac!($input[idx], $($args)*) { found = true; break; } } if index == 0 { $crate::IResult::Error($crate::Err::Position($crate::ErrorCode::Filter as u32,$input)) } else if found { $crate::IResult::Done(&$input[index..], &$input[0..index]) } else { $crate::IResult::Done(&b""[..], $input) } } ); ($input:expr, $f:expr) => ( filter!($input, call!($f)); ); );
filter!(&[T] -> bool) => &[T] -> IResult<&[T], &[T]>
returns the longest list of bytes until the provided function fails.
The argument is either a function &[T] -> bool
or a macro returning a `bool
named!( alpha, filter!( is_alphanumeric ) ); let r = alpha(&b"abcd\nefgh"[..]); assert_eq!(r, Done(&b"\nefgh"[..], &b"abcd"[..]));