nom::is_a!
[−]
[src]
macro_rules! is_a( ($input:expr, $arr:expr) => ( { #[inline(always)] fn as_bytes<T: $crate::AsBytes>(b: &T) -> &[u8] { b.as_bytes() } let expected = $arr; let bytes = as_bytes(&expected); let mut index = 0; for idx in 0..$input.len() { index = idx; let mut cont = false; for &i in bytes.iter() { if $input[idx] == i { cont = true; break; } } if !cont { break; } } if index == 0 { $crate::IResult::Error($crate::Err::Position($crate::ErrorCode::IsA as u32,$input)) } else { $crate::IResult::Done(&$input[index..], &$input[0..index]) } } ); );
is_a!(&[T]) => &[T] -> IResult<&[T], &[T]>
returns the longest list of bytes that appear in the provided array
named!(abcd, is_a!( "abcd" )); let r1 = abcd(&b"aaaaefgh"[..]); assert_eq!(r1, Done(&b"efgh"[..], &b"aaaa"[..])); let r2 = abcd(&b"dcbaefgh"[..]); assert_eq!(r2, Done(&b"efgh"[..], &b"dcba"[..]));