From: Pierre Chifflier Date: Fri, 12 Nov 2021 12:45:40 +0000 (+0100) Subject: rust: add nom7 combinator take_until_and_consume X-Git-Tag: suricata-7.0.0-beta1~1119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90f9450971596c043c6834f11838c502a4fa42ea;p=thirdparty%2Fsuricata.git rust: add nom7 combinator take_until_and_consume --- diff --git a/rust/src/common.rs b/rust/src/common.rs index 1d28ba5f0a..71eaad728f 100644 --- a/rust/src/common.rs +++ b/rust/src/common.rs @@ -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 ) => (