Coverage Report

Created: 2026-06-30 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/nom-8.0.0/src/multi/mod.rs
Line
Count
Source
1
//! Combinators applying their child parser multiple times
2
3
#[cfg(test)]
4
mod tests;
5
6
use core::marker::PhantomData;
7
8
use crate::bytes::take;
9
use crate::error::ErrorKind;
10
use crate::error::ParseError;
11
use crate::internal::{Err, Needed, Parser};
12
use crate::lib::std::num::NonZeroUsize;
13
#[cfg(feature = "alloc")]
14
use crate::lib::std::vec::Vec;
15
use crate::traits::ToUsize;
16
use crate::Check;
17
use crate::Emit;
18
use crate::Input;
19
use crate::Mode;
20
use crate::NomRange;
21
use crate::OutputM;
22
use crate::OutputMode;
23
24
/// Don't pre-allocate more than 64KiB when calling `Vec::with_capacity`.
25
///
26
/// Pre-allocating memory is a nice optimization but count fields can't
27
/// always be trusted. We should clamp initial capacities to some reasonable
28
/// amount. This reduces the risk of a bogus count value triggering a panic
29
/// due to an OOM error.
30
///
31
/// This does not affect correctness. Nom will always read the full number
32
/// of elements regardless of the capacity cap.
33
#[cfg(feature = "alloc")]
34
const MAX_INITIAL_CAPACITY_BYTES: usize = 65536;
35
36
/// Repeats the embedded parser, gathering the results in a `Vec`.
37
///
38
/// This stops on [`Err::Error`] and returns the results that were accumulated. To instead chain an error up, see
39
/// [`cut`][crate::combinator::cut].
40
///
41
/// # Arguments
42
/// * `f` The parser to apply.
43
///
44
/// *Note*: if the parser passed in accepts empty inputs (like `alpha0` or `digit0`), `many0` will
45
/// return an error, to prevent going into an infinite loop
46
///
47
/// ```rust
48
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
49
/// use nom::multi::many0;
50
/// use nom::bytes::complete::tag;
51
///
52
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
53
///   many0(tag("abc")).parse(s)
54
/// }
55
///
56
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
57
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
58
/// assert_eq!(parser("123123"), Ok(("123123", vec![])));
59
/// assert_eq!(parser(""), Ok(("", vec![])));
60
/// ```
61
#[cfg(feature = "alloc")]
62
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
63
3.21M
pub fn many0<I, F>(
64
3.21M
  f: F,
65
3.21M
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
3.21M
where
67
3.21M
  I: Clone + Input,
68
3.21M
  F: Parser<I>,
69
{
70
3.21M
  Many0 { parser: f }
71
3.21M
}
nom::multi::many0::<&[u8], nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::branch::Choice<(nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0})>, core::str::converts::from_utf8>, nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::character::complete::digit1<&[u8], nom::error::Error<&[u8]>>, core::str::converts::from_utf8>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>>
Line
Count
Source
63
168k
pub fn many0<I, F>(
64
168k
  f: F,
65
168k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
168k
where
67
168k
  I: Clone + Input,
68
168k
  F: Parser<I>,
69
{
70
168k
  Many0 { parser: f }
71
168k
}
nom::multi::many0::<&[u8], nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::bytes::complete::take_while<suricata::sdp::parser::parse_attributes::{closure#0}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>, nom::combinator::Opt<nom::sequence::Preceded<nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::bytes::complete::take_till<suricata::sdp::parser::is_line_ending, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>>
Line
Count
Source
63
126k
pub fn many0<I, F>(
64
126k
  f: F,
65
126k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
126k
where
67
126k
  I: Clone + Input,
68
126k
  F: Parser<I>,
69
{
70
126k
  Many0 { parser: f }
71
126k
}
nom::multi::many0::<&[u8], suricata::sdp::parser::parse_media_description>
Line
Count
Source
63
30.1k
pub fn many0<I, F>(
64
30.1k
  f: F,
65
30.1k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
30.1k
where
67
30.1k
  I: Clone + Input,
68
30.1k
  F: Parser<I>,
69
{
70
30.1k
  Many0 { parser: f }
71
30.1k
}
nom::multi::many0::<&[u8], nom::combinator::MakeComplete<nom::number::streaming::be_u8<&[u8], nom::error::Error<&[u8]>>>>
Line
Count
Source
63
116k
pub fn many0<I, F>(
64
116k
  f: F,
65
116k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
116k
where
67
116k
  I: Clone + Input,
68
116k
  F: Parser<I>,
69
{
70
116k
  Many0 { parser: f }
71
116k
}
nom::multi::many0::<&[u8], nom::combinator::MakeComplete<suricata::mqtt::parser::parse_mqtt_string>>
Line
Count
Source
63
230k
pub fn many0<I, F>(
64
230k
  f: F,
65
230k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
230k
where
67
230k
  I: Clone + Input,
68
230k
  F: Parser<I>,
69
{
70
230k
  Many0 { parser: f }
71
230k
}
nom::multi::many0::<&[u8], nom::combinator::MakeComplete<suricata::ike::parser::parse_sa_attribute::parse_attribute>>
Line
Count
Source
63
618k
pub fn many0<I, F>(
64
618k
  f: F,
65
618k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
618k
where
67
618k
  I: Clone + Input,
68
618k
  F: Parser<I>,
69
{
70
618k
  Many0 { parser: f }
71
618k
}
nom::multi::many0::<&[u8], nom::combinator::MakeComplete<suricata::ike::parser::parse_ikev1_payload_list::parse_payload>>
Line
Count
Source
63
171k
pub fn many0<I, F>(
64
171k
  f: F,
65
171k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
171k
where
67
171k
  I: Clone + Input,
68
171k
  F: Parser<I>,
69
{
70
171k
  Many0 { parser: f }
71
171k
}
nom::multi::many0::<&[u8], nom::combinator::MakeComplete<<suricata::quic::frames::Frame>::decode_frame>>
Line
Count
Source
63
1.22M
pub fn many0<I, F>(
64
1.22M
  f: F,
65
1.22M
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
1.22M
where
67
1.22M
  I: Clone + Input,
68
1.22M
  F: Parser<I>,
69
{
70
1.22M
  Many0 { parser: f }
71
1.22M
}
nom::multi::many0::<&[u8], suricata::bittorrent_dht::parser::parse_node>
Line
Count
Source
63
7.21k
pub fn many0<I, F>(
64
7.21k
  f: F,
65
7.21k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
7.21k
where
67
7.21k
  I: Clone + Input,
68
7.21k
  F: Parser<I>,
69
{
70
7.21k
  Many0 { parser: f }
71
7.21k
}
nom::multi::many0::<&[u8], suricata::bittorrent_dht::parser::parse_node6>
Line
Count
Source
63
1.34k
pub fn many0<I, F>(
64
1.34k
  f: F,
65
1.34k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
1.34k
where
67
1.34k
  I: Clone + Input,
68
1.34k
  F: Parser<I>,
69
{
70
1.34k
  Many0 { parser: f }
71
1.34k
}
nom::multi::many0::<&[u8], nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}>
Line
Count
Source
63
517k
pub fn many0<I, F>(
64
517k
  f: F,
65
517k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
66
517k
where
67
517k
  I: Clone + Input,
68
517k
  F: Parser<I>,
69
{
70
517k
  Many0 { parser: f }
71
517k
}
Unexecuted instantiation: nom::multi::many0::<_, _>
72
73
#[cfg(feature = "alloc")]
74
/// Parser implementation for the [many0] combinator
75
pub struct Many0<F> {
76
  parser: F,
77
}
78
79
#[cfg(feature = "alloc")]
80
impl<I, F> Parser<I> for Many0<F>
81
where
82
  I: Clone + Input,
83
  F: Parser<I>,
84
{
85
  type Output = crate::lib::std::vec::Vec<<F as Parser<I>>::Output>;
86
  type Error = <F as Parser<I>>::Error;
87
88
2.98M
  fn process<OM: OutputMode>(
89
2.98M
    &mut self,
90
2.98M
    mut i: I,
91
2.98M
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
2.98M
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<nom::combinator::MakeComplete<nom::number::streaming::be_u8<&[u8], nom::error::Error<&[u8]>>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
116k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<nom::combinator::MakeComplete<<suricata::quic::frames::Frame>::decode_frame>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
1.22M
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_mqtt_string>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
230k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::ike::parser::parse_sa_attribute::parse_attribute>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
618k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::ike::parser::parse_ikev1_payload_list::parse_payload>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
171k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::branch::Choice<(nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0})>, core::str::converts::from_utf8>, nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::character::complete::digit1<&[u8], nom::error::Error<&[u8]>>, core::str::converts::from_utf8>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
168k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::bytes::complete::take_while<suricata::sdp::parser::parse_attributes::{closure#0}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>, nom::combinator::Opt<nom::sequence::Preceded<nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::bytes::complete::take_till<suricata::sdp::parser::is_line_ending, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
126k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<suricata::bittorrent_dht::parser::parse_node> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
7.20k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<suricata::bittorrent_dht::parser::parse_node6> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
1.34k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<suricata::sdp::parser::parse_media_description> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
30.1k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
<nom::multi::Many0<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
92
286k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
Unexecuted instantiation: <nom::multi::Many0<_> as nom::internal::Parser<_>>::process::<_>::{closure#0}
93
    loop {
94
12.0M
      let len = i.input_len();
95
12.0M
      match self
96
12.0M
        .parser
97
12.0M
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
2.98M
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
9.08M
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
9.08M
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
0
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
0
            })));
Unexecuted instantiation: <nom::multi::Many0<nom::combinator::MakeComplete<nom::number::streaming::be_u8<&[u8], nom::error::Error<&[u8]>>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<nom::combinator::MakeComplete<<suricata::quic::frames::Frame>::decode_frame>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_mqtt_string>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<nom::combinator::MakeComplete<suricata::ike::parser::parse_sa_attribute::parse_attribute>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<nom::combinator::MakeComplete<suricata::ike::parser::parse_ikev1_payload_list::parse_payload>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::branch::Choice<(nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0})>, core::str::converts::from_utf8>, nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::character::complete::digit1<&[u8], nom::error::Error<&[u8]>>, core::str::converts::from_utf8>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::bytes::complete::take_while<suricata::sdp::parser::parse_attributes::{closure#0}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>, nom::combinator::Opt<nom::sequence::Preceded<nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::bytes::complete::take_till<suricata::sdp::parser::is_line_ending, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<suricata::bittorrent_dht::parser::parse_node> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<suricata::bittorrent_dht::parser::parse_node6> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many0<_> as nom::internal::Parser<_>>::process::<_>::{closure#1}
108
9.08M
          }
109
110
9.08M
          i = i1;
111
112
9.08M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
9.08M
            acc.push(o);
114
9.08M
            acc
115
9.08M
          })
<nom::multi::Many0<nom::combinator::MakeComplete<nom::number::streaming::be_u8<&[u8], nom::error::Error<&[u8]>>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
1.66M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
1.66M
            acc.push(o);
114
1.66M
            acc
115
1.66M
          })
<nom::multi::Many0<nom::combinator::MakeComplete<<suricata::quic::frames::Frame>::decode_frame>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
440k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
440k
            acc.push(o);
114
440k
            acc
115
440k
          })
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_mqtt_string>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
476k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
476k
            acc.push(o);
114
476k
            acc
115
476k
          })
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::ike::parser::parse_sa_attribute::parse_attribute>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
349k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
349k
            acc.push(o);
114
349k
            acc
115
349k
          })
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::ike::parser::parse_ikev1_payload_list::parse_payload>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
2.70M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
2.70M
            acc.push(o);
114
2.70M
            acc
115
2.70M
          })
<nom::multi::Many0<nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::branch::Choice<(nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0})>, core::str::converts::from_utf8>, nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::character::complete::digit1<&[u8], nom::error::Error<&[u8]>>, core::str::converts::from_utf8>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
1.08M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
1.08M
            acc.push(o);
114
1.08M
            acc
115
1.08M
          })
<nom::multi::Many0<nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::bytes::complete::take_while<suricata::sdp::parser::parse_attributes::{closure#0}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>, nom::combinator::Opt<nom::sequence::Preceded<nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::bytes::complete::take_till<suricata::sdp::parser::is_line_ending, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
2.16M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
2.16M
            acc.push(o);
114
2.16M
            acc
115
2.16M
          })
<nom::multi::Many0<suricata::bittorrent_dht::parser::parse_node> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
54.7k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
54.7k
            acc.push(o);
114
54.7k
            acc
115
54.7k
          })
<nom::multi::Many0<suricata::bittorrent_dht::parser::parse_node6> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
28.9k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
28.9k
            acc.push(o);
114
28.9k
            acc
115
28.9k
          })
<nom::multi::Many0<suricata::sdp::parser::parse_media_description> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
95.0k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
95.0k
            acc.push(o);
114
95.0k
            acc
115
95.0k
          })
<nom::multi::Many0<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
112
16.6k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
16.6k
            acc.push(o);
114
16.6k
            acc
115
16.6k
          })
Unexecuted instantiation: <nom::multi::Many0<_> as nom::internal::Parser<_>>::process::<_>::{closure#2}
116
        }
117
      }
118
    }
119
2.98M
  }
<nom::multi::Many0<nom::combinator::MakeComplete<nom::number::streaming::be_u8<&[u8], nom::error::Error<&[u8]>>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
116k
  fn process<OM: OutputMode>(
89
116k
    &mut self,
90
116k
    mut i: I,
91
116k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
116k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
1.78M
      let len = i.input_len();
95
1.78M
      match self
96
1.78M
        .parser
97
1.78M
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
116k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
1.66M
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
1.66M
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
1.66M
          }
109
110
1.66M
          i = i1;
111
112
1.66M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
116k
  }
<nom::multi::Many0<nom::combinator::MakeComplete<<suricata::quic::frames::Frame>::decode_frame>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
1.22M
  fn process<OM: OutputMode>(
89
1.22M
    &mut self,
90
1.22M
    mut i: I,
91
1.22M
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
1.22M
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
1.66M
      let len = i.input_len();
95
1.66M
      match self
96
1.66M
        .parser
97
1.66M
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
1.22M
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
440k
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
440k
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
440k
          }
109
110
440k
          i = i1;
111
112
440k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
1.22M
  }
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_mqtt_string>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
230k
  fn process<OM: OutputMode>(
89
230k
    &mut self,
90
230k
    mut i: I,
91
230k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
230k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
707k
      let len = i.input_len();
95
707k
      match self
96
707k
        .parser
97
707k
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
230k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
476k
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
476k
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
476k
          }
109
110
476k
          i = i1;
111
112
476k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
230k
  }
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::ike::parser::parse_sa_attribute::parse_attribute>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
618k
  fn process<OM: OutputMode>(
89
618k
    &mut self,
90
618k
    mut i: I,
91
618k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
618k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
968k
      let len = i.input_len();
95
968k
      match self
96
968k
        .parser
97
968k
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
618k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
349k
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
349k
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
349k
          }
109
110
349k
          i = i1;
111
112
349k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
618k
  }
<nom::multi::Many0<nom::combinator::MakeComplete<suricata::ike::parser::parse_ikev1_payload_list::parse_payload>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
171k
  fn process<OM: OutputMode>(
89
171k
    &mut self,
90
171k
    mut i: I,
91
171k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
171k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
2.87M
      let len = i.input_len();
95
2.87M
      match self
96
2.87M
        .parser
97
2.87M
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
171k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
2.70M
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
2.70M
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
2.70M
          }
109
110
2.70M
          i = i1;
111
112
2.70M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
171k
  }
<nom::multi::Many0<nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::branch::Choice<(nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0})>, core::str::converts::from_utf8>, nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::character::complete::digit1<&[u8], nom::error::Error<&[u8]>>, core::str::converts::from_utf8>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
168k
  fn process<OM: OutputMode>(
89
168k
    &mut self,
90
168k
    mut i: I,
91
168k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
168k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
1.25M
      let len = i.input_len();
95
1.25M
      match self
96
1.25M
        .parser
97
1.25M
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
168k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
1.08M
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
1.08M
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
1.08M
          }
109
110
1.08M
          i = i1;
111
112
1.08M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
168k
  }
<nom::multi::Many0<nom::sequence::Preceded<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}, (nom::internal::MapRes<nom::bytes::complete::take_while<suricata::sdp::parser::parse_attributes::{closure#0}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>, nom::combinator::Opt<nom::sequence::Preceded<nom::character::complete::char<&[u8], nom::error::Error<&[u8]>>::{closure#0}, nom::internal::MapRes<nom::bytes::complete::take_till<suricata::sdp::parser::is_line_ending, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>>, nom::character::complete::line_ending<&[u8], nom::error::Error<&[u8]>>)>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
126k
  fn process<OM: OutputMode>(
89
126k
    &mut self,
90
126k
    mut i: I,
91
126k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
126k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
2.29M
      let len = i.input_len();
95
2.29M
      match self
96
2.29M
        .parser
97
2.29M
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
126k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
2.16M
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
2.16M
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
2.16M
          }
109
110
2.16M
          i = i1;
111
112
2.16M
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
126k
  }
<nom::multi::Many0<suricata::bittorrent_dht::parser::parse_node> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
7.20k
  fn process<OM: OutputMode>(
89
7.20k
    &mut self,
90
7.20k
    mut i: I,
91
7.20k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
7.20k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
61.9k
      let len = i.input_len();
95
61.9k
      match self
96
61.9k
        .parser
97
61.9k
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
7.20k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
54.7k
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
54.7k
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
54.7k
          }
109
110
54.7k
          i = i1;
111
112
54.7k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
7.20k
  }
<nom::multi::Many0<suricata::bittorrent_dht::parser::parse_node6> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
1.34k
  fn process<OM: OutputMode>(
89
1.34k
    &mut self,
90
1.34k
    mut i: I,
91
1.34k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
1.34k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
30.2k
      let len = i.input_len();
95
30.2k
      match self
96
30.2k
        .parser
97
30.2k
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
1.34k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
28.9k
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
28.9k
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
28.9k
          }
109
110
28.9k
          i = i1;
111
112
28.9k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
1.34k
  }
<nom::multi::Many0<suricata::sdp::parser::parse_media_description> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>
Line
Count
Source
88
30.1k
  fn process<OM: OutputMode>(
89
30.1k
    &mut self,
90
30.1k
    mut i: I,
91
30.1k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
30.1k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
125k
      let len = i.input_len();
95
125k
      match self
96
125k
        .parser
97
125k
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
30.1k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
95.0k
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
95.0k
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
95.0k
          }
109
110
95.0k
          i = i1;
111
112
95.0k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
30.1k
  }
<nom::multi::Many0<nom::bytes::complete::tag<&str, &[u8], nom::error::Error<&[u8]>>::{closure#0}> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
88
286k
  fn process<OM: OutputMode>(
89
286k
    &mut self,
90
286k
    mut i: I,
91
286k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
92
286k
    let mut acc = OM::Output::bind(|| crate::lib::std::vec::Vec::with_capacity(4));
93
    loop {
94
303k
      let len = i.input_len();
95
303k
      match self
96
303k
        .parser
97
303k
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
98
      {
99
286k
        Err(Err::Error(_)) => return Ok((i, acc)),
100
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
101
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
102
16.6k
        Ok((i1, o)) => {
103
          // infinite loop check: the parser must always consume
104
16.6k
          if i1.input_len() == len {
105
0
            return Err(Err::Error(OM::Error::bind(|| {
106
              <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
107
            })));
108
16.6k
          }
109
110
16.6k
          i = i1;
111
112
16.6k
          acc = OM::Output::combine(acc, o, |mut acc, o| {
113
            acc.push(o);
114
            acc
115
          })
116
        }
117
      }
118
    }
119
286k
  }
Unexecuted instantiation: <nom::multi::Many0<_> as nom::internal::Parser<_>>::process::<_>
120
}
121
122
/// Runs the embedded parser, gathering the results in a `Vec`.
123
///
124
/// This stops on [`Err::Error`] if there is at least one result,  and returns the results that were accumulated. To instead chain an error up,
125
/// see [`cut`][crate::combinator::cut].
126
///
127
/// # Arguments
128
/// * `f` The parser to apply.
129
///
130
/// *Note*: If the parser passed to `many1` accepts empty inputs
131
/// (like `alpha0` or `digit0`), `many1` will return an error,
132
/// to prevent going into an infinite loop.
133
///
134
/// ```rust
135
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
136
/// use nom::multi::many1;
137
/// use nom::bytes::complete::tag;
138
///
139
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
140
///   many1(tag("abc")).parse(s)
141
/// }
142
///
143
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
144
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
145
/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Tag))));
146
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
147
/// ```
148
#[cfg(feature = "alloc")]
149
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
150
542k
pub fn many1<I, F>(
151
542k
  parser: F,
152
542k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
542k
where
154
542k
  I: Clone + Input,
155
542k
  F: Parser<I>,
156
{
157
542k
  Many1 { parser }
158
542k
}
nom::multi::many1::<&[u8], nom::sequence::Preceded<nom::character::complete::space1<&[u8], nom::error::Error<&[u8]>>, nom::internal::MapRes<nom::bytes::complete::take_while_m_n<suricata::sdp::parser::parse_media_description::{closure#4}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>>
Line
Count
Source
150
98.8k
pub fn many1<I, F>(
151
98.8k
  parser: F,
152
98.8k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
98.8k
where
154
98.8k
  I: Clone + Input,
155
98.8k
  F: Parser<I>,
156
{
157
98.8k
  Many1 { parser }
158
98.8k
}
nom::multi::many1::<&[u8], suricata::sdp::parser::parse_time_description>
Line
Count
Source
150
71.6k
pub fn many1<I, F>(
151
71.6k
  parser: F,
152
71.6k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
71.6k
where
154
71.6k
  I: Clone + Input,
155
71.6k
  F: Parser<I>,
156
{
157
71.6k
  Many1 { parser }
158
71.6k
}
nom::multi::many1::<&str, (suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)>
Line
Count
Source
150
12.2k
pub fn many1<I, F>(
151
12.2k
  parser: F,
152
12.2k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
12.2k
where
154
12.2k
  I: Clone + Input,
155
12.2k
  F: Parser<I>,
156
{
157
12.2k
  Many1 { parser }
158
12.2k
}
nom::multi::many1::<&[u8], nom::combinator::MakeComplete<suricata::mqtt::parser::parse_subscribe_topic>>
Line
Count
Source
150
287k
pub fn many1<I, F>(
151
287k
  parser: F,
152
287k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
287k
where
154
287k
  I: Clone + Input,
155
287k
  F: Parser<I>,
156
{
157
287k
  Many1 { parser }
158
287k
}
nom::multi::many1::<&[u8], nom::combinator::MakeComplete<suricata::common::nom8::take_until_and_consume<nom::error::Error<&[u8]>>::{closure#0}>>
Line
Count
Source
150
22.0k
pub fn many1<I, F>(
151
22.0k
  parser: F,
152
22.0k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
22.0k
where
154
22.0k
  I: Clone + Input,
155
22.0k
  F: Parser<I>,
156
{
157
22.0k
  Many1 { parser }
158
22.0k
}
nom::multi::many1::<&[u8], suricata::pgsql::parser::parse_sasl_mechanism>
Line
Count
Source
150
12.5k
pub fn many1<I, F>(
151
12.5k
  parser: F,
152
12.5k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
12.5k
where
154
12.5k
  I: Clone + Input,
155
12.5k
  F: Parser<I>,
156
{
157
12.5k
  Many1 { parser }
158
12.5k
}
nom::multi::many1::<&[u8], suricata::pgsql::parser::pgsql_parse_generic_parameter>
Line
Count
Source
150
31.3k
pub fn many1<I, F>(
151
31.3k
  parser: F,
152
31.3k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
31.3k
where
154
31.3k
  I: Clone + Input,
155
31.3k
  F: Parser<I>,
156
{
157
31.3k
  Many1 { parser }
158
31.3k
}
nom::multi::many1::<&str, suricata::krb::detect::detect_parse_encryption_item>
Line
Count
Source
150
6.36k
pub fn many1<I, F>(
151
6.36k
  parser: F,
152
6.36k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
153
6.36k
where
154
6.36k
  I: Clone + Input,
155
6.36k
  F: Parser<I>,
156
{
157
6.36k
  Many1 { parser }
158
6.36k
}
Unexecuted instantiation: nom::multi::many1::<_, _>
159
160
#[cfg(feature = "alloc")]
161
/// Parser implementation for the [many1] combinator
162
pub struct Many1<F> {
163
  parser: F,
164
}
165
166
#[cfg(feature = "alloc")]
167
impl<I, F> Parser<I> for Many1<F>
168
where
169
  I: Clone + Input,
170
  F: Parser<I>,
171
{
172
  type Output = Vec<<F as Parser<I>>::Output>;
173
  type Error = <F as Parser<I>>::Error;
174
175
550k
  fn process<OM: OutputMode>(
176
550k
    &mut self,
177
550k
    mut i: I,
178
550k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
550k
    match self
180
550k
      .parser
181
550k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
54.1k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
51.0k
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
51.0k
      }))),
<nom::multi::Many1<nom::combinator::MakeComplete<suricata::common::nom8::take_until_and_consume<nom::error::Error<&[u8]>>::{closure#0}>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
183
3.43k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
3.43k
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
3.43k
      }))),
<nom::multi::Many1<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_subscribe_topic>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
183
169
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
169
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
169
      }))),
<nom::multi::Many1<nom::sequence::Preceded<nom::character::complete::space1<&[u8], nom::error::Error<&[u8]>>, nom::internal::MapRes<nom::bytes::complete::take_while_m_n<suricata::sdp::parser::parse_media_description::{closure#4}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
183
978
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
978
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
978
      }))),
<nom::multi::Many1<suricata::krb::detect::detect_parse_encryption_item> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
183
2.71k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
2.71k
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
2.71k
      }))),
<nom::multi::Many1<suricata::sdp::parser::parse_time_description> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
183
41.5k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
41.5k
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
41.5k
      }))),
<nom::multi::Many1<suricata::pgsql::parser::parse_sasl_mechanism> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
183
1.28k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
1.28k
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
1.28k
      }))),
<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
183
842
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
842
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
842
      }))),
Unexecuted instantiation: <nom::multi::Many1<_> as nom::internal::Parser<_>>::process::<_>::{closure#0}
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
868
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
495k
      Ok((i1, o)) => {
189
495k
        let mut acc = OM::Output::map(o, |o| {
190
495k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
495k
          acc.push(o);
192
495k
          acc
193
495k
        });
<nom::multi::Many1<nom::combinator::MakeComplete<suricata::common::nom8::take_until_and_consume<nom::error::Error<&[u8]>>::{closure#0}>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
18.5k
        let mut acc = OM::Output::map(o, |o| {
190
18.5k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
18.5k
          acc.push(o);
192
18.5k
          acc
193
18.5k
        });
<nom::multi::Many1<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_subscribe_topic>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
287k
        let mut acc = OM::Output::map(o, |o| {
190
287k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
287k
          acc.push(o);
192
287k
          acc
193
287k
        });
<nom::multi::Many1<nom::sequence::Preceded<nom::character::complete::space1<&[u8], nom::error::Error<&[u8]>>, nom::internal::MapRes<nom::bytes::complete::take_while_m_n<suricata::sdp::parser::parse_media_description::{closure#4}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
97.8k
        let mut acc = OM::Output::map(o, |o| {
190
97.8k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
97.8k
          acc.push(o);
192
97.8k
          acc
193
97.8k
        });
<nom::multi::Many1<suricata::krb::detect::detect_parse_encryption_item> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
3.65k
        let mut acc = OM::Output::map(o, |o| {
190
3.65k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
3.65k
          acc.push(o);
192
3.65k
          acc
193
3.65k
        });
<nom::multi::Many1<suricata::sdp::parser::parse_time_description> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
30.1k
        let mut acc = OM::Output::map(o, |o| {
190
30.1k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
30.1k
          acc.push(o);
192
30.1k
          acc
193
30.1k
        });
<nom::multi::Many1<suricata::pgsql::parser::parse_sasl_mechanism> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
11.2k
        let mut acc = OM::Output::map(o, |o| {
190
11.2k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
11.2k
          acc.push(o);
192
11.2k
          acc
193
11.2k
        });
<nom::multi::Many1<suricata::pgsql::parser::pgsql_parse_generic_parameter> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
29.7k
        let mut acc = OM::Output::map(o, |o| {
190
29.7k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
29.7k
          acc.push(o);
192
29.7k
          acc
193
29.7k
        });
<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
11.3k
        let mut acc = OM::Output::map(o, |o| {
190
11.3k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
11.3k
          acc.push(o);
192
11.3k
          acc
193
11.3k
        });
<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
189
5.70k
        let mut acc = OM::Output::map(o, |o| {
190
5.70k
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
5.70k
          acc.push(o);
192
5.70k
          acc
193
5.70k
        });
Unexecuted instantiation: <nom::multi::Many1<_> as nom::internal::Parser<_>>::process::<_>::{closure#1}
194
195
495k
        i = i1;
196
197
        loop {
198
8.70M
          let len = i.input_len();
199
8.70M
          match self
200
8.70M
            .parser
201
8.70M
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
487k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
8.04k
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
8.20M
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
8.20M
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
0
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
0
                })));
Unexecuted instantiation: <nom::multi::Many1<nom::combinator::MakeComplete<suricata::common::nom8::take_until_and_consume<nom::error::Error<&[u8]>>::{closure#0}>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Many1<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_subscribe_topic>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Many1<nom::sequence::Preceded<nom::character::complete::space1<&[u8], nom::error::Error<&[u8]>>, nom::internal::MapRes<nom::bytes::complete::take_while_m_n<suricata::sdp::parser::parse_media_description::{closure#4}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Many1<suricata::krb::detect::detect_parse_encryption_item> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Many1<suricata::sdp::parser::parse_time_description> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Many1<suricata::pgsql::parser::parse_sasl_mechanism> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Many1<_> as nom::internal::Parser<_>>::process::<_>::{closure#2}
212
8.20M
              }
213
214
8.20M
              i = i1;
215
216
8.20M
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
8.20M
                acc.push(o);
218
8.20M
                acc
219
8.20M
              })
<nom::multi::Many1<nom::combinator::MakeComplete<suricata::common::nom8::take_until_and_consume<nom::error::Error<&[u8]>>::{closure#0}>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
3.44M
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
3.44M
                acc.push(o);
218
3.44M
                acc
219
3.44M
              })
<nom::multi::Many1<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_subscribe_topic>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
191k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
191k
                acc.push(o);
218
191k
                acc
219
191k
              })
<nom::multi::Many1<nom::sequence::Preceded<nom::character::complete::space1<&[u8], nom::error::Error<&[u8]>>, nom::internal::MapRes<nom::bytes::complete::take_while_m_n<suricata::sdp::parser::parse_media_description::{closure#4}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
2.42M
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
2.42M
                acc.push(o);
218
2.42M
                acc
219
2.42M
              })
<nom::multi::Many1<suricata::krb::detect::detect_parse_encryption_item> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
35.4k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
35.4k
                acc.push(o);
218
35.4k
                acc
219
35.4k
              })
<nom::multi::Many1<suricata::sdp::parser::parse_time_description> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
356k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
356k
                acc.push(o);
218
356k
                acc
219
356k
              })
<nom::multi::Many1<suricata::pgsql::parser::parse_sasl_mechanism> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
2.74k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
2.74k
                acc.push(o);
218
2.74k
                acc
219
2.74k
              })
<nom::multi::Many1<suricata::pgsql::parser::pgsql_parse_generic_parameter> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
1.73M
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
1.73M
                acc.push(o);
218
1.73M
                acc
219
1.73M
              })
<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
3.15k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
3.15k
                acc.push(o);
218
3.15k
                acc
219
3.15k
              })
<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
216
5.79k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
5.79k
                acc.push(o);
218
5.79k
                acc
219
5.79k
              })
Unexecuted instantiation: <nom::multi::Many1<_> as nom::internal::Parser<_>>::process::<_>::{closure#3}
220
            }
221
          }
222
        }
223
      }
224
    }
225
550k
  }
<nom::multi::Many1<nom::combinator::MakeComplete<suricata::common::nom8::take_until_and_consume<nom::error::Error<&[u8]>>::{closure#0}>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
175
22.0k
  fn process<OM: OutputMode>(
176
22.0k
    &mut self,
177
22.0k
    mut i: I,
178
22.0k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
22.0k
    match self
180
22.0k
      .parser
181
22.0k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
3.43k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
18.5k
      Ok((i1, o)) => {
189
18.5k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
18.5k
        i = i1;
196
197
        loop {
198
3.46M
          let len = i.input_len();
199
3.46M
          match self
200
3.46M
            .parser
201
3.46M
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
18.5k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
3.44M
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
3.44M
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
3.44M
              }
213
214
3.44M
              i = i1;
215
216
3.44M
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
22.0k
  }
<nom::multi::Many1<nom::combinator::MakeComplete<suricata::mqtt::parser::parse_subscribe_topic>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
175
287k
  fn process<OM: OutputMode>(
176
287k
    &mut self,
177
287k
    mut i: I,
178
287k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
287k
    match self
180
287k
      .parser
181
287k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
169
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
287k
      Ok((i1, o)) => {
189
287k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
287k
        i = i1;
196
197
        loop {
198
479k
          let len = i.input_len();
199
479k
          match self
200
479k
            .parser
201
479k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
287k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
191k
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
191k
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
191k
              }
213
214
191k
              i = i1;
215
216
191k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
287k
  }
<nom::multi::Many1<nom::sequence::Preceded<nom::character::complete::space1<&[u8], nom::error::Error<&[u8]>>, nom::internal::MapRes<nom::bytes::complete::take_while_m_n<suricata::sdp::parser::parse_media_description::{closure#4}, &[u8], nom::error::Error<&[u8]>>::{closure#0}, core::str::converts::from_utf8>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
175
98.8k
  fn process<OM: OutputMode>(
176
98.8k
    &mut self,
177
98.8k
    mut i: I,
178
98.8k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
98.8k
    match self
180
98.8k
      .parser
181
98.8k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
978
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
97.8k
      Ok((i1, o)) => {
189
97.8k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
97.8k
        i = i1;
196
197
        loop {
198
2.52M
          let len = i.input_len();
199
2.52M
          match self
200
2.52M
            .parser
201
2.52M
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
97.8k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
2.42M
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
2.42M
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
2.42M
              }
213
214
2.42M
              i = i1;
215
216
2.42M
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
98.8k
  }
<nom::multi::Many1<suricata::krb::detect::detect_parse_encryption_item> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
175
6.36k
  fn process<OM: OutputMode>(
176
6.36k
    &mut self,
177
6.36k
    mut i: I,
178
6.36k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
6.36k
    match self
180
6.36k
      .parser
181
6.36k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
2.71k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
3.65k
      Ok((i1, o)) => {
189
3.65k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
3.65k
        i = i1;
196
197
        loop {
198
39.0k
          let len = i.input_len();
199
39.0k
          match self
200
39.0k
            .parser
201
39.0k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
3.65k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
35.4k
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
35.4k
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
35.4k
              }
213
214
35.4k
              i = i1;
215
216
35.4k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
6.36k
  }
<nom::multi::Many1<suricata::sdp::parser::parse_time_description> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
175
71.6k
  fn process<OM: OutputMode>(
176
71.6k
    &mut self,
177
71.6k
    mut i: I,
178
71.6k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
71.6k
    match self
180
71.6k
      .parser
181
71.6k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
41.5k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
30.1k
      Ok((i1, o)) => {
189
30.1k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
30.1k
        i = i1;
196
197
        loop {
198
386k
          let len = i.input_len();
199
386k
          match self
200
386k
            .parser
201
386k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
30.1k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
356k
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
356k
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
356k
              }
213
214
356k
              i = i1;
215
216
356k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
71.6k
  }
<nom::multi::Many1<suricata::pgsql::parser::parse_sasl_mechanism> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
175
12.5k
  fn process<OM: OutputMode>(
176
12.5k
    &mut self,
177
12.5k
    mut i: I,
178
12.5k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
12.5k
    match self
180
12.5k
      .parser
181
12.5k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
1.28k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
11.2k
      Ok((i1, o)) => {
189
11.2k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
11.2k
        i = i1;
196
197
        loop {
198
13.9k
          let len = i.input_len();
199
13.9k
          match self
200
13.9k
            .parser
201
13.9k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
11.2k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
2.74k
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
2.74k
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
2.74k
              }
213
214
2.74k
              i = i1;
215
216
2.74k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
12.5k
  }
<nom::multi::Many1<suricata::pgsql::parser::pgsql_parse_generic_parameter> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>
Line
Count
Source
175
31.3k
  fn process<OM: OutputMode>(
176
31.3k
    &mut self,
177
31.3k
    mut i: I,
178
31.3k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
31.3k
    match self
180
31.3k
      .parser
181
31.3k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
686
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
868
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
29.7k
      Ok((i1, o)) => {
189
29.7k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
29.7k
        i = i1;
196
197
        loop {
198
1.76M
          let len = i.input_len();
199
1.76M
          match self
200
1.76M
            .parser
201
1.76M
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
21.7k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
8.04k
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
1.73M
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
1.73M
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
1.73M
              }
213
214
1.73M
              i = i1;
215
216
1.73M
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
31.3k
  }
<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
175
12.2k
  fn process<OM: OutputMode>(
176
12.2k
    &mut self,
177
12.2k
    mut i: I,
178
12.2k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
12.2k
    match self
180
12.2k
      .parser
181
12.2k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
842
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
11.3k
      Ok((i1, o)) => {
189
11.3k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
11.3k
        i = i1;
196
197
        loop {
198
14.5k
          let len = i.input_len();
199
14.5k
          match self
200
14.5k
            .parser
201
14.5k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
11.3k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
3.15k
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
3.15k
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
3.15k
              }
213
214
3.15k
              i = i1;
215
216
3.15k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
12.2k
  }
<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Check, nom::internal::Streaming>>
Line
Count
Source
175
8.12k
  fn process<OM: OutputMode>(
176
8.12k
    &mut self,
177
8.12k
    mut i: I,
178
8.12k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
179
8.12k
    match self
180
8.12k
      .parser
181
8.12k
      .process::<OutputM<OM::Output, Emit, OM::Incomplete>>(i.clone())
182
    {
183
2.41k
      Err(Err::Error(err)) => Err(Err::Error(OM::Error::bind(|| {
184
        <F as Parser<I>>::Error::append(i, ErrorKind::Many1, err)
185
      }))),
186
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
187
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
188
5.70k
      Ok((i1, o)) => {
189
5.70k
        let mut acc = OM::Output::map(o, |o| {
190
          let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
191
          acc.push(o);
192
          acc
193
        });
194
195
5.70k
        i = i1;
196
197
        loop {
198
11.4k
          let len = i.input_len();
199
11.4k
          match self
200
11.4k
            .parser
201
11.4k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
202
          {
203
5.70k
            Err(Err::Error(_)) => return Ok((i, acc)),
204
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
205
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
206
5.79k
            Ok((i1, o)) => {
207
              // infinite loop check: the parser must always consume
208
5.79k
              if i1.input_len() == len {
209
0
                return Err(Err::Error(OM::Error::bind(|| {
210
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many0)
211
                })));
212
5.79k
              }
213
214
5.79k
              i = i1;
215
216
5.79k
              acc = OM::Output::combine(acc, o, |mut acc, o| {
217
                acc.push(o);
218
                acc
219
              })
220
            }
221
          }
222
        }
223
      }
224
    }
225
8.12k
  }
Unexecuted instantiation: <nom::multi::Many1<_> as nom::internal::Parser<_>>::process::<_>
226
}
227
228
/// Applies the parser `f` until the parser `g` produces a result.
229
///
230
/// Returns a tuple of the results of `f` in a `Vec` and the result of `g`.
231
///
232
/// `f` keeps going so long as `g` produces [`Err::Error`]. To instead chain an error up, see [`cut`][crate::combinator::cut].
233
///
234
/// ```rust
235
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
236
/// use nom::multi::many_till;
237
/// use nom::bytes::complete::tag;
238
///
239
/// fn parser(s: &str) -> IResult<&str, (Vec<&str>, &str)> {
240
///   many_till(tag("abc"), tag("end")).parse(s)
241
/// };
242
///
243
/// assert_eq!(parser("abcabcend"), Ok(("", (vec!["abc", "abc"], "end"))));
244
/// assert_eq!(parser("abc123end"), Err(Err::Error(Error::new("123end", ErrorKind::Tag))));
245
/// assert_eq!(parser("123123end"), Err(Err::Error(Error::new("123123end", ErrorKind::Tag))));
246
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
247
/// assert_eq!(parser("abcendefg"), Ok(("efg", (vec!["abc"], "end"))));
248
/// ```
249
#[cfg(feature = "alloc")]
250
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
251
39.8k
pub fn many_till<I, E, F, G>(
252
39.8k
  f: F,
253
39.8k
  g: G,
254
39.8k
) -> impl Parser<I, Output = (Vec<<F as Parser<I>>::Output>, <G as Parser<I>>::Output), Error = E>
255
39.8k
where
256
39.8k
  I: Clone + Input,
257
39.8k
  F: Parser<I, Error = E>,
258
39.8k
  G: Parser<I, Error = E>,
259
39.8k
  E: ParseError<I>,
260
{
261
39.8k
  ManyTill {
262
39.8k
    f,
263
39.8k
    g,
264
39.8k
    e: PhantomData,
265
39.8k
  }
266
39.8k
}
nom::multi::many_till::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>, suricata::pgsql::parser::parse_error_notice_fields::{closure#0}, nom::bytes::streaming::tag<&[u8], &[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}>
Line
Count
Source
251
39.8k
pub fn many_till<I, E, F, G>(
252
39.8k
  f: F,
253
39.8k
  g: G,
254
39.8k
) -> impl Parser<I, Output = (Vec<<F as Parser<I>>::Output>, <G as Parser<I>>::Output), Error = E>
255
39.8k
where
256
39.8k
  I: Clone + Input,
257
39.8k
  F: Parser<I, Error = E>,
258
39.8k
  G: Parser<I, Error = E>,
259
39.8k
  E: ParseError<I>,
260
{
261
39.8k
  ManyTill {
262
39.8k
    f,
263
39.8k
    g,
264
39.8k
    e: PhantomData,
265
39.8k
  }
266
39.8k
}
Unexecuted instantiation: nom::multi::many_till::<_, _, _, _>
267
268
#[cfg(feature = "alloc")]
269
/// Parser implementation for the [many_till] combinator
270
pub struct ManyTill<F, G, E> {
271
  f: F,
272
  g: G,
273
  e: PhantomData<E>,
274
}
275
276
#[cfg(feature = "alloc")]
277
impl<I, F, G, E> Parser<I> for ManyTill<F, G, E>
278
where
279
  I: Clone + Input,
280
  F: Parser<I, Error = E>,
281
  G: Parser<I, Error = E>,
282
  E: ParseError<I>,
283
{
284
  type Output = (Vec<<F as Parser<I>>::Output>, <G as Parser<I>>::Output);
285
  type Error = E;
286
287
39.8k
  fn process<OM: OutputMode>(
288
39.8k
    &mut self,
289
39.8k
    mut i: I,
290
39.8k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
291
39.8k
    let mut res = OM::Output::bind(crate::lib::std::vec::Vec::new);
292
    loop {
293
381k
      let len = i.input_len();
294
381k
      match self
295
381k
        .g
296
381k
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
297
      {
298
14.1k
        Ok((i1, o)) => return Ok((i1, OM::Output::combine(res, o, |res, o| (res, o)))),
<nom::multi::ManyTill<suricata::pgsql::parser::parse_error_notice_fields::{closure#0}, nom::bytes::streaming::tag<&[u8], &[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}, suricata::pgsql::parser::PgsqlParseError<&[u8]>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
298
14.1k
        Ok((i1, o)) => return Ok((i1, OM::Output::combine(res, o, |res, o| (res, o)))),
Unexecuted instantiation: <nom::multi::ManyTill<_, _, _> as nom::internal::Parser<_>>::process::<_>::{closure#0}
299
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
300
5.50k
        Err(Err::Incomplete(i)) => return Err(Err::Incomplete(i)),
301
        Err(Err::Error(_)) => {
302
361k
          match self.f.process::<OM>(i.clone()) {
303
5.29k
            Err(Err::Error(err)) => {
304
5.29k
              return Err(Err::Error(OM::Error::map(err, |err| {
305
5.29k
                E::append(i, ErrorKind::ManyTill, err)
306
5.29k
              })))
<nom::multi::ManyTill<suricata::pgsql::parser::parse_error_notice_fields::{closure#0}, nom::bytes::streaming::tag<&[u8], &[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}, suricata::pgsql::parser::PgsqlParseError<&[u8]>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
304
5.29k
              return Err(Err::Error(OM::Error::map(err, |err| {
305
5.29k
                E::append(i, ErrorKind::ManyTill, err)
306
5.29k
              })))
Unexecuted instantiation: <nom::multi::ManyTill<_, _, _> as nom::internal::Parser<_>>::process::<_>::{closure#1}
307
            }
308
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
309
14.8k
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
310
341k
            Ok((i1, o)) => {
311
              // infinite loop check: the parser must always consume
312
341k
              if i1.input_len() == len {
313
0
                return Err(Err::Error(OM::Error::bind(|| {
314
0
                  E::from_error_kind(i, ErrorKind::Many0)
315
0
                })));
Unexecuted instantiation: <nom::multi::ManyTill<suricata::pgsql::parser::parse_error_notice_fields::{closure#0}, nom::bytes::streaming::tag<&[u8], &[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}, suricata::pgsql::parser::PgsqlParseError<&[u8]>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::ManyTill<_, _, _> as nom::internal::Parser<_>>::process::<_>::{closure#2}
316
341k
              }
317
318
341k
              i = i1;
319
320
341k
              res = OM::Output::combine(res, o, |mut acc, o| {
321
341k
                acc.push(o);
322
341k
                acc
323
341k
              })
<nom::multi::ManyTill<suricata::pgsql::parser::parse_error_notice_fields::{closure#0}, nom::bytes::streaming::tag<&[u8], &[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}, suricata::pgsql::parser::PgsqlParseError<&[u8]>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Line
Count
Source
320
341k
              res = OM::Output::combine(res, o, |mut acc, o| {
321
341k
                acc.push(o);
322
341k
                acc
323
341k
              })
Unexecuted instantiation: <nom::multi::ManyTill<_, _, _> as nom::internal::Parser<_>>::process::<_>::{closure#3}
324
            }
325
          }
326
        }
327
      }
328
    }
329
39.8k
  }
<nom::multi::ManyTill<suricata::pgsql::parser::parse_error_notice_fields::{closure#0}, nom::bytes::streaming::tag<&[u8], &[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}, suricata::pgsql::parser::PgsqlParseError<&[u8]>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
287
39.8k
  fn process<OM: OutputMode>(
288
39.8k
    &mut self,
289
39.8k
    mut i: I,
290
39.8k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
291
39.8k
    let mut res = OM::Output::bind(crate::lib::std::vec::Vec::new);
292
    loop {
293
381k
      let len = i.input_len();
294
381k
      match self
295
381k
        .g
296
381k
        .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
297
      {
298
14.1k
        Ok((i1, o)) => return Ok((i1, OM::Output::combine(res, o, |res, o| (res, o)))),
299
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
300
5.50k
        Err(Err::Incomplete(i)) => return Err(Err::Incomplete(i)),
301
        Err(Err::Error(_)) => {
302
361k
          match self.f.process::<OM>(i.clone()) {
303
5.29k
            Err(Err::Error(err)) => {
304
5.29k
              return Err(Err::Error(OM::Error::map(err, |err| {
305
                E::append(i, ErrorKind::ManyTill, err)
306
              })))
307
            }
308
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
309
14.8k
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
310
341k
            Ok((i1, o)) => {
311
              // infinite loop check: the parser must always consume
312
341k
              if i1.input_len() == len {
313
0
                return Err(Err::Error(OM::Error::bind(|| {
314
                  E::from_error_kind(i, ErrorKind::Many0)
315
                })));
316
341k
              }
317
318
341k
              i = i1;
319
320
341k
              res = OM::Output::combine(res, o, |mut acc, o| {
321
                acc.push(o);
322
                acc
323
              })
324
            }
325
          }
326
        }
327
      }
328
    }
329
39.8k
  }
Unexecuted instantiation: <nom::multi::ManyTill<_, _, _> as nom::internal::Parser<_>>::process::<_>
330
}
331
332
/// Alternates between two parsers to produce a list of elements.
333
///
334
/// This stops when either parser returns [`Err::Error`]  and returns the results that were accumulated. To instead chain an error up, see
335
/// [`cut`][crate::combinator::cut].
336
///
337
/// # Arguments
338
/// * `sep` Parses the separator between list elements.
339
/// * `f` Parses the elements of the list.
340
///
341
/// ```rust
342
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
343
/// use nom::multi::separated_list0;
344
/// use nom::bytes::complete::tag;
345
///
346
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
347
///   separated_list0(tag("|"), tag("abc")).parse(s)
348
/// }
349
///
350
/// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
351
/// assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"])));
352
/// assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"])));
353
/// assert_eq!(parser(""), Ok(("", vec![])));
354
/// assert_eq!(parser("def|abc"), Ok(("def|abc", vec![])));
355
/// ```
356
#[cfg(feature = "alloc")]
357
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
358
0
pub fn separated_list0<I, E, F, G>(
359
0
  sep: G,
360
0
  f: F,
361
0
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = E>
362
0
where
363
0
  I: Clone + Input,
364
0
  F: Parser<I, Error = E>,
365
0
  G: Parser<I, Error = E>,
366
0
  E: ParseError<I>,
367
{
368
0
  SeparatedList0 {
369
0
    parser: f,
370
0
    separator: sep,
371
0
  }
372
0
}
373
374
#[cfg(feature = "alloc")]
375
/// Parser implementation for the [separated_list0] combinator
376
pub struct SeparatedList0<F, G> {
377
  parser: F,
378
  separator: G,
379
}
380
381
#[cfg(feature = "alloc")]
382
impl<I, E: ParseError<I>, F, G> Parser<I> for SeparatedList0<F, G>
383
where
384
  I: Clone + Input,
385
  F: Parser<I, Error = E>,
386
  G: Parser<I, Error = E>,
387
{
388
  type Output = Vec<<F as Parser<I>>::Output>;
389
  type Error = <F as Parser<I>>::Error;
390
391
0
  fn process<OM: OutputMode>(
392
0
    &mut self,
393
0
    mut i: I,
394
0
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
395
0
    let mut res = OM::Output::bind(crate::lib::std::vec::Vec::new);
396
397
0
    match self
398
0
      .parser
399
0
      .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i.clone())
400
    {
401
0
      Err(Err::Error(_)) => return Ok((i, res)),
402
0
      Err(Err::Failure(e)) => return Err(Err::Failure(e)),
403
0
      Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
404
0
      Ok((i1, o)) => {
405
0
        res = OM::Output::combine(res, o, |mut res, o| {
406
0
          res.push(o);
407
0
          res
408
0
        });
409
0
        i = i1;
410
      }
411
    }
412
413
    loop {
414
0
      let len = i.input_len();
415
0
      match self
416
0
        .separator
417
0
        .process::<OutputM<Check, Check, OM::Incomplete>>(i.clone())
418
      {
419
0
        Err(Err::Error(_)) => return Ok((i, res)),
420
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
421
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
422
0
        Ok((i1, _)) => {
423
0
          match self
424
0
            .parser
425
0
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i1.clone())
426
          {
427
0
            Err(Err::Error(_)) => return Ok((i, res)),
428
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
429
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
430
0
            Ok((i2, o)) => {
431
              // infinite loop check: the parser must always consume
432
0
              if i2.input_len() == len {
433
0
                return Err(Err::Error(OM::Error::bind(|| {
434
0
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::SeparatedList)
435
0
                })));
436
0
              }
437
438
0
              res = OM::Output::combine(res, o, |mut res, o| {
439
0
                res.push(o);
440
0
                res
441
0
              });
442
443
0
              i = i2;
444
            }
445
          }
446
        }
447
      }
448
    }
449
0
  }
450
}
451
452
/// Alternates between two parsers to produce a list of elements until [`Err::Error`].
453
///
454
/// Fails if the element parser does not produce at least one element.
455
///
456
/// This stops when either parser returns [`Err::Error`]  and returns the results that were accumulated. To instead chain an error up, see
457
/// [`cut`][crate::combinator::cut].
458
///
459
/// # Arguments
460
/// * `sep` Parses the separator between list elements.
461
/// * `f` Parses the elements of the list.
462
/// ```rust
463
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
464
/// use nom::multi::separated_list1;
465
/// use nom::bytes::complete::tag;
466
///
467
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
468
///   separated_list1(tag("|"), tag("abc")).parse(s)
469
/// }
470
///
471
/// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
472
/// assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"])));
473
/// assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"])));
474
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
475
/// assert_eq!(parser("def|abc"), Err(Err::Error(Error::new("def|abc", ErrorKind::Tag))));
476
/// ```
477
#[cfg(feature = "alloc")]
478
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
479
109k
pub fn separated_list1<I, E, F, G>(
480
109k
  separator: G,
481
109k
  parser: F,
482
109k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = E>
483
109k
where
484
109k
  I: Clone + Input,
485
109k
  F: Parser<I, Error = E>,
486
109k
  G: Parser<I, Error = E>,
487
109k
  E: ParseError<I>,
488
{
489
109k
  SeparatedList1 { parser, separator }
490
109k
}
nom::multi::separated_list1::<&str, nom::error::Error<&str>, nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)>, nom::sequence::Preceded<nom::character::complete::multispace0<&str, nom::error::Error<&str>>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>>
Line
Count
Source
479
12.2k
pub fn separated_list1<I, E, F, G>(
480
12.2k
  separator: G,
481
12.2k
  parser: F,
482
12.2k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = E>
483
12.2k
where
484
12.2k
  I: Clone + Input,
485
12.2k
  F: Parser<I, Error = E>,
486
12.2k
  G: Parser<I, Error = E>,
487
12.2k
  E: ParseError<I>,
488
{
489
12.2k
  SeparatedList1 { parser, separator }
490
12.2k
}
nom::multi::separated_list1::<&str, suricata::detect::error::RuleParseError<&str>, nom::sequence::Preceded<nom::character::complete::multispace0<&str, suricata::detect::error::RuleParseError<&str>>, nom::bytes::complete::is_not<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}>, nom::bytes::complete::tag<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}>
Line
Count
Source
479
97.4k
pub fn separated_list1<I, E, F, G>(
480
97.4k
  separator: G,
481
97.4k
  parser: F,
482
97.4k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = E>
483
97.4k
where
484
97.4k
  I: Clone + Input,
485
97.4k
  F: Parser<I, Error = E>,
486
97.4k
  G: Parser<I, Error = E>,
487
97.4k
  E: ParseError<I>,
488
{
489
97.4k
  SeparatedList1 { parser, separator }
490
97.4k
}
Unexecuted instantiation: nom::multi::separated_list1::<_, _, _, _>
491
492
#[cfg(feature = "alloc")]
493
/// Parser implementation for the [separated_list1] combinator
494
pub struct SeparatedList1<F, G> {
495
  parser: F,
496
  separator: G,
497
}
498
499
#[cfg(feature = "alloc")]
500
impl<I, E: ParseError<I>, F, G> Parser<I> for SeparatedList1<F, G>
501
where
502
  I: Clone + Input,
503
  F: Parser<I, Error = E>,
504
  G: Parser<I, Error = E>,
505
{
506
  type Output = Vec<<F as Parser<I>>::Output>;
507
  type Error = <F as Parser<I>>::Error;
508
509
109k
  fn process<OM: OutputMode>(
510
109k
    &mut self,
511
109k
    mut i: I,
512
109k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
513
109k
    let mut res = OM::Output::bind(crate::lib::std::vec::Vec::new);
514
515
109k
    match self.parser.process::<OM>(i.clone()) {
516
967
      Err(e) => return Err(e),
517
108k
      Ok((i1, o)) => {
518
108k
        res = OM::Output::combine(res, o, |mut res, o| {
519
108k
          res.push(o);
520
108k
          res
521
108k
        });
<nom::multi::SeparatedList1<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)>, nom::sequence::Preceded<nom::character::complete::multispace0<&str, nom::error::Error<&str>>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
518
11.3k
        res = OM::Output::combine(res, o, |mut res, o| {
519
11.3k
          res.push(o);
520
11.3k
          res
521
11.3k
        });
<nom::multi::SeparatedList1<nom::sequence::Preceded<nom::character::complete::multispace0<&str, suricata::detect::error::RuleParseError<&str>>, nom::bytes::complete::is_not<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}>, nom::bytes::complete::tag<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
518
97.3k
        res = OM::Output::combine(res, o, |mut res, o| {
519
97.3k
          res.push(o);
520
97.3k
          res
521
97.3k
        });
Unexecuted instantiation: <nom::multi::SeparatedList1<_, _> as nom::internal::Parser<_>>::process::<_>::{closure#0}
522
108k
        i = i1;
523
      }
524
    }
525
526
    loop {
527
484k
      let len = i.input_len();
528
484k
      match self
529
484k
        .separator
530
484k
        .process::<OutputM<Check, Check, OM::Incomplete>>(i.clone())
531
      {
532
104k
        Err(Err::Error(_)) => return Ok((i, res)),
533
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
534
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
535
380k
        Ok((i1, _)) => {
536
380k
          match self
537
380k
            .parser
538
380k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i1.clone())
539
          {
540
4.56k
            Err(Err::Error(_)) => return Ok((i, res)),
541
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
542
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
543
376k
            Ok((i2, o)) => {
544
              // infinite loop check: the parser must always consume
545
376k
              if i2.input_len() == len {
546
0
                return Err(Err::Error(OM::Error::bind(|| {
547
0
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::SeparatedList)
548
0
                })));
Unexecuted instantiation: <nom::multi::SeparatedList1<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)>, nom::sequence::Preceded<nom::character::complete::multispace0<&str, nom::error::Error<&str>>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::SeparatedList1<nom::sequence::Preceded<nom::character::complete::multispace0<&str, suricata::detect::error::RuleParseError<&str>>, nom::bytes::complete::is_not<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}>, nom::bytes::complete::tag<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::SeparatedList1<_, _> as nom::internal::Parser<_>>::process::<_>::{closure#1}
549
376k
              }
550
551
376k
              res = OM::Output::combine(res, o, |mut res, o| {
552
376k
                res.push(o);
553
376k
                res
554
376k
              });
<nom::multi::SeparatedList1<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)>, nom::sequence::Preceded<nom::character::complete::multispace0<&str, nom::error::Error<&str>>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
551
5.70k
              res = OM::Output::combine(res, o, |mut res, o| {
552
5.70k
                res.push(o);
553
5.70k
                res
554
5.70k
              });
<nom::multi::SeparatedList1<nom::sequence::Preceded<nom::character::complete::multispace0<&str, suricata::detect::error::RuleParseError<&str>>, nom::bytes::complete::is_not<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}>, nom::bytes::complete::tag<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
551
370k
              res = OM::Output::combine(res, o, |mut res, o| {
552
370k
                res.push(o);
553
370k
                res
554
370k
              });
Unexecuted instantiation: <nom::multi::SeparatedList1<_, _> as nom::internal::Parser<_>>::process::<_>::{closure#2}
555
376k
              i = i2;
556
            }
557
          }
558
        }
559
      }
560
    }
561
109k
  }
<nom::multi::SeparatedList1<nom::multi::Many1<(suricata::detect::requires::parse_op, suricata::detect::requires::parse_version)>, nom::sequence::Preceded<nom::character::complete::multispace0<&str, nom::error::Error<&str>>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
509
12.2k
  fn process<OM: OutputMode>(
510
12.2k
    &mut self,
511
12.2k
    mut i: I,
512
12.2k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
513
12.2k
    let mut res = OM::Output::bind(crate::lib::std::vec::Vec::new);
514
515
12.2k
    match self.parser.process::<OM>(i.clone()) {
516
842
      Err(e) => return Err(e),
517
11.3k
      Ok((i1, o)) => {
518
11.3k
        res = OM::Output::combine(res, o, |mut res, o| {
519
          res.push(o);
520
          res
521
        });
522
11.3k
        i = i1;
523
      }
524
    }
525
526
    loop {
527
17.0k
      let len = i.input_len();
528
17.0k
      match self
529
17.0k
        .separator
530
17.0k
        .process::<OutputM<Check, Check, OM::Incomplete>>(i.clone())
531
      {
532
8.94k
        Err(Err::Error(_)) => return Ok((i, res)),
533
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
534
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
535
8.12k
        Ok((i1, _)) => {
536
8.12k
          match self
537
8.12k
            .parser
538
8.12k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i1.clone())
539
          {
540
2.41k
            Err(Err::Error(_)) => return Ok((i, res)),
541
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
542
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
543
5.70k
            Ok((i2, o)) => {
544
              // infinite loop check: the parser must always consume
545
5.70k
              if i2.input_len() == len {
546
0
                return Err(Err::Error(OM::Error::bind(|| {
547
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::SeparatedList)
548
                })));
549
5.70k
              }
550
551
5.70k
              res = OM::Output::combine(res, o, |mut res, o| {
552
                res.push(o);
553
                res
554
              });
555
5.70k
              i = i2;
556
            }
557
          }
558
        }
559
      }
560
    }
561
12.2k
  }
<nom::multi::SeparatedList1<nom::sequence::Preceded<nom::character::complete::multispace0<&str, suricata::detect::error::RuleParseError<&str>>, nom::bytes::complete::is_not<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}>, nom::bytes::complete::tag<&str, &str, suricata::detect::error::RuleParseError<&str>>::{closure#0}> as nom::internal::Parser<&str>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
509
97.4k
  fn process<OM: OutputMode>(
510
97.4k
    &mut self,
511
97.4k
    mut i: I,
512
97.4k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
513
97.4k
    let mut res = OM::Output::bind(crate::lib::std::vec::Vec::new);
514
515
97.4k
    match self.parser.process::<OM>(i.clone()) {
516
125
      Err(e) => return Err(e),
517
97.3k
      Ok((i1, o)) => {
518
97.3k
        res = OM::Output::combine(res, o, |mut res, o| {
519
          res.push(o);
520
          res
521
        });
522
97.3k
        i = i1;
523
      }
524
    }
525
526
    loop {
527
467k
      let len = i.input_len();
528
467k
      match self
529
467k
        .separator
530
467k
        .process::<OutputM<Check, Check, OM::Incomplete>>(i.clone())
531
      {
532
95.2k
        Err(Err::Error(_)) => return Ok((i, res)),
533
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
534
0
        Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
535
372k
        Ok((i1, _)) => {
536
372k
          match self
537
372k
            .parser
538
372k
            .process::<OutputM<OM::Output, Check, OM::Incomplete>>(i1.clone())
539
          {
540
2.14k
            Err(Err::Error(_)) => return Ok((i, res)),
541
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
542
0
            Err(Err::Incomplete(e)) => return Err(Err::Incomplete(e)),
543
370k
            Ok((i2, o)) => {
544
              // infinite loop check: the parser must always consume
545
370k
              if i2.input_len() == len {
546
0
                return Err(Err::Error(OM::Error::bind(|| {
547
                  <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::SeparatedList)
548
                })));
549
370k
              }
550
551
370k
              res = OM::Output::combine(res, o, |mut res, o| {
552
                res.push(o);
553
                res
554
              });
555
370k
              i = i2;
556
            }
557
          }
558
        }
559
      }
560
    }
561
97.4k
  }
Unexecuted instantiation: <nom::multi::SeparatedList1<_, _> as nom::internal::Parser<_>>::process::<_>
562
}
563
564
/// Repeats the embedded parser `m..=n` times
565
///
566
/// This stops before `n` when the parser returns [`Err::Error`]  and returns the results that were accumulated. To instead chain an error up, see
567
/// [`cut`][crate::combinator::cut].
568
///
569
/// # Arguments
570
/// * `m` The minimum number of iterations.
571
/// * `n` The maximum number of iterations.
572
/// * `f` The parser to apply.
573
///
574
/// *Note*: If the parser passed to `many1` accepts empty inputs
575
/// (like `alpha0` or `digit0`), `many1` will return an error,
576
/// to prevent going into an infinite loop.
577
///
578
/// ```rust
579
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
580
/// use nom::multi::many_m_n;
581
/// use nom::bytes::complete::tag;
582
///
583
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
584
///   many_m_n(0, 2, tag("abc")).parse(s)
585
/// }
586
///
587
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
588
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
589
/// assert_eq!(parser("123123"), Ok(("123123", vec![])));
590
/// assert_eq!(parser(""), Ok(("", vec![])));
591
/// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
592
/// ```
593
#[cfg(feature = "alloc")]
594
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
595
539k
pub fn many_m_n<I, E, F>(
596
539k
  min: usize,
597
539k
  max: usize,
598
539k
  parser: F,
599
539k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = E>
600
539k
where
601
539k
  I: Clone + Input,
602
539k
  F: Parser<I, Error = E>,
603
539k
  E: ParseError<I>,
604
{
605
539k
  ManyMN { parser, min, max }
606
539k
}
nom::multi::many_m_n::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>, nom::number::streaming::be_u16<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>>
Line
Count
Source
595
56.6k
pub fn many_m_n<I, E, F>(
596
56.6k
  min: usize,
597
56.6k
  max: usize,
598
56.6k
  parser: F,
599
56.6k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = E>
600
56.6k
where
601
56.6k
  I: Clone + Input,
602
56.6k
  F: Parser<I, Error = E>,
603
56.6k
  E: ParseError<I>,
604
{
605
56.6k
  ManyMN { parser, min, max }
606
56.6k
}
nom::multi::many_m_n::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>, suricata::pgsql::parser::parse_row_field>
Line
Count
Source
595
24.2k
pub fn many_m_n<I, E, F>(
596
24.2k
  min: usize,
597
24.2k
  max: usize,
598
24.2k
  parser: F,
599
24.2k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = E>
600
24.2k
where
601
24.2k
  I: Clone + Input,
602
24.2k
  F: Parser<I, Error = E>,
603
24.2k
  E: ParseError<I>,
604
{
605
24.2k
  ManyMN { parser, min, max }
606
24.2k
}
nom::multi::many_m_n::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>, suricata::pgsql::parser::parse_data_row_value>
Line
Count
Source
595
458k
pub fn many_m_n<I, E, F>(
596
458k
  min: usize,
597
458k
  max: usize,
598
458k
  parser: F,
599
458k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = E>
600
458k
where
601
458k
  I: Clone + Input,
602
458k
  F: Parser<I, Error = E>,
603
458k
  E: ParseError<I>,
604
{
605
458k
  ManyMN { parser, min, max }
606
458k
}
Unexecuted instantiation: nom::multi::many_m_n::<_, _, _>
607
608
#[cfg(feature = "alloc")]
609
/// Parser implementation for the [many_m_n] combinator
610
pub struct ManyMN<F> {
611
  parser: F,
612
  min: usize,
613
  max: usize,
614
}
615
616
#[cfg(feature = "alloc")]
617
impl<I, F> Parser<I> for ManyMN<F>
618
where
619
  I: Clone + Input,
620
  F: Parser<I>,
621
{
622
  type Output = Vec<<F as Parser<I>>::Output>;
623
  type Error = <F as Parser<I>>::Error;
624
625
490k
  fn process<OM: OutputMode>(
626
490k
    &mut self,
627
490k
    mut input: I,
628
490k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
629
490k
    if self.min > self.max {
630
0
      return Err(Err::Failure(<F as Parser<I>>::Error::from_error_kind(
631
0
        input,
632
0
        ErrorKind::ManyMN,
633
0
      )));
634
490k
    }
635
636
490k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
637
490k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
638
490k
    let mut res = OM::Output::bind(|| {
639
490k
      crate::lib::std::vec::Vec::with_capacity(self.min.min(max_initial_capacity))
640
490k
    });
<nom::multi::ManyMN<nom::number::streaming::be_u16<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
638
56.6k
    let mut res = OM::Output::bind(|| {
639
56.6k
      crate::lib::std::vec::Vec::with_capacity(self.min.min(max_initial_capacity))
640
56.6k
    });
<nom::multi::ManyMN<suricata::pgsql::parser::parse_row_field> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
638
10.9k
    let mut res = OM::Output::bind(|| {
639
10.9k
      crate::lib::std::vec::Vec::with_capacity(self.min.min(max_initial_capacity))
640
10.9k
    });
<nom::multi::ManyMN<suricata::pgsql::parser::parse_data_row_value> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
638
423k
    let mut res = OM::Output::bind(|| {
639
423k
      crate::lib::std::vec::Vec::with_capacity(self.min.min(max_initial_capacity))
640
423k
    });
Unexecuted instantiation: <nom::multi::ManyMN<_> as nom::internal::Parser<_>>::process::<_>::{closure#0}
641
2.68M
    for count in 0..self.max {
642
2.68M
      let len = input.input_len();
643
2.68M
      match self.parser.process::<OM>(input.clone()) {
644
2.66M
        Ok((tail, value)) => {
645
          // infinite loop check: the parser must always consume
646
2.66M
          if tail.input_len() == len {
647
0
            return Err(Err::Error(OM::Error::bind(|| {
648
0
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::ManyMN)
649
0
            })));
Unexecuted instantiation: <nom::multi::ManyMN<nom::number::streaming::be_u16<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::ManyMN<suricata::pgsql::parser::parse_row_field> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::ManyMN<suricata::pgsql::parser::parse_data_row_value> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::ManyMN<_> as nom::internal::Parser<_>>::process::<_>::{closure#1}
650
2.66M
          }
651
652
2.66M
          res = OM::Output::combine(res, value, |mut res, value| {
653
2.66M
            res.push(value);
654
2.66M
            res
655
2.66M
          });
<nom::multi::ManyMN<nom::number::streaming::be_u16<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
652
1.62M
          res = OM::Output::combine(res, value, |mut res, value| {
653
1.62M
            res.push(value);
654
1.62M
            res
655
1.62M
          });
<nom::multi::ManyMN<suricata::pgsql::parser::parse_row_field> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
652
255k
          res = OM::Output::combine(res, value, |mut res, value| {
653
255k
            res.push(value);
654
255k
            res
655
255k
          });
<nom::multi::ManyMN<suricata::pgsql::parser::parse_data_row_value> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
652
785k
          res = OM::Output::combine(res, value, |mut res, value| {
653
785k
            res.push(value);
654
785k
            res
655
785k
          });
Unexecuted instantiation: <nom::multi::ManyMN<_> as nom::internal::Parser<_>>::process::<_>::{closure#2}
656
2.66M
          input = tail;
657
        }
658
1.61k
        Err(Err::Error(e)) => {
659
1.61k
          if count < self.min {
660
0
            return Err(Err::Error(OM::Error::map(e, |e| {
661
0
              <F as Parser<I>>::Error::append(input, ErrorKind::ManyMN, e)
662
0
            })));
Unexecuted instantiation: <nom::multi::ManyMN<nom::number::streaming::be_u16<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Unexecuted instantiation: <nom::multi::ManyMN<suricata::pgsql::parser::parse_row_field> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Unexecuted instantiation: <nom::multi::ManyMN<suricata::pgsql::parser::parse_data_row_value> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#3}
Unexecuted instantiation: <nom::multi::ManyMN<_> as nom::internal::Parser<_>>::process::<_>::{closure#3}
663
          } else {
664
1.61k
            return Ok((input, res));
665
          }
666
        }
667
13.2k
        Err(e) => {
668
13.2k
          return Err(e);
669
        }
670
      }
671
    }
672
673
475k
    Ok((input, res))
674
490k
  }
<nom::multi::ManyMN<nom::number::streaming::be_u16<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
625
56.6k
  fn process<OM: OutputMode>(
626
56.6k
    &mut self,
627
56.6k
    mut input: I,
628
56.6k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
629
56.6k
    if self.min > self.max {
630
0
      return Err(Err::Failure(<F as Parser<I>>::Error::from_error_kind(
631
0
        input,
632
0
        ErrorKind::ManyMN,
633
0
      )));
634
56.6k
    }
635
636
56.6k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
637
56.6k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
638
56.6k
    let mut res = OM::Output::bind(|| {
639
      crate::lib::std::vec::Vec::with_capacity(self.min.min(max_initial_capacity))
640
    });
641
1.63M
    for count in 0..self.max {
642
1.63M
      let len = input.input_len();
643
1.63M
      match self.parser.process::<OM>(input.clone()) {
644
1.62M
        Ok((tail, value)) => {
645
          // infinite loop check: the parser must always consume
646
1.62M
          if tail.input_len() == len {
647
0
            return Err(Err::Error(OM::Error::bind(|| {
648
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::ManyMN)
649
            })));
650
1.62M
          }
651
652
1.62M
          res = OM::Output::combine(res, value, |mut res, value| {
653
            res.push(value);
654
            res
655
          });
656
1.62M
          input = tail;
657
        }
658
0
        Err(Err::Error(e)) => {
659
0
          if count < self.min {
660
0
            return Err(Err::Error(OM::Error::map(e, |e| {
661
              <F as Parser<I>>::Error::append(input, ErrorKind::ManyMN, e)
662
            })));
663
          } else {
664
0
            return Ok((input, res));
665
          }
666
        }
667
3.83k
        Err(e) => {
668
3.83k
          return Err(e);
669
        }
670
      }
671
    }
672
673
52.8k
    Ok((input, res))
674
56.6k
  }
<nom::multi::ManyMN<suricata::pgsql::parser::parse_row_field> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
625
10.9k
  fn process<OM: OutputMode>(
626
10.9k
    &mut self,
627
10.9k
    mut input: I,
628
10.9k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
629
10.9k
    if self.min > self.max {
630
0
      return Err(Err::Failure(<F as Parser<I>>::Error::from_error_kind(
631
0
        input,
632
0
        ErrorKind::ManyMN,
633
0
      )));
634
10.9k
    }
635
636
10.9k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
637
10.9k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
638
10.9k
    let mut res = OM::Output::bind(|| {
639
      crate::lib::std::vec::Vec::with_capacity(self.min.min(max_initial_capacity))
640
    });
641
264k
    for count in 0..self.max {
642
264k
      let len = input.input_len();
643
264k
      match self.parser.process::<OM>(input.clone()) {
644
255k
        Ok((tail, value)) => {
645
          // infinite loop check: the parser must always consume
646
255k
          if tail.input_len() == len {
647
0
            return Err(Err::Error(OM::Error::bind(|| {
648
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::ManyMN)
649
            })));
650
255k
          }
651
652
255k
          res = OM::Output::combine(res, value, |mut res, value| {
653
            res.push(value);
654
            res
655
          });
656
255k
          input = tail;
657
        }
658
1.61k
        Err(Err::Error(e)) => {
659
1.61k
          if count < self.min {
660
0
            return Err(Err::Error(OM::Error::map(e, |e| {
661
              <F as Parser<I>>::Error::append(input, ErrorKind::ManyMN, e)
662
            })));
663
          } else {
664
1.61k
            return Ok((input, res));
665
          }
666
        }
667
7.54k
        Err(e) => {
668
7.54k
          return Err(e);
669
        }
670
      }
671
    }
672
673
1.76k
    Ok((input, res))
674
10.9k
  }
<nom::multi::ManyMN<suricata::pgsql::parser::parse_data_row_value> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
625
423k
  fn process<OM: OutputMode>(
626
423k
    &mut self,
627
423k
    mut input: I,
628
423k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
629
423k
    if self.min > self.max {
630
0
      return Err(Err::Failure(<F as Parser<I>>::Error::from_error_kind(
631
0
        input,
632
0
        ErrorKind::ManyMN,
633
0
      )));
634
423k
    }
635
636
423k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
637
423k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
638
423k
    let mut res = OM::Output::bind(|| {
639
      crate::lib::std::vec::Vec::with_capacity(self.min.min(max_initial_capacity))
640
    });
641
786k
    for count in 0..self.max {
642
786k
      let len = input.input_len();
643
786k
      match self.parser.process::<OM>(input.clone()) {
644
785k
        Ok((tail, value)) => {
645
          // infinite loop check: the parser must always consume
646
785k
          if tail.input_len() == len {
647
0
            return Err(Err::Error(OM::Error::bind(|| {
648
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::ManyMN)
649
            })));
650
785k
          }
651
652
785k
          res = OM::Output::combine(res, value, |mut res, value| {
653
            res.push(value);
654
            res
655
          });
656
785k
          input = tail;
657
        }
658
0
        Err(Err::Error(e)) => {
659
0
          if count < self.min {
660
0
            return Err(Err::Error(OM::Error::map(e, |e| {
661
              <F as Parser<I>>::Error::append(input, ErrorKind::ManyMN, e)
662
            })));
663
          } else {
664
0
            return Ok((input, res));
665
          }
666
        }
667
1.84k
        Err(e) => {
668
1.84k
          return Err(e);
669
        }
670
      }
671
    }
672
673
421k
    Ok((input, res))
674
423k
  }
Unexecuted instantiation: <nom::multi::ManyMN<_> as nom::internal::Parser<_>>::process::<_>
675
}
676
677
/// Repeats the embedded parser, counting the results
678
///
679
/// This stops on [`Err::Error`]. To instead chain an error up, see
680
/// [`cut`][crate::combinator::cut].
681
///
682
/// # Arguments
683
/// * `f` The parser to apply.
684
///
685
/// *Note*: if the parser passed in accepts empty inputs (like `alpha0` or `digit0`), `many0` will
686
/// return an error, to prevent going into an infinite loop
687
///
688
/// ```rust
689
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
690
/// use nom::multi::many0_count;
691
/// use nom::bytes::complete::tag;
692
///
693
/// fn parser(s: &str) -> IResult<&str, usize> {
694
///   many0_count(tag("abc")).parse(s)
695
/// }
696
///
697
/// assert_eq!(parser("abcabc"), Ok(("", 2)));
698
/// assert_eq!(parser("abc123"), Ok(("123", 1)));
699
/// assert_eq!(parser("123123"), Ok(("123123", 0)));
700
/// assert_eq!(parser(""), Ok(("", 0)));
701
/// ```
702
0
pub fn many0_count<I, E, F>(parser: F) -> impl Parser<I, Output = usize, Error = E>
703
0
where
704
0
  I: Clone + Input,
705
0
  F: Parser<I, Error = E>,
706
0
  E: ParseError<I>,
707
{
708
0
  Many0Count { parser }
709
0
}
710
711
/// Parser implementation for the [many0_count] combinator
712
pub struct Many0Count<F> {
713
  parser: F,
714
}
715
716
impl<I, F> Parser<I> for Many0Count<F>
717
where
718
  I: Clone + Input,
719
  F: Parser<I>,
720
{
721
  type Output = usize;
722
  type Error = <F as Parser<I>>::Error;
723
724
0
  fn process<OM: OutputMode>(
725
0
    &mut self,
726
0
    mut input: I,
727
0
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
728
0
    let mut count = 0;
729
730
    loop {
731
0
      let input_ = input.clone();
732
0
      let len = input.input_len();
733
0
      match self
734
0
        .parser
735
0
        .process::<OutputM<Check, Check, OM::Incomplete>>(input_)
736
      {
737
0
        Ok((i, _)) => {
738
          // infinite loop check: the parser must always consume
739
0
          if i.input_len() == len {
740
0
            return Err(Err::Error(OM::Error::bind(|| {
741
0
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many0Count)
742
0
            })));
743
0
          }
744
745
0
          input = i;
746
0
          count += 1;
747
        }
748
749
0
        Err(Err::Error(_)) => return Ok((input, OM::Output::bind(|| count))),
750
0
        Err(Err::Failure(e)) => return Err(Err::Failure(e)),
751
0
        Err(Err::Incomplete(i)) => return Err(Err::Incomplete(i)),
752
      }
753
    }
754
0
  }
755
}
756
757
/// Runs the embedded parser, counting the results.
758
///
759
/// This stops on [`Err::Error`] if there is at least one result. To instead chain an error up,
760
/// see [`cut`][crate::combinator::cut].
761
///
762
/// # Arguments
763
/// * `f` The parser to apply.
764
///
765
/// *Note*: If the parser passed to `many1` accepts empty inputs
766
/// (like `alpha0` or `digit0`), `many1` will return an error,
767
/// to prevent going into an infinite loop.
768
///
769
/// ```rust
770
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
771
/// use nom::multi::many1_count;
772
/// use nom::bytes::complete::tag;
773
///
774
/// fn parser(s: &str) -> IResult<&str, usize> {
775
///   many1_count(tag("abc")).parse(s)
776
/// }
777
///
778
/// assert_eq!(parser("abcabc"), Ok(("", 2)));
779
/// assert_eq!(parser("abc123"), Ok(("123", 1)));
780
/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Many1Count))));
781
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Many1Count))));
782
/// ```
783
1.86k
pub fn many1_count<I, E, F>(parser: F) -> impl Parser<I, Output = usize, Error = E>
784
1.86k
where
785
1.86k
  I: Clone + Input,
786
1.86k
  F: Parser<I, Error = E>,
787
1.86k
  E: ParseError<I>,
788
{
789
1.86k
  Many1Count { parser }
790
1.86k
}
nom::multi::many1_count::<&[u8], nom::error::Error<&[u8]>, suricata::util::parse_subdomain>
Line
Count
Source
783
1.86k
pub fn many1_count<I, E, F>(parser: F) -> impl Parser<I, Output = usize, Error = E>
784
1.86k
where
785
1.86k
  I: Clone + Input,
786
1.86k
  F: Parser<I, Error = E>,
787
1.86k
  E: ParseError<I>,
788
{
789
1.86k
  Many1Count { parser }
790
1.86k
}
Unexecuted instantiation: nom::multi::many1_count::<_, _, _>
791
792
/// Parser implementation for the [many1_count] combinator
793
pub struct Many1Count<F> {
794
  parser: F,
795
}
796
797
impl<I, F> Parser<I> for Many1Count<F>
798
where
799
  I: Clone + Input,
800
  F: Parser<I>,
801
{
802
  type Output = usize;
803
  type Error = <F as Parser<I>>::Error;
804
805
1.86k
  fn process<OM: OutputMode>(
806
1.86k
    &mut self,
807
1.86k
    input: I,
808
1.86k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
809
1.86k
    let mut count = 0;
810
811
1.86k
    match self
812
1.86k
      .parser
813
1.86k
      .process::<OutputM<Check, Check, OM::Incomplete>>(input.clone())
814
    {
815
505
      Err(Err::Error(_)) => Err(Err::Error(OM::Error::bind(move || {
816
505
        <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many1Count)
817
505
      }))),
<nom::multi::Many1Count<suricata::util::parse_subdomain> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
815
505
      Err(Err::Error(_)) => Err(Err::Error(OM::Error::bind(move || {
816
505
        <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many1Count)
817
505
      }))),
Unexecuted instantiation: <nom::multi::Many1Count<_> as nom::internal::Parser<_>>::process::<_>::{closure#0}
818
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
819
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
820
1.35k
      Ok((mut input, _)) => {
821
1.35k
        count += 1;
822
823
        loop {
824
117k
          let input_ = input.clone();
825
117k
          let len = input.input_len();
826
117k
          match self
827
117k
            .parser
828
117k
            .process::<OutputM<Check, Check, OM::Incomplete>>(input_)
829
          {
830
116k
            Ok((i, _)) => {
831
              // infinite loop check: the parser must always consume
832
116k
              if i.input_len() == len {
833
0
                return Err(Err::Error(OM::Error::bind(|| {
834
0
                  <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many1Count)
835
0
                })));
Unexecuted instantiation: <nom::multi::Many1Count<suricata::util::parse_subdomain> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::Many1Count<_> as nom::internal::Parser<_>>::process::<_>::{closure#1}
836
116k
              }
837
838
116k
              input = i;
839
116k
              count += 1;
840
            }
841
842
1.35k
            Err(Err::Error(_)) => return Ok((input, OM::Output::bind(|| count))),
843
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
844
0
            Err(Err::Incomplete(i)) => return Err(Err::Incomplete(i)),
845
          }
846
        }
847
      }
848
    }
849
1.86k
  }
<nom::multi::Many1Count<suricata::util::parse_subdomain> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
805
1.86k
  fn process<OM: OutputMode>(
806
1.86k
    &mut self,
807
1.86k
    input: I,
808
1.86k
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
809
1.86k
    let mut count = 0;
810
811
1.86k
    match self
812
1.86k
      .parser
813
1.86k
      .process::<OutputM<Check, Check, OM::Incomplete>>(input.clone())
814
    {
815
505
      Err(Err::Error(_)) => Err(Err::Error(OM::Error::bind(move || {
816
        <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many1Count)
817
      }))),
818
0
      Err(Err::Failure(e)) => Err(Err::Failure(e)),
819
0
      Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
820
1.35k
      Ok((mut input, _)) => {
821
1.35k
        count += 1;
822
823
        loop {
824
117k
          let input_ = input.clone();
825
117k
          let len = input.input_len();
826
117k
          match self
827
117k
            .parser
828
117k
            .process::<OutputM<Check, Check, OM::Incomplete>>(input_)
829
          {
830
116k
            Ok((i, _)) => {
831
              // infinite loop check: the parser must always consume
832
116k
              if i.input_len() == len {
833
0
                return Err(Err::Error(OM::Error::bind(|| {
834
                  <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many1Count)
835
                })));
836
116k
              }
837
838
116k
              input = i;
839
116k
              count += 1;
840
            }
841
842
1.35k
            Err(Err::Error(_)) => return Ok((input, OM::Output::bind(|| count))),
843
0
            Err(Err::Failure(e)) => return Err(Err::Failure(e)),
844
0
            Err(Err::Incomplete(i)) => return Err(Err::Incomplete(i)),
845
          }
846
        }
847
      }
848
    }
849
1.86k
  }
Unexecuted instantiation: <nom::multi::Many1Count<_> as nom::internal::Parser<_>>::process::<_>
850
}
851
852
/// Runs the embedded parser `count` times, gathering the results in a `Vec`
853
///
854
/// # Arguments
855
/// * `f` The parser to apply.
856
/// * `count` How often to apply the parser.
857
/// ```rust
858
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
859
/// use nom::multi::count;
860
/// use nom::bytes::complete::tag;
861
///
862
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
863
///   count(tag("abc"), 2).parse(s)
864
/// }
865
///
866
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
867
/// assert_eq!(parser("abc123"), Err(Err::Error(Error::new("123", ErrorKind::Tag))));
868
/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Tag))));
869
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
870
/// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
871
/// ```
872
#[cfg(feature = "alloc")]
873
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
874
4.97M
pub fn count<I, F>(
875
4.97M
  parser: F,
876
4.97M
  count: usize,
877
4.97M
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
4.97M
where
879
4.97M
  I: Clone,
880
4.97M
  F: Parser<I>,
881
{
882
4.97M
  Count { parser, count }
883
4.97M
}
nom::multi::count::<&[u8], nom::number::complete::le_u16<&[u8], nom::error::Error<&[u8]>>>
Line
Count
Source
874
38.9k
pub fn count<I, F>(
875
38.9k
  parser: F,
876
38.9k
  count: usize,
877
38.9k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
38.9k
where
879
38.9k
  I: Clone,
880
38.9k
  F: Parser<I>,
881
{
882
38.9k
  Count { parser, count }
883
38.9k
}
nom::multi::count::<&[u8], nom::number::streaming::le_u16<&[u8], nom::error::Error<&[u8]>>>
Line
Count
Source
874
15.1k
pub fn count<I, F>(
875
15.1k
  parser: F,
876
15.1k
  count: usize,
877
15.1k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
15.1k
where
879
15.1k
  I: Clone,
880
15.1k
  F: Parser<I>,
881
{
882
15.1k
  Count { parser, count }
883
15.1k
}
nom::multi::count::<&[u8], suricata::smb::dcerpc_records::parse_dcerpc_bind_iface>
Line
Count
Source
874
4.55k
pub fn count<I, F>(
875
4.55k
  parser: F,
876
4.55k
  count: usize,
877
4.55k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
4.55k
where
879
4.55k
  I: Clone,
880
4.55k
  F: Parser<I>,
881
{
882
4.55k
  Count { parser, count }
883
4.55k
}
nom::multi::count::<&[u8], suricata::smb::dcerpc_records::parse_dcerpc_bind_iface_big>
Line
Count
Source
874
4.53k
pub fn count<I, F>(
875
4.53k
  parser: F,
876
4.53k
  count: usize,
877
4.53k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
4.53k
where
879
4.53k
  I: Clone,
880
4.53k
  F: Parser<I>,
881
{
882
4.53k
  Count { parser, count }
883
4.53k
}
nom::multi::count::<&[u8], suricata::smb::dcerpc_records::parse_dcerpc_bindack_result>
Line
Count
Source
874
3.93k
pub fn count<I, F>(
875
3.93k
  parser: F,
876
3.93k
  count: usize,
877
3.93k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
3.93k
where
879
3.93k
  I: Clone,
880
3.93k
  F: Parser<I>,
881
{
882
3.93k
  Count { parser, count }
883
3.93k
}
nom::multi::count::<&[u8], suricata::dns::parser::dns_parse_body::{closure#0}>
Line
Count
Source
874
4.79M
pub fn count<I, F>(
875
4.79M
  parser: F,
876
4.79M
  count: usize,
877
4.79M
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
4.79M
where
879
4.79M
  I: Clone,
880
4.79M
  F: Parser<I>,
881
{
882
4.79M
  Count { parser, count }
883
4.79M
}
nom::multi::count::<&[u8], suricata::dcerpc::parser::parse_dcerpc_bindack_result>
Line
Count
Source
874
96.8k
pub fn count<I, F>(
875
96.8k
  parser: F,
876
96.8k
  count: usize,
877
96.8k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
96.8k
where
879
96.8k
  I: Clone,
880
96.8k
  F: Parser<I>,
881
{
882
96.8k
  Count { parser, count }
883
96.8k
}
nom::multi::count::<&[u8], nom::combinator::MakeComplete<suricata::quic::frames::parse_tag_and_offset>>
Line
Count
Source
874
16.7k
pub fn count<I, F>(
875
16.7k
  parser: F,
876
16.7k
  count: usize,
877
16.7k
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
878
16.7k
where
879
16.7k
  I: Clone,
880
16.7k
  F: Parser<I>,
881
{
882
16.7k
  Count { parser, count }
883
16.7k
}
Unexecuted instantiation: nom::multi::count::<_, _>
884
885
#[cfg(feature = "alloc")]
886
/// Parser implementation for the [count] combinator
887
pub struct Count<F> {
888
  parser: F,
889
  count: usize,
890
}
891
892
#[cfg(feature = "alloc")]
893
impl<I, F> Parser<I> for Count<F>
894
where
895
  I: Clone,
896
  F: Parser<I>,
897
{
898
  type Output = Vec<<F as Parser<I>>::Output>;
899
  type Error = <F as Parser<I>>::Error;
900
901
4.97M
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
4.97M
    let mut input = i.clone();
903
4.97M
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
4.97M
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
4.97M
    let mut res = OM::Output::bind(|| {
906
4.97M
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
4.97M
    });
<nom::multi::Count<nom::combinator::MakeComplete<suricata::quic::frames::parse_tag_and_offset>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
905
16.7k
    let mut res = OM::Output::bind(|| {
906
16.7k
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
16.7k
    });
<nom::multi::Count<nom::number::complete::le_u16<&[u8], nom::error::Error<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
905
38.9k
    let mut res = OM::Output::bind(|| {
906
38.9k
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
38.9k
    });
<nom::multi::Count<nom::number::streaming::le_u16<&[u8], nom::error::Error<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
905
15.1k
    let mut res = OM::Output::bind(|| {
906
15.1k
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
15.1k
    });
<nom::multi::Count<suricata::dns::parser::dns_parse_body::{closure#0}> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
905
4.79M
    let mut res = OM::Output::bind(|| {
906
4.79M
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
4.79M
    });
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bind_iface> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
905
4.55k
    let mut res = OM::Output::bind(|| {
906
4.55k
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
4.55k
    });
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bind_iface_big> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
905
4.53k
    let mut res = OM::Output::bind(|| {
906
4.53k
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
4.53k
    });
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bindack_result> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
905
3.93k
    let mut res = OM::Output::bind(|| {
906
3.93k
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
3.93k
    });
<nom::multi::Count<suricata::dcerpc::parser::parse_dcerpc_bindack_result> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
905
96.8k
    let mut res = OM::Output::bind(|| {
906
96.8k
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
96.8k
    });
Unexecuted instantiation: <nom::multi::Count<_> as nom::internal::Parser<_>>::process::<_>::{closure#0}
908
909
4.97M
    for _ in 0..self.count {
910
8.76M
      let input_ = input.clone();
911
8.76M
      match self.parser.process::<OM>(input_) {
912
8.69M
        Ok((i, o)) => {
913
8.69M
          res = OM::Output::combine(res, o, |mut res, o| {
914
8.69M
            res.push(o);
915
8.69M
            res
916
8.69M
          });
<nom::multi::Count<nom::combinator::MakeComplete<suricata::quic::frames::parse_tag_and_offset>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
913
128k
          res = OM::Output::combine(res, o, |mut res, o| {
914
128k
            res.push(o);
915
128k
            res
916
128k
          });
<nom::multi::Count<nom::number::complete::le_u16<&[u8], nom::error::Error<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
913
398k
          res = OM::Output::combine(res, o, |mut res, o| {
914
398k
            res.push(o);
915
398k
            res
916
398k
          });
<nom::multi::Count<nom::number::streaming::le_u16<&[u8], nom::error::Error<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
913
571k
          res = OM::Output::combine(res, o, |mut res, o| {
914
571k
            res.push(o);
915
571k
            res
916
571k
          });
<nom::multi::Count<suricata::dns::parser::dns_parse_body::{closure#0}> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
913
7.49M
          res = OM::Output::combine(res, o, |mut res, o| {
914
7.49M
            res.push(o);
915
7.49M
            res
916
7.49M
          });
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bind_iface> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
913
18.3k
          res = OM::Output::combine(res, o, |mut res, o| {
914
18.3k
            res.push(o);
915
18.3k
            res
916
18.3k
          });
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bind_iface_big> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
913
40.1k
          res = OM::Output::combine(res, o, |mut res, o| {
914
40.1k
            res.push(o);
915
40.1k
            res
916
40.1k
          });
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bindack_result> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
913
12.4k
          res = OM::Output::combine(res, o, |mut res, o| {
914
12.4k
            res.push(o);
915
12.4k
            res
916
12.4k
          });
<nom::multi::Count<suricata::dcerpc::parser::parse_dcerpc_bindack_result> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Line
Count
Source
913
24.4k
          res = OM::Output::combine(res, o, |mut res, o| {
914
24.4k
            res.push(o);
915
24.4k
            res
916
24.4k
          });
Unexecuted instantiation: <nom::multi::Count<_> as nom::internal::Parser<_>>::process::<_>::{closure#1}
917
8.69M
          input = i;
918
        }
919
43.1k
        Err(Err::Error(e)) => {
920
43.1k
          return Err(Err::Error(OM::Error::map(e, |e| {
921
43.1k
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
43.1k
          })));
<nom::multi::Count<nom::combinator::MakeComplete<suricata::quic::frames::parse_tag_and_offset>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
920
3.17k
          return Err(Err::Error(OM::Error::map(e, |e| {
921
3.17k
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
3.17k
          })));
<nom::multi::Count<nom::number::complete::le_u16<&[u8], nom::error::Error<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
920
1.66k
          return Err(Err::Error(OM::Error::map(e, |e| {
921
1.66k
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
1.66k
          })));
Unexecuted instantiation: <nom::multi::Count<nom::number::streaming::le_u16<&[u8], nom::error::Error<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
<nom::multi::Count<suricata::dns::parser::dns_parse_body::{closure#0}> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
920
38.2k
          return Err(Err::Error(OM::Error::map(e, |e| {
921
38.2k
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
38.2k
          })));
Unexecuted instantiation: <nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bind_iface> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bind_iface_big> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Unexecuted instantiation: <nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bindack_result> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
<nom::multi::Count<suricata::dcerpc::parser::parse_dcerpc_bindack_result> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
920
53
          return Err(Err::Error(OM::Error::map(e, |e| {
921
53
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
53
          })));
Unexecuted instantiation: <nom::multi::Count<_> as nom::internal::Parser<_>>::process::<_>::{closure#2}
923
        }
924
29.2k
        Err(e) => {
925
29.2k
          return Err(e);
926
        }
927
      }
928
    }
929
930
4.90M
    Ok((input, res))
931
4.97M
  }
<nom::multi::Count<nom::combinator::MakeComplete<suricata::quic::frames::parse_tag_and_offset>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
901
16.7k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
16.7k
    let mut input = i.clone();
903
16.7k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
16.7k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
16.7k
    let mut res = OM::Output::bind(|| {
906
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
    });
908
909
16.7k
    for _ in 0..self.count {
910
131k
      let input_ = input.clone();
911
131k
      match self.parser.process::<OM>(input_) {
912
128k
        Ok((i, o)) => {
913
128k
          res = OM::Output::combine(res, o, |mut res, o| {
914
            res.push(o);
915
            res
916
          });
917
128k
          input = i;
918
        }
919
3.17k
        Err(Err::Error(e)) => {
920
3.17k
          return Err(Err::Error(OM::Error::map(e, |e| {
921
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
          })));
923
        }
924
0
        Err(e) => {
925
0
          return Err(e);
926
        }
927
      }
928
    }
929
930
13.6k
    Ok((input, res))
931
16.7k
  }
<nom::multi::Count<nom::number::complete::le_u16<&[u8], nom::error::Error<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
901
38.9k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
38.9k
    let mut input = i.clone();
903
38.9k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
38.9k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
38.9k
    let mut res = OM::Output::bind(|| {
906
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
    });
908
909
38.9k
    for _ in 0..self.count {
910
400k
      let input_ = input.clone();
911
400k
      match self.parser.process::<OM>(input_) {
912
398k
        Ok((i, o)) => {
913
398k
          res = OM::Output::combine(res, o, |mut res, o| {
914
            res.push(o);
915
            res
916
          });
917
398k
          input = i;
918
        }
919
1.66k
        Err(Err::Error(e)) => {
920
1.66k
          return Err(Err::Error(OM::Error::map(e, |e| {
921
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
          })));
923
        }
924
0
        Err(e) => {
925
0
          return Err(e);
926
        }
927
      }
928
    }
929
930
37.2k
    Ok((input, res))
931
38.9k
  }
<nom::multi::Count<nom::number::streaming::le_u16<&[u8], nom::error::Error<&[u8]>>> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
901
15.1k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
15.1k
    let mut input = i.clone();
903
15.1k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
15.1k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
15.1k
    let mut res = OM::Output::bind(|| {
906
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
    });
908
909
15.1k
    for _ in 0..self.count {
910
573k
      let input_ = input.clone();
911
573k
      match self.parser.process::<OM>(input_) {
912
571k
        Ok((i, o)) => {
913
571k
          res = OM::Output::combine(res, o, |mut res, o| {
914
            res.push(o);
915
            res
916
          });
917
571k
          input = i;
918
        }
919
0
        Err(Err::Error(e)) => {
920
0
          return Err(Err::Error(OM::Error::map(e, |e| {
921
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
          })));
923
        }
924
2.75k
        Err(e) => {
925
2.75k
          return Err(e);
926
        }
927
      }
928
    }
929
930
12.3k
    Ok((input, res))
931
15.1k
  }
<nom::multi::Count<suricata::dns::parser::dns_parse_body::{closure#0}> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
901
4.79M
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
4.79M
    let mut input = i.clone();
903
4.79M
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
4.79M
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
4.79M
    let mut res = OM::Output::bind(|| {
906
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
    });
908
909
4.79M
    for _ in 0..self.count {
910
7.55M
      let input_ = input.clone();
911
7.55M
      match self.parser.process::<OM>(input_) {
912
7.49M
        Ok((i, o)) => {
913
7.49M
          res = OM::Output::combine(res, o, |mut res, o| {
914
            res.push(o);
915
            res
916
          });
917
7.49M
          input = i;
918
        }
919
38.2k
        Err(Err::Error(e)) => {
920
38.2k
          return Err(Err::Error(OM::Error::map(e, |e| {
921
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
          })));
923
        }
924
18.5k
        Err(e) => {
925
18.5k
          return Err(e);
926
        }
927
      }
928
    }
929
930
4.73M
    Ok((input, res))
931
4.79M
  }
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bind_iface> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
901
4.55k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
4.55k
    let mut input = i.clone();
903
4.55k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
4.55k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
4.55k
    let mut res = OM::Output::bind(|| {
906
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
    });
908
909
4.55k
    for _ in 0..self.count {
910
20.9k
      let input_ = input.clone();
911
20.9k
      match self.parser.process::<OM>(input_) {
912
18.3k
        Ok((i, o)) => {
913
18.3k
          res = OM::Output::combine(res, o, |mut res, o| {
914
            res.push(o);
915
            res
916
          });
917
18.3k
          input = i;
918
        }
919
0
        Err(Err::Error(e)) => {
920
0
          return Err(Err::Error(OM::Error::map(e, |e| {
921
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
          })));
923
        }
924
2.57k
        Err(e) => {
925
2.57k
          return Err(e);
926
        }
927
      }
928
    }
929
930
1.97k
    Ok((input, res))
931
4.55k
  }
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bind_iface_big> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
901
4.53k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
4.53k
    let mut input = i.clone();
903
4.53k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
4.53k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
4.53k
    let mut res = OM::Output::bind(|| {
906
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
    });
908
909
4.53k
    for _ in 0..self.count {
910
43.8k
      let input_ = input.clone();
911
43.8k
      match self.parser.process::<OM>(input_) {
912
40.1k
        Ok((i, o)) => {
913
40.1k
          res = OM::Output::combine(res, o, |mut res, o| {
914
            res.push(o);
915
            res
916
          });
917
40.1k
          input = i;
918
        }
919
0
        Err(Err::Error(e)) => {
920
0
          return Err(Err::Error(OM::Error::map(e, |e| {
921
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
          })));
923
        }
924
3.71k
        Err(e) => {
925
3.71k
          return Err(e);
926
        }
927
      }
928
    }
929
930
821
    Ok((input, res))
931
4.53k
  }
<nom::multi::Count<suricata::smb::dcerpc_records::parse_dcerpc_bindack_result> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
901
3.93k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
3.93k
    let mut input = i.clone();
903
3.93k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
3.93k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
3.93k
    let mut res = OM::Output::bind(|| {
906
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
    });
908
909
3.93k
    for _ in 0..self.count {
910
13.9k
      let input_ = input.clone();
911
13.9k
      match self.parser.process::<OM>(input_) {
912
12.4k
        Ok((i, o)) => {
913
12.4k
          res = OM::Output::combine(res, o, |mut res, o| {
914
            res.push(o);
915
            res
916
          });
917
12.4k
          input = i;
918
        }
919
0
        Err(Err::Error(e)) => {
920
0
          return Err(Err::Error(OM::Error::map(e, |e| {
921
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
          })));
923
        }
924
1.57k
        Err(e) => {
925
1.57k
          return Err(e);
926
        }
927
      }
928
    }
929
930
2.35k
    Ok((input, res))
931
3.93k
  }
<nom::multi::Count<suricata::dcerpc::parser::parse_dcerpc_bindack_result> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
901
96.8k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
902
96.8k
    let mut input = i.clone();
903
96.8k
    let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
904
96.8k
      / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
905
96.8k
    let mut res = OM::Output::bind(|| {
906
      crate::lib::std::vec::Vec::with_capacity(self.count.min(max_initial_capacity))
907
    });
908
909
96.8k
    for _ in 0..self.count {
910
24.5k
      let input_ = input.clone();
911
24.5k
      match self.parser.process::<OM>(input_) {
912
24.4k
        Ok((i, o)) => {
913
24.4k
          res = OM::Output::combine(res, o, |mut res, o| {
914
            res.push(o);
915
            res
916
          });
917
24.4k
          input = i;
918
        }
919
53
        Err(Err::Error(e)) => {
920
53
          return Err(Err::Error(OM::Error::map(e, |e| {
921
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
922
          })));
923
        }
924
42
        Err(e) => {
925
42
          return Err(e);
926
        }
927
      }
928
    }
929
930
96.7k
    Ok((input, res))
931
96.8k
  }
Unexecuted instantiation: <nom::multi::Count<_> as nom::internal::Parser<_>>::process::<_>
932
}
933
934
/// Runs the embedded parser repeatedly, filling the given slice with results.
935
///
936
/// This parser fails if the input runs out before the given slice is full.
937
///
938
/// # Arguments
939
/// * `f` The parser to apply.
940
/// * `buf` The slice to fill
941
/// ```rust
942
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
943
/// use nom::multi::fill;
944
/// use nom::bytes::complete::tag;
945
///
946
/// fn parser(s: &str) -> IResult<&str, [&str; 2]> {
947
///   let mut buf = ["", ""];
948
///   let (rest, ()) = fill(tag("abc"), &mut buf).parse(s)?;
949
///   Ok((rest, buf))
950
/// }
951
///
952
/// assert_eq!(parser("abcabc"), Ok(("", ["abc", "abc"])));
953
/// assert_eq!(parser("abc123"), Err(Err::Error(Error::new("123", ErrorKind::Tag))));
954
/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Tag))));
955
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
956
/// assert_eq!(parser("abcabcabc"), Ok(("abc", ["abc", "abc"])));
957
/// ```
958
0
pub fn fill<'a, I, E, F>(
959
0
  parser: F,
960
0
  buf: &'a mut [<F as Parser<I>>::Output],
961
0
) -> impl Parser<I, Output = (), Error = E> + 'a
962
0
where
963
0
  I: Clone,
964
0
  F: Parser<I, Error = E> + 'a,
965
0
  E: ParseError<I>,
966
{
967
0
  Fill { parser, buf }
968
0
}
969
970
/// Parser implementation for the [fill] combinator
971
pub struct Fill<'a, F, O> {
972
  parser: F,
973
  buf: &'a mut [O],
974
}
975
976
impl<'a, I, F, O> Parser<I> for Fill<'a, F, O>
977
where
978
  I: Clone,
979
  F: Parser<I, Output = O>,
980
{
981
  type Output = ();
982
  type Error = <F as Parser<I>>::Error;
983
984
0
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
985
0
    let mut input = i.clone();
986
987
0
    for elem in self.buf.iter_mut() {
988
0
      let input_ = input.clone();
989
0
      match self.parser.process::<OM>(input_) {
990
0
        Ok((i, o)) => {
991
0
          OM::Output::map(o, |o| *elem = o);
992
0
          input = i;
993
        }
994
0
        Err(Err::Error(e)) => {
995
0
          return Err(Err::Error(OM::Error::map(e, |e| {
996
0
            <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
997
0
          })));
998
        }
999
0
        Err(e) => {
1000
0
          return Err(e);
1001
        }
1002
      }
1003
    }
1004
1005
0
    Ok((input, OM::Output::bind(|| ())))
1006
0
  }
1007
}
1008
1009
/// Repeats the embedded parser, calling `g` to gather the results.
1010
///
1011
/// This stops on [`Err::Error`]. To instead chain an error up, see
1012
/// [`cut`][crate::combinator::cut].
1013
///
1014
/// # Arguments
1015
/// * `f` The parser to apply.
1016
/// * `init` A function returning the initial value.
1017
/// * `g` The function that combines a result of `f` with
1018
///       the current accumulator.
1019
///
1020
/// *Note*: if the parser passed in accepts empty inputs (like `alpha0` or `digit0`), `many0` will
1021
/// return an error, to prevent going into an infinite loop
1022
///
1023
/// ```rust
1024
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
1025
/// use nom::multi::fold_many0;
1026
/// use nom::bytes::complete::tag;
1027
///
1028
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
1029
///   fold_many0(
1030
///     tag("abc"),
1031
///     Vec::new,
1032
///     |mut acc: Vec<_>, item| {
1033
///       acc.push(item);
1034
///       acc
1035
///     }
1036
///   ).parse(s)
1037
/// }
1038
///
1039
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
1040
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
1041
/// assert_eq!(parser("123123"), Ok(("123123", vec![])));
1042
/// assert_eq!(parser(""), Ok(("", vec![])));
1043
/// ```
1044
426k
pub fn fold_many0<I, E, F, G, H, R>(
1045
426k
  parser: F,
1046
426k
  init: H,
1047
426k
  g: G,
1048
426k
) -> impl Parser<I, Output = R, Error = E>
1049
426k
where
1050
426k
  I: Clone + Input,
1051
426k
  F: Parser<I, Error = E>,
1052
426k
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1053
426k
  H: FnMut() -> R,
1054
426k
  E: ParseError<I>,
1055
{
1056
426k
  FoldMany0 {
1057
426k
    parser,
1058
426k
    g,
1059
426k
    init,
1060
426k
    r: PhantomData,
1061
426k
  }
1062
426k
}
nom::multi::fold_many0::<&[u8], nom::error::Error<&[u8]>, nom::branch::Choice<(suricata_htp::urlencoded::decode_percent::{closure#0}, suricata_htp::urlencoded::decode_plus::{closure#0}, suricata_htp::urlencoded::unencoded_byte::{closure#0})>, suricata_htp::urlencoded::decode_uri::{closure#1}, suricata_htp::urlencoded::decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)>
Line
Count
Source
1044
150k
pub fn fold_many0<I, E, F, G, H, R>(
1045
150k
  parser: F,
1046
150k
  init: H,
1047
150k
  g: G,
1048
150k
) -> impl Parser<I, Output = R, Error = E>
1049
150k
where
1050
150k
  I: Clone + Input,
1051
150k
  F: Parser<I, Error = E>,
1052
150k
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1053
150k
  H: FnMut() -> R,
1054
150k
  E: ParseError<I>,
1055
{
1056
150k
  FoldMany0 {
1057
150k
    parser,
1058
150k
    g,
1059
150k
    init,
1060
150k
    r: PhantomData,
1061
150k
  }
1062
150k
}
nom::multi::fold_many0::<&[u8], nom::error::Error<&[u8]>, nom::branch::Choice<(suricata_htp::urlencoded::path_decode_percent::{closure#0}, suricata_htp::urlencoded::path_parse_other::{closure#0})>, suricata_htp::urlencoded::path_decode_uri::{closure#1}, suricata_htp::urlencoded::path_decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)>
Line
Count
Source
1044
275k
pub fn fold_many0<I, E, F, G, H, R>(
1045
275k
  parser: F,
1046
275k
  init: H,
1047
275k
  g: G,
1048
275k
) -> impl Parser<I, Output = R, Error = E>
1049
275k
where
1050
275k
  I: Clone + Input,
1051
275k
  F: Parser<I, Error = E>,
1052
275k
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1053
275k
  H: FnMut() -> R,
1054
275k
  E: ParseError<I>,
1055
{
1056
275k
  FoldMany0 {
1057
275k
    parser,
1058
275k
    g,
1059
275k
    init,
1060
275k
    r: PhantomData,
1061
275k
  }
1062
275k
}
Unexecuted instantiation: nom::multi::fold_many0::<_, _, _, _, _, _>
1063
1064
/// Parser implementation for the [fold_many0] combinator
1065
pub struct FoldMany0<F, G, Init, R> {
1066
  parser: F,
1067
  g: G,
1068
  init: Init,
1069
  r: PhantomData<R>,
1070
}
1071
1072
impl<I, F, G, Init, R> Parser<I> for FoldMany0<F, G, Init, R>
1073
where
1074
  I: Clone + Input,
1075
  F: Parser<I>,
1076
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1077
  Init: FnMut() -> R,
1078
{
1079
  type Output = R;
1080
  type Error = <F as Parser<I>>::Error;
1081
1082
426k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1083
426k
    let mut res = OM::Output::bind(|| (self.init)());
<nom::multi::FoldMany0<nom::branch::Choice<(suricata_htp::urlencoded::decode_percent::{closure#0}, suricata_htp::urlencoded::decode_plus::{closure#0}, suricata_htp::urlencoded::unencoded_byte::{closure#0})>, suricata_htp::urlencoded::decode_uri::{closure#1}, suricata_htp::urlencoded::decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
1083
150k
    let mut res = OM::Output::bind(|| (self.init)());
<nom::multi::FoldMany0<nom::branch::Choice<(suricata_htp::urlencoded::path_decode_percent::{closure#0}, suricata_htp::urlencoded::path_parse_other::{closure#0})>, suricata_htp::urlencoded::path_decode_uri::{closure#1}, suricata_htp::urlencoded::path_decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#0}
Line
Count
Source
1083
275k
    let mut res = OM::Output::bind(|| (self.init)());
Unexecuted instantiation: <nom::multi::FoldMany0<_, _, _, _> as nom::internal::Parser<_>>::process::<_>::{closure#0}
1084
426k
    let mut input = i;
1085
1086
    loop {
1087
16.1M
      let i_ = input.clone();
1088
16.1M
      let len = input.input_len();
1089
16.1M
      match self.parser.process::<OM>(i_) {
1090
15.7M
        Ok((i, o)) => {
1091
          // infinite loop check: the parser must always consume
1092
15.7M
          if i.input_len() == len {
1093
0
            return Err(Err::Error(OM::Error::bind(|| {
1094
0
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many0)
1095
0
            })));
Unexecuted instantiation: <nom::multi::FoldMany0<nom::branch::Choice<(suricata_htp::urlencoded::decode_percent::{closure#0}, suricata_htp::urlencoded::decode_plus::{closure#0}, suricata_htp::urlencoded::unencoded_byte::{closure#0})>, suricata_htp::urlencoded::decode_uri::{closure#1}, suricata_htp::urlencoded::decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::FoldMany0<nom::branch::Choice<(suricata_htp::urlencoded::path_decode_percent::{closure#0}, suricata_htp::urlencoded::path_parse_other::{closure#0})>, suricata_htp::urlencoded::path_decode_uri::{closure#1}, suricata_htp::urlencoded::path_decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#1}
Unexecuted instantiation: <nom::multi::FoldMany0<_, _, _, _> as nom::internal::Parser<_>>::process::<_>::{closure#1}
1096
15.7M
          }
1097
1098
15.7M
          res = OM::Output::combine(res, o, |res, o| (self.g)(res, o));
<nom::multi::FoldMany0<nom::branch::Choice<(suricata_htp::urlencoded::decode_percent::{closure#0}, suricata_htp::urlencoded::decode_plus::{closure#0}, suricata_htp::urlencoded::unencoded_byte::{closure#0})>, suricata_htp::urlencoded::decode_uri::{closure#1}, suricata_htp::urlencoded::decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
1098
5.25M
          res = OM::Output::combine(res, o, |res, o| (self.g)(res, o));
<nom::multi::FoldMany0<nom::branch::Choice<(suricata_htp::urlencoded::path_decode_percent::{closure#0}, suricata_htp::urlencoded::path_parse_other::{closure#0})>, suricata_htp::urlencoded::path_decode_uri::{closure#1}, suricata_htp::urlencoded::path_decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>::{closure#2}
Line
Count
Source
1098
10.5M
          res = OM::Output::combine(res, o, |res, o| (self.g)(res, o));
Unexecuted instantiation: <nom::multi::FoldMany0<_, _, _, _> as nom::internal::Parser<_>>::process::<_>::{closure#2}
1099
15.7M
          input = i;
1100
        }
1101
        Err(Err::Error(_)) => {
1102
426k
          return Ok((input, res));
1103
        }
1104
0
        Err(e) => {
1105
0
          return Err(e);
1106
        }
1107
      }
1108
    }
1109
426k
  }
<nom::multi::FoldMany0<nom::branch::Choice<(suricata_htp::urlencoded::decode_percent::{closure#0}, suricata_htp::urlencoded::decode_plus::{closure#0}, suricata_htp::urlencoded::unencoded_byte::{closure#0})>, suricata_htp::urlencoded::decode_uri::{closure#1}, suricata_htp::urlencoded::decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
1082
150k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1083
150k
    let mut res = OM::Output::bind(|| (self.init)());
1084
150k
    let mut input = i;
1085
1086
    loop {
1087
5.40M
      let i_ = input.clone();
1088
5.40M
      let len = input.input_len();
1089
5.40M
      match self.parser.process::<OM>(i_) {
1090
5.25M
        Ok((i, o)) => {
1091
          // infinite loop check: the parser must always consume
1092
5.25M
          if i.input_len() == len {
1093
0
            return Err(Err::Error(OM::Error::bind(|| {
1094
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many0)
1095
            })));
1096
5.25M
          }
1097
1098
5.25M
          res = OM::Output::combine(res, o, |res, o| (self.g)(res, o));
1099
5.25M
          input = i;
1100
        }
1101
        Err(Err::Error(_)) => {
1102
150k
          return Ok((input, res));
1103
        }
1104
0
        Err(e) => {
1105
0
          return Err(e);
1106
        }
1107
      }
1108
    }
1109
150k
  }
<nom::multi::FoldMany0<nom::branch::Choice<(suricata_htp::urlencoded::path_decode_percent::{closure#0}, suricata_htp::urlencoded::path_parse_other::{closure#0})>, suricata_htp::urlencoded::path_decode_uri::{closure#1}, suricata_htp::urlencoded::path_decode_uri::{closure#0}, (alloc::vec::Vec<u8>, u64, suricata_htp::config::HtpUnwanted)> as nom::internal::Parser<&[u8]>>::process::<nom::internal::OutputM<nom::internal::Emit, nom::internal::Emit, nom::internal::Streaming>>
Line
Count
Source
1082
275k
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1083
275k
    let mut res = OM::Output::bind(|| (self.init)());
1084
275k
    let mut input = i;
1085
1086
    loop {
1087
10.7M
      let i_ = input.clone();
1088
10.7M
      let len = input.input_len();
1089
10.7M
      match self.parser.process::<OM>(i_) {
1090
10.5M
        Ok((i, o)) => {
1091
          // infinite loop check: the parser must always consume
1092
10.5M
          if i.input_len() == len {
1093
0
            return Err(Err::Error(OM::Error::bind(|| {
1094
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many0)
1095
            })));
1096
10.5M
          }
1097
1098
10.5M
          res = OM::Output::combine(res, o, |res, o| (self.g)(res, o));
1099
10.5M
          input = i;
1100
        }
1101
        Err(Err::Error(_)) => {
1102
275k
          return Ok((input, res));
1103
        }
1104
0
        Err(e) => {
1105
0
          return Err(e);
1106
        }
1107
      }
1108
    }
1109
275k
  }
Unexecuted instantiation: <nom::multi::FoldMany0<_, _, _, _> as nom::internal::Parser<_>>::process::<_>
1110
}
1111
1112
/// Repeats the embedded parser, calling `g` to gather the results.
1113
///
1114
/// This stops on [`Err::Error`] if there is at least one result. To instead chain an error up,
1115
/// see [`cut`][crate::combinator::cut].
1116
///
1117
/// # Arguments
1118
/// * `f` The parser to apply.
1119
/// * `init` A function returning the initial value.
1120
/// * `g` The function that combines a result of `f` with
1121
///       the current accumulator.
1122
///
1123
/// *Note*: If the parser passed to `many1` accepts empty inputs
1124
/// (like `alpha0` or `digit0`), `many1` will return an error,
1125
/// to prevent going into an infinite loop.
1126
///
1127
/// ```rust
1128
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
1129
/// use nom::multi::fold_many1;
1130
/// use nom::bytes::complete::tag;
1131
///
1132
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
1133
///   fold_many1(
1134
///     tag("abc"),
1135
///     Vec::new,
1136
///     |mut acc: Vec<_>, item| {
1137
///       acc.push(item);
1138
///       acc
1139
///     }
1140
///   ).parse(s)
1141
/// }
1142
///
1143
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
1144
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
1145
/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Many1))));
1146
/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Many1))));
1147
/// ```
1148
0
pub fn fold_many1<I, E, F, G, H, R>(
1149
0
  parser: F,
1150
0
  init: H,
1151
0
  g: G,
1152
0
) -> impl Parser<I, Output = R, Error = E>
1153
0
where
1154
0
  I: Clone + Input,
1155
0
  F: Parser<I, Error = E>,
1156
0
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1157
0
  H: FnMut() -> R,
1158
0
  E: ParseError<I>,
1159
{
1160
0
  FoldMany1 {
1161
0
    parser,
1162
0
    g,
1163
0
    init,
1164
0
    r: PhantomData,
1165
0
  }
1166
0
}
1167
1168
/// Parser implementation for the [fold_many1] combinator
1169
pub struct FoldMany1<F, G, Init, R> {
1170
  parser: F,
1171
  g: G,
1172
  init: Init,
1173
  r: PhantomData<R>,
1174
}
1175
1176
impl<I, F, G, Init, R> Parser<I> for FoldMany1<F, G, Init, R>
1177
where
1178
  I: Clone + Input,
1179
  F: Parser<I>,
1180
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1181
  Init: FnMut() -> R,
1182
{
1183
  type Output = R;
1184
  type Error = <F as Parser<I>>::Error;
1185
1186
0
  fn process<OM: OutputMode>(&mut self, i: I) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1187
0
    let mut res = OM::Output::bind(|| (self.init)());
1188
0
    let input = i.clone();
1189
1190
0
    match self.parser.process::<OM>(input) {
1191
0
      Err(Err::Error(_)) => Err(Err::Error(OM::Error::bind(|| {
1192
0
        <F as Parser<I>>::Error::from_error_kind(i, ErrorKind::Many1)
1193
0
      }))),
1194
0
      Err(e) => Err(e),
1195
0
      Ok((i1, o1)) => {
1196
0
        res = OM::Output::combine(res, o1, |res, o| (self.g)(res, o));
1197
1198
0
        let mut input = i1;
1199
        loop {
1200
0
          let i_ = input.clone();
1201
0
          let len = input.input_len();
1202
0
          match self.parser.process::<OM>(i_) {
1203
0
            Ok((i, o)) => {
1204
              // infinite loop check: the parser must always consume
1205
0
              if i.input_len() == len {
1206
0
                return Err(Err::Error(OM::Error::bind(|| {
1207
0
                  <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many1)
1208
0
                })));
1209
0
              }
1210
1211
0
              res = OM::Output::combine(res, o, |res, o| (self.g)(res, o));
1212
0
              input = i;
1213
            }
1214
            Err(Err::Error(_)) => {
1215
0
              return Ok((input, res));
1216
            }
1217
0
            Err(e) => {
1218
0
              return Err(e);
1219
            }
1220
          }
1221
        }
1222
      }
1223
    }
1224
0
  }
1225
}
1226
1227
/// Repeats the embedded parser `m..=n` times, calling `g` to gather the results
1228
///
1229
/// This stops before `n` when the parser returns [`Err::Error`]. To instead chain an error up, see
1230
/// [`cut`][crate::combinator::cut].
1231
///
1232
/// # Arguments
1233
/// * `m` The minimum number of iterations.
1234
/// * `n` The maximum number of iterations.
1235
/// * `f` The parser to apply.
1236
/// * `init` A function returning the initial value.
1237
/// * `g` The function that combines a result of `f` with
1238
///       the current accumulator.
1239
///
1240
/// *Note*: If the parser passed to `many1` accepts empty inputs
1241
/// (like `alpha0` or `digit0`), `many1` will return an error,
1242
/// to prevent going into an infinite loop.
1243
///
1244
/// ```rust
1245
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
1246
/// use nom::multi::fold_many_m_n;
1247
/// use nom::bytes::complete::tag;
1248
///
1249
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
1250
///   fold_many_m_n(
1251
///     0,
1252
///     2,
1253
///     tag("abc"),
1254
///     Vec::new,
1255
///     |mut acc: Vec<_>, item| {
1256
///       acc.push(item);
1257
///       acc
1258
///     }
1259
///   ).parse(s)
1260
/// }
1261
///
1262
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
1263
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
1264
/// assert_eq!(parser("123123"), Ok(("123123", vec![])));
1265
/// assert_eq!(parser(""), Ok(("", vec![])));
1266
/// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
1267
/// ```
1268
0
pub fn fold_many_m_n<I, E, F, G, H, R>(
1269
0
  min: usize,
1270
0
  max: usize,
1271
0
  parser: F,
1272
0
  init: H,
1273
0
  g: G,
1274
0
) -> impl Parser<I, Output = R, Error = E>
1275
0
where
1276
0
  I: Clone + Input,
1277
0
  F: Parser<I, Error = E>,
1278
0
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1279
0
  H: FnMut() -> R,
1280
0
  E: ParseError<I>,
1281
{
1282
0
  FoldManyMN {
1283
0
    parser,
1284
0
    g,
1285
0
    init,
1286
0
    min,
1287
0
    max,
1288
0
    r: PhantomData,
1289
0
  }
1290
0
}
1291
1292
/// Parser implementation for the [fold_many_m_n] combinator
1293
pub struct FoldManyMN<F, G, Init, R> {
1294
  parser: F,
1295
  g: G,
1296
  init: Init,
1297
  r: PhantomData<R>,
1298
  min: usize,
1299
  max: usize,
1300
}
1301
1302
impl<I, F, G, Init, R> Parser<I> for FoldManyMN<F, G, Init, R>
1303
where
1304
  I: Clone + Input,
1305
  F: Parser<I>,
1306
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1307
  Init: FnMut() -> R,
1308
{
1309
  type Output = R;
1310
  type Error = <F as Parser<I>>::Error;
1311
1312
0
  fn process<OM: OutputMode>(
1313
0
    &mut self,
1314
0
    mut input: I,
1315
0
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1316
0
    if self.min > self.max {
1317
0
      return Err(Err::Error(OM::Error::bind(|| {
1318
0
        <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::ManyMN)
1319
0
      })));
1320
0
    }
1321
1322
0
    let mut res = OM::Output::bind(|| (self.init)());
1323
0
    for count in 0..self.max {
1324
0
      let len = input.input_len();
1325
0
      match self.parser.process::<OM>(input.clone()) {
1326
0
        Ok((tail, value)) => {
1327
          // infinite loop check: the parser must always consume
1328
0
          if tail.input_len() == len {
1329
0
            return Err(Err::Error(OM::Error::bind(|| {
1330
0
              <F as Parser<I>>::Error::from_error_kind(tail, ErrorKind::ManyMN)
1331
0
            })));
1332
0
          }
1333
1334
0
          res = OM::Output::combine(res, value, |res, o| (self.g)(res, o));
1335
0
          input = tail;
1336
        }
1337
0
        Err(Err::Error(err)) => {
1338
0
          if count < self.min {
1339
0
            return Err(Err::Error(OM::Error::map(err, |err| {
1340
0
              <F as Parser<I>>::Error::append(input, ErrorKind::ManyMN, err)
1341
0
            })));
1342
          } else {
1343
0
            break;
1344
          }
1345
        }
1346
0
        Err(e) => return Err(e),
1347
      }
1348
    }
1349
1350
0
    Ok((input, res))
1351
0
  }
1352
}
1353
1354
/// Gets a number from the parser and returns a
1355
/// subslice of the input of that size.
1356
/// If the parser returns `Incomplete`,
1357
/// `length_data` will return an error.
1358
/// # Arguments
1359
/// * `f` The parser to apply.
1360
/// ```rust
1361
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
1362
/// use nom::number::complete::be_u16;
1363
/// use nom::multi::length_data;
1364
/// use nom::bytes::complete::tag;
1365
///
1366
/// fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
1367
///   length_data(be_u16).parse(s)
1368
/// }
1369
///
1370
/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"efg"[..], &b"abc"[..])));
1371
/// assert_eq!(parser(b"\x00\x03a"), Err(Err::Incomplete(Needed::new(2))));
1372
/// ```
1373
110M
pub fn length_data<I, E, F>(f: F) -> impl Parser<I, Output = I, Error = E>
1374
110M
where
1375
110M
  I: Input,
1376
110M
  <F as Parser<I>>::Output: ToUsize,
1377
110M
  F: Parser<I, Error = E>,
1378
110M
  E: ParseError<I>,
1379
{
1380
110M
  f.flat_map(|size| take(size))
nom::multi::length_data::<&[u8], nom::error::Error<&[u8]>, nom::number::streaming::be_u8<&[u8], nom::error::Error<&[u8]>>>::{closure#0}
Line
Count
Source
1380
104M
  f.flat_map(|size| take(size))
nom::multi::length_data::<&[u8], nom::error::Error<&[u8]>, nom::number::streaming::be_u16<&[u8], nom::error::Error<&[u8]>>>::{closure#0}
Line
Count
Source
1380
4.49M
  f.flat_map(|size| take(size))
nom::multi::length_data::<&[u8], nom::error::Error<&[u8]>, nom::number::streaming::be_u32<&[u8], nom::error::Error<&[u8]>>>::{closure#0}
Line
Count
Source
1380
299k
  f.flat_map(|size| take(size))
nom::multi::length_data::<&[u8], suricata::rdp::error::RdpError, suricata::rdp::util::parse_per_length_determinant>::{closure#0}
Line
Count
Source
1380
29.7k
  f.flat_map(|size| take(size))
Unexecuted instantiation: nom::multi::length_data::<_, _, _>::{closure#0}
1381
110M
}
nom::multi::length_data::<&[u8], nom::error::Error<&[u8]>, nom::number::streaming::be_u32<&[u8], nom::error::Error<&[u8]>>>
Line
Count
Source
1373
302k
pub fn length_data<I, E, F>(f: F) -> impl Parser<I, Output = I, Error = E>
1374
302k
where
1375
302k
  I: Input,
1376
302k
  <F as Parser<I>>::Output: ToUsize,
1377
302k
  F: Parser<I, Error = E>,
1378
302k
  E: ParseError<I>,
1379
{
1380
302k
  f.flat_map(|size| take(size))
1381
302k
}
nom::multi::length_data::<&[u8], nom::error::Error<&[u8]>, nom::number::streaming::be_u16<&[u8], nom::error::Error<&[u8]>>>
Line
Count
Source
1373
4.99M
pub fn length_data<I, E, F>(f: F) -> impl Parser<I, Output = I, Error = E>
1374
4.99M
where
1375
4.99M
  I: Input,
1376
4.99M
  <F as Parser<I>>::Output: ToUsize,
1377
4.99M
  F: Parser<I, Error = E>,
1378
4.99M
  E: ParseError<I>,
1379
{
1380
4.99M
  f.flat_map(|size| take(size))
1381
4.99M
}
nom::multi::length_data::<&[u8], suricata::rdp::error::RdpError, suricata::rdp::util::parse_per_length_determinant>
Line
Count
Source
1373
30.9k
pub fn length_data<I, E, F>(f: F) -> impl Parser<I, Output = I, Error = E>
1374
30.9k
where
1375
30.9k
  I: Input,
1376
30.9k
  <F as Parser<I>>::Output: ToUsize,
1377
30.9k
  F: Parser<I, Error = E>,
1378
30.9k
  E: ParseError<I>,
1379
{
1380
30.9k
  f.flat_map(|size| take(size))
1381
30.9k
}
nom::multi::length_data::<&[u8], nom::error::Error<&[u8]>, nom::number::streaming::be_u8<&[u8], nom::error::Error<&[u8]>>>
Line
Count
Source
1373
104M
pub fn length_data<I, E, F>(f: F) -> impl Parser<I, Output = I, Error = E>
1374
104M
where
1375
104M
  I: Input,
1376
104M
  <F as Parser<I>>::Output: ToUsize,
1377
104M
  F: Parser<I, Error = E>,
1378
104M
  E: ParseError<I>,
1379
{
1380
104M
  f.flat_map(|size| take(size))
1381
104M
}
Unexecuted instantiation: nom::multi::length_data::<_, _, _>
1382
1383
/// Gets a number from the first parser,
1384
/// takes a subslice of the input of that size,
1385
/// then applies the second parser on that subslice.
1386
/// If the second parser returns `Incomplete`,
1387
/// `length_value` will return an error.
1388
/// # Arguments
1389
/// * `f` The parser to apply.
1390
/// * `g` The parser to apply on the subslice.
1391
/// ```rust
1392
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
1393
/// use nom::number::complete::be_u16;
1394
/// use nom::multi::length_value;
1395
/// use nom::bytes::complete::tag;
1396
///
1397
/// fn parser(s: &[u8]) -> IResult<&[u8], &[u8]> {
1398
///   length_value(be_u16, tag("abc")).parse(s)
1399
/// }
1400
///
1401
/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"efg"[..], &b"abc"[..])));
1402
/// assert_eq!(parser(b"\x00\x03123123"), Err(Err::Error(Error::new(&b"123"[..], ErrorKind::Tag))));
1403
/// assert_eq!(parser(b"\x00\x03a"), Err(Err::Incomplete(Needed::new(2))));
1404
/// ```
1405
0
pub fn length_value<I, E, F, G>(
1406
0
  f: F,
1407
0
  g: G,
1408
0
) -> impl Parser<I, Output = <G as Parser<I>>::Output, Error = E>
1409
0
where
1410
0
  I: Clone + Input,
1411
0
  <F as Parser<I>>::Output: ToUsize,
1412
0
  F: Parser<I, Error = E>,
1413
0
  G: Parser<I, Error = E>,
1414
0
  E: ParseError<I>,
1415
{
1416
  /*f.flat_map(|size| {
1417
    println!("got size: {size}");
1418
    take(size)
1419
  })
1420
  .and_then(g)*/
1421
0
  LengthValue {
1422
0
    length: f,
1423
0
    parser: g,
1424
0
    e: PhantomData,
1425
0
  }
1426
0
}
1427
1428
/// Parser implementation for the [length_value] combinator
1429
pub struct LengthValue<F, G, E> {
1430
  length: F,
1431
  parser: G,
1432
  e: PhantomData<E>,
1433
}
1434
1435
impl<I, F, G, E> Parser<I> for LengthValue<F, G, E>
1436
where
1437
  I: Clone + Input,
1438
  F: Parser<I, Error = E>,
1439
  G: Parser<I, Error = E>,
1440
  <F as Parser<I>>::Output: ToUsize,
1441
  E: ParseError<I>,
1442
{
1443
  type Output = <G as Parser<I>>::Output;
1444
  type Error = E;
1445
1446
0
  fn process<OM: OutputMode>(
1447
0
    &mut self,
1448
0
    input: I,
1449
0
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1450
0
    let (i, length) = self
1451
0
      .length
1452
0
      .process::<OutputM<Emit, OM::Error, OM::Incomplete>>(input)?;
1453
1454
0
    let length: usize = length.to_usize();
1455
1456
0
    if let Some(needed) = length
1457
0
      .checked_sub(i.input_len())
1458
0
      .and_then(NonZeroUsize::new)
1459
    {
1460
0
      Err(Err::Incomplete(Needed::Size(needed)))
1461
    } else {
1462
0
      let (rest, i) = i.take_split(length);
1463
0
      match self.parser.process::<OM>(i.clone()) {
1464
0
        Err(Err::Incomplete(_)) => Err(Err::Error(OM::Error::bind(|| {
1465
0
          E::from_error_kind(i, ErrorKind::Complete)
1466
0
        }))),
1467
0
        Err(e) => Err(e),
1468
0
        Ok((_, o)) => Ok((rest, o)),
1469
      }
1470
    }
1471
0
  }
1472
}
1473
1474
/// Gets a number from the first parser,
1475
/// then applies the second parser that many times.
1476
/// # Arguments
1477
/// * `f` The parser to apply to obtain the count.
1478
/// * `g` The parser to apply repeatedly.
1479
/// ```rust
1480
/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult, Parser};
1481
/// use nom::number::complete::u8;
1482
/// use nom::multi::length_count;
1483
/// use nom::bytes::complete::tag;
1484
/// use nom::combinator::map;
1485
///
1486
/// fn parser(s: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
1487
///   length_count(map(u8, |i| {
1488
///      println!("got number: {}", i);
1489
///      i
1490
///   }), tag("abc")).parse(s)
1491
/// }
1492
///
1493
/// assert_eq!(parser(&b"\x02abcabcabc"[..]), Ok(((&b"abc"[..], vec![&b"abc"[..], &b"abc"[..]]))));
1494
/// assert_eq!(parser(b"\x03123123123"), Err(Err::Error(Error::new(&b"123123123"[..], ErrorKind::Tag))));
1495
/// ```
1496
#[cfg(feature = "alloc")]
1497
0
pub fn length_count<I, E, F, G>(
1498
0
  f: F,
1499
0
  g: G,
1500
0
) -> impl Parser<I, Output = Vec<<G as Parser<I>>::Output>, Error = E>
1501
0
where
1502
0
  I: Clone,
1503
0
  <F as Parser<I>>::Output: ToUsize,
1504
0
  F: Parser<I, Error = E>,
1505
0
  G: Parser<I, Error = E>,
1506
0
  E: ParseError<I>,
1507
{
1508
0
  LengthCount {
1509
0
    length: f,
1510
0
    parser: g,
1511
0
    e: PhantomData,
1512
0
  }
1513
0
}
1514
1515
#[cfg(feature = "alloc")]
1516
/// Parser implementation for the [length_count] combinator
1517
pub struct LengthCount<F, G, E> {
1518
  length: F,
1519
  parser: G,
1520
  e: PhantomData<E>,
1521
}
1522
1523
#[cfg(feature = "alloc")]
1524
impl<I, F, G, E> Parser<I> for LengthCount<F, G, E>
1525
where
1526
  I: Clone,
1527
  F: Parser<I, Error = E>,
1528
  G: Parser<I, Error = E>,
1529
  <F as Parser<I>>::Output: ToUsize,
1530
  E: ParseError<I>,
1531
{
1532
  type Output = Vec<<G as Parser<I>>::Output>;
1533
  type Error = E;
1534
1535
0
  fn process<OM: OutputMode>(
1536
0
    &mut self,
1537
0
    input: I,
1538
0
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1539
0
    match self
1540
0
      .length
1541
0
      .process::<OutputM<Emit, OM::Error, OM::Incomplete>>(input)
1542
    {
1543
0
      Err(e) => Err(e),
1544
0
      Ok((i, count)) => {
1545
0
        let count = count.to_usize();
1546
0
        let mut input = i.clone();
1547
0
        let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES
1548
0
          / crate::lib::std::mem::size_of::<<F as Parser<I>>::Output>().max(1);
1549
0
        let mut res = OM::Output::bind(|| {
1550
0
          crate::lib::std::vec::Vec::with_capacity(count.min(max_initial_capacity))
1551
0
        });
1552
1553
0
        for _ in 0..count {
1554
0
          let input_ = input.clone();
1555
0
          match self.parser.process::<OM>(input_) {
1556
0
            Ok((i, o)) => {
1557
0
              res = OM::Output::combine(res, o, |mut res, o| {
1558
0
                res.push(o);
1559
0
                res
1560
0
              });
1561
0
              input = i;
1562
            }
1563
0
            Err(Err::Error(e)) => {
1564
0
              return Err(Err::Error(OM::Error::map(e, |e| {
1565
0
                <F as Parser<I>>::Error::append(i, ErrorKind::Count, e)
1566
0
              })));
1567
            }
1568
0
            Err(e) => {
1569
0
              return Err(e);
1570
            }
1571
          }
1572
        }
1573
1574
0
        Ok((input, res))
1575
      }
1576
    }
1577
0
  }
1578
}
1579
1580
/// Repeats the embedded parser and collects the results in a type implementing `Extend + Default`.
1581
/// Fails if the amount of time the embedded parser is run is not
1582
/// within the specified range.
1583
/// # Arguments
1584
/// * `range` Constrains the number of iterations.
1585
///   * A range without an upper bound `a..` is equivalent to a range of `a..=usize::MAX`.
1586
///   * A single `usize` value is equivalent to `value..=value`.
1587
///   * An empty range is invalid.
1588
/// * `parse` The parser to apply.
1589
///
1590
/// ```rust
1591
/// # #[macro_use] extern crate nom;
1592
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
1593
/// use nom::multi::many;
1594
/// use nom::bytes::complete::tag;
1595
///
1596
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
1597
///   many(0..=2, tag("abc")).parse(s)
1598
/// }
1599
///
1600
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
1601
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
1602
/// assert_eq!(parser("123123"), Ok(("123123", vec![])));
1603
/// assert_eq!(parser(""), Ok(("", vec![])));
1604
/// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
1605
/// ```
1606
///
1607
/// This is not limited to `Vec`, other collections like `HashMap`
1608
/// can be used:
1609
///
1610
/// ```rust
1611
/// # #[macro_use] extern crate nom;
1612
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
1613
/// use nom::multi::many;
1614
/// use nom::bytes::complete::{tag, take_while};
1615
/// use nom::sequence::{separated_pair, terminated};
1616
/// use nom::AsChar;
1617
///
1618
/// use std::collections::HashMap;
1619
///
1620
/// fn key_value(s: &str) -> IResult<&str, HashMap<&str, &str>> {
1621
///   many(0.., terminated(
1622
///     separated_pair(
1623
///       take_while(AsChar::is_alpha),
1624
///       tag("="),
1625
///       take_while(AsChar::is_alpha)
1626
///     ),
1627
///     tag(";")
1628
///   )).parse(s)
1629
/// }
1630
///
1631
/// assert_eq!(
1632
///   key_value("a=b;c=d;"),
1633
///   Ok(("", HashMap::from([("a", "b"), ("c", "d")])))
1634
/// );
1635
/// ```
1636
///
1637
/// If more control is needed on the default value, [fold] can
1638
/// be used instead:
1639
///
1640
/// ```rust
1641
/// # #[macro_use] extern crate nom;
1642
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
1643
/// use nom::multi::fold;
1644
/// use nom::bytes::complete::tag;
1645
///
1646
///
1647
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
1648
///   fold(
1649
///     0..=4,
1650
///     tag("abc"),
1651
///     // preallocates a vector of the max size
1652
///     || Vec::with_capacity(4),
1653
///     |mut acc: Vec<_>, item| {
1654
///       acc.push(item);
1655
///       acc
1656
///     }
1657
///   ).parse(s)
1658
/// }
1659
///
1660
///
1661
/// assert_eq!(parser("abcabcabcabc"), Ok(("", vec!["abc", "abc", "abc", "abc"])));
1662
/// ```
1663
#[cfg(feature = "alloc")]
1664
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
1665
0
pub fn many<I, E, Collection, F, G>(
1666
0
  range: G,
1667
0
  parser: F,
1668
0
) -> impl Parser<I, Output = Collection, Error = E>
1669
0
where
1670
0
  I: Clone + Input,
1671
0
  F: Parser<I, Error = E>,
1672
0
  Collection: Extend<<F as Parser<I>>::Output> + Default,
1673
0
  E: ParseError<I>,
1674
0
  G: NomRange<usize>,
1675
{
1676
0
  Many {
1677
0
    parser,
1678
0
    range,
1679
0
    c: PhantomData,
1680
0
  }
1681
0
}
1682
1683
/// Parser implementation for the [many] combinator
1684
pub struct Many<F, R, Collection> {
1685
  parser: F,
1686
  range: R,
1687
  c: PhantomData<Collection>,
1688
}
1689
1690
impl<I, F, R, Collection> Parser<I> for Many<F, R, Collection>
1691
where
1692
  I: Clone + Input,
1693
  F: Parser<I>,
1694
  Collection: Extend<<F as Parser<I>>::Output> + Default,
1695
  R: NomRange<usize>,
1696
{
1697
  type Output = Collection;
1698
  type Error = <F as Parser<I>>::Error;
1699
1700
0
  fn process<OM: OutputMode>(
1701
0
    &mut self,
1702
0
    mut input: I,
1703
0
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1704
0
    if self.range.is_inverted() {
1705
0
      return Err(Err::Failure(<F as Parser<I>>::Error::from_error_kind(
1706
0
        input,
1707
0
        ErrorKind::Many,
1708
0
      )));
1709
0
    }
1710
1711
0
    let mut res = OM::Output::bind(Collection::default);
1712
1713
0
    for count in self.range.bounded_iter() {
1714
0
      let len = input.input_len();
1715
0
      match self.parser.process::<OM>(input.clone()) {
1716
0
        Ok((tail, value)) => {
1717
          // infinite loop check: the parser must always consume
1718
0
          if tail.input_len() == len {
1719
0
            return Err(Err::Error(OM::Error::bind(|| {
1720
0
              <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many)
1721
0
            })));
1722
0
          }
1723
1724
0
          res = OM::Output::combine(res, value, |mut res, value| {
1725
0
            res.extend(Some(value));
1726
0
            res
1727
0
          });
1728
0
          input = tail;
1729
        }
1730
0
        Err(Err::Error(e)) => {
1731
0
          if !self.range.contains(&count) {
1732
0
            return Err(Err::Error(OM::Error::map(e, |e| {
1733
0
              <F as Parser<I>>::Error::append(input, ErrorKind::Many, e)
1734
0
            })));
1735
          } else {
1736
0
            return Ok((input, res));
1737
          }
1738
        }
1739
0
        Err(e) => {
1740
0
          return Err(e);
1741
        }
1742
      }
1743
    }
1744
1745
0
    Ok((input, res))
1746
0
  }
1747
}
1748
1749
/// Applies a parser and accumulates the results using a given
1750
/// function and initial value.
1751
/// Fails if the amount of time the embedded parser is run is not
1752
/// within the specified range.
1753
///
1754
/// # Arguments
1755
/// * `range` Constrains the number of iterations.
1756
///   * A range without an upper bound `a..` allows the parser to run until it fails.
1757
///   * A single `usize` value is equivalent to `value..=value`.
1758
///   * An empty range is invalid.
1759
/// * `parse` The parser to apply.
1760
/// * `init` A function returning the initial value.
1761
/// * `fold` The function that combines a result of `f` with
1762
///       the current accumulator.
1763
/// ```rust
1764
/// # #[macro_use] extern crate nom;
1765
/// # use nom::{Err, error::ErrorKind, Needed, IResult, Parser};
1766
/// use nom::multi::fold;
1767
/// use nom::bytes::complete::tag;
1768
///
1769
/// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
1770
///   fold(
1771
///     0..=2,
1772
///     tag("abc"),
1773
///     Vec::new,
1774
///     |mut acc: Vec<_>, item| {
1775
///       acc.push(item);
1776
///       acc
1777
///     }
1778
///   ).parse(s)
1779
/// }
1780
///
1781
/// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
1782
/// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
1783
/// assert_eq!(parser("123123"), Ok(("123123", vec![])));
1784
/// assert_eq!(parser(""), Ok(("", vec![])));
1785
/// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
1786
/// ```
1787
0
pub fn fold<I, E, F, G, H, J, R>(
1788
0
  range: J,
1789
0
  parser: F,
1790
0
  init: H,
1791
0
  fold: G,
1792
0
) -> impl Parser<I, Output = R, Error = E>
1793
0
where
1794
0
  I: Clone + Input,
1795
0
  F: Parser<I, Error = E>,
1796
0
  G: FnMut(R, <F as Parser<I>>::Output) -> R,
1797
0
  H: FnMut() -> R,
1798
0
  E: ParseError<I>,
1799
0
  J: NomRange<usize>,
1800
{
1801
0
  Fold {
1802
0
    parser,
1803
0
    init,
1804
0
    fold,
1805
0
    range,
1806
0
  }
1807
0
}
1808
1809
/// Parser implementation for the [fold] combinator
1810
pub struct Fold<F, G, H, Range> {
1811
  parser: F,
1812
  init: H,
1813
  fold: G,
1814
  range: Range,
1815
}
1816
1817
impl<I, F, G, H, Range, Res> Parser<I> for Fold<F, G, H, Range>
1818
where
1819
  I: Clone + Input,
1820
  F: Parser<I>,
1821
  G: FnMut(Res, <F as Parser<I>>::Output) -> Res,
1822
  H: FnMut() -> Res,
1823
  Range: NomRange<usize>,
1824
{
1825
  type Output = Res;
1826
  type Error = <F as Parser<I>>::Error;
1827
1828
0
  fn process<OM: OutputMode>(
1829
0
    &mut self,
1830
0
    mut input: I,
1831
0
  ) -> crate::PResult<OM, I, Self::Output, Self::Error> {
1832
0
    if self.range.is_inverted() {
1833
0
      return Err(Err::Failure(<F as Parser<I>>::Error::from_error_kind(
1834
0
        input,
1835
0
        ErrorKind::Fold,
1836
0
      )));
1837
0
    }
1838
1839
0
    let mut acc = OM::Output::bind(|| (self.init)());
1840
1841
0
    for count in self.range.saturating_iter() {
1842
0
      let len = input.input_len();
1843
0
      match self.parser.process::<OM>(input.clone()) {
1844
0
        Ok((tail, value)) => {
1845
          // infinite loop check: the parser must always consume
1846
0
          if tail.input_len() == len {
1847
0
            return Err(Err::Error(OM::Error::bind(|| {
1848
0
              <F as Parser<I>>::Error::from_error_kind(tail, ErrorKind::Fold)
1849
0
            })));
1850
0
          }
1851
1852
0
          acc = OM::Output::combine(acc, value, |acc, value| (self.fold)(acc, value));
1853
0
          input = tail;
1854
        }
1855
0
        Err(Err::Error(err)) => {
1856
0
          if !self.range.contains(&count) {
1857
0
            return Err(Err::Error(OM::Error::map(err, |err| {
1858
0
              <F as Parser<I>>::Error::append(input, ErrorKind::Fold, err)
1859
0
            })));
1860
          } else {
1861
0
            break;
1862
          }
1863
        }
1864
0
        Err(e) => return Err(e),
1865
      }
1866
    }
1867
1868
0
    Ok((input, acc))
1869
0
  }
1870
}