rust: add nom7 combinator take_until_and_consume

pull/6705/head
Pierre Chifflier 3 years ago committed by Victor Julien
parent e4b5239202
commit 90f9450971

@ -1,6 +1,27 @@
use std::ffi::CString;
use std::os::raw::c_char;
pub mod nom7 {
use nom7::bytes::streaming::{tag, take_until};
use nom7::error::ParseError;
use nom7::IResult;
/// Reimplementation of `take_until_and_consume` for nom 7
///
/// `take_until` does not consume the matched tag, and
/// `take_until_and_consume` was removed in nom 7. This function
/// provides an implementation (specialized for `&[u8]`).
pub fn take_until_and_consume<'a, E: ParseError<&'a [u8]>>(t: &'a [u8])
-> impl Fn(&'a [u8]) -> IResult<&'a [u8], &'a [u8], E>
{
move |i: &'a [u8]| {
let (i, res) = take_until(t)(i)?;
let (i, _) = tag(t)(i)?;
Ok((i, res))
}
}
}
#[macro_export]
macro_rules! take_until_and_consume (
( $i:expr, $needle:expr ) => (

Loading…
Cancel
Save