Coverage Report

Created: 2025-07-23 07:29

/rust/registry/src/index.crates.io-6f17d22bba15001f/nom-7.1.3/src/character/streaming.rs
Line
Count
Source (jump to first uncovered line)
1
//! Character specific parsers and combinators, streaming version
2
//!
3
//! Functions recognizing specific characters
4
5
use crate::branch::alt;
6
use crate::combinator::opt;
7
use crate::error::ErrorKind;
8
use crate::error::ParseError;
9
use crate::internal::{Err, IResult, Needed};
10
use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
11
use crate::traits::{
12
  AsChar, FindToken, InputIter, InputLength, InputTake, InputTakeAtPosition, Slice,
13
};
14
use crate::traits::{Compare, CompareResult};
15
16
/// Recognizes one character.
17
///
18
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
19
/// # Example
20
///
21
/// ```
22
/// # use nom::{Err, error::{ErrorKind, Error}, Needed, IResult};
23
/// # use nom::character::streaming::char;
24
/// fn parser(i: &str) -> IResult<&str, char> {
25
///     char('a')(i)
26
/// }
27
/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
28
/// assert_eq!(parser("bc"), Err(Err::Error(Error::new("bc", ErrorKind::Char))));
29
/// assert_eq!(parser(""), Err(Err::Incomplete(Needed::new(1))));
30
/// ```
31
4.71M
pub fn char<I, Error: ParseError<I>>(c: char) -> impl Fn(I) -> IResult<I, char, Error>
32
4.71M
where
33
4.71M
  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
34
4.71M
  <I as InputIter>::Item: AsChar,
35
4.71M
{
36
4.71M
  move |i: I| match (i).iter_elements().next().map(|t| {
37
4.71M
    let b = t.as_char() == c;
38
4.71M
    (&c, b)
39
4.71M
  }) {
nom::character::streaming::char::<&[u8], nom::error::Error<&[u8]>>::{closure#0}::{closure#0}
Line
Count
Source
36
2.90M
  move |i: I| match (i).iter_elements().next().map(|t| {
37
2.90M
    let b = t.as_char() == c;
38
2.90M
    (&c, b)
39
2.90M
  }) {
nom::character::streaming::char::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}::{closure#0}
Line
Count
Source
36
138k
  move |i: I| match (i).iter_elements().next().map(|t| {
37
138k
    let b = t.as_char() == c;
38
138k
    (&c, b)
39
138k
  }) {
Unexecuted instantiation: nom::character::streaming::char::<_, _>::{closure#0}::{closure#0}
nom::character::streaming::char::<&[u8], nom::error::Error<&[u8]>>::{closure#0}::{closure#0}
Line
Count
Source
36
1.66M
  move |i: I| match (i).iter_elements().next().map(|t| {
37
1.66M
    let b = t.as_char() == c;
38
1.66M
    (&c, b)
39
1.66M
  }) {
Unexecuted instantiation: nom::character::streaming::char::<_, _>::{closure#0}::{closure#0}
40
228
    None => Err(Err::Incomplete(Needed::new(c.len() - i.input_len()))),
41
826k
    Some((_, false)) => Err(Err::Error(Error::from_char(i, c))),
42
3.88M
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
43
4.71M
  }
nom::character::streaming::char::<&[u8], nom::error::Error<&[u8]>>::{closure#0}
Line
Count
Source
36
2.90M
  move |i: I| match (i).iter_elements().next().map(|t| {
37
    let b = t.as_char() == c;
38
    (&c, b)
39
2.90M
  }) {
40
223
    None => Err(Err::Incomplete(Needed::new(c.len() - i.input_len()))),
41
3.47k
    Some((_, false)) => Err(Err::Error(Error::from_char(i, c))),
42
2.90M
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
43
2.90M
  }
nom::character::streaming::char::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}
Line
Count
Source
36
138k
  move |i: I| match (i).iter_elements().next().map(|t| {
37
    let b = t.as_char() == c;
38
    (&c, b)
39
138k
  }) {
40
0
    None => Err(Err::Incomplete(Needed::new(c.len() - i.input_len()))),
41
67.8k
    Some((_, false)) => Err(Err::Error(Error::from_char(i, c))),
42
70.9k
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
43
138k
  }
Unexecuted instantiation: nom::character::streaming::char::<_, _>::{closure#0}
nom::character::streaming::char::<&[u8], nom::error::Error<&[u8]>>::{closure#0}
Line
Count
Source
36
1.66M
  move |i: I| match (i).iter_elements().next().map(|t| {
37
    let b = t.as_char() == c;
38
    (&c, b)
39
1.66M
  }) {
40
5
    None => Err(Err::Incomplete(Needed::new(c.len() - i.input_len()))),
41
755k
    Some((_, false)) => Err(Err::Error(Error::from_char(i, c))),
42
908k
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
43
1.66M
  }
Unexecuted instantiation: nom::character::streaming::char::<_, _>::{closure#0}
44
4.71M
}
nom::character::streaming::char::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>
Line
Count
Source
31
141k
pub fn char<I, Error: ParseError<I>>(c: char) -> impl Fn(I) -> IResult<I, char, Error>
32
141k
where
33
141k
  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
34
141k
  <I as InputIter>::Item: AsChar,
35
141k
{
36
  move |i: I| match (i).iter_elements().next().map(|t| {
37
    let b = t.as_char() == c;
38
    (&c, b)
39
  }) {
40
    None => Err(Err::Incomplete(Needed::new(c.len() - i.input_len()))),
41
    Some((_, false)) => Err(Err::Error(Error::from_char(i, c))),
42
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
43
  }
44
141k
}
nom::character::streaming::char::<&[u8], nom::error::Error<&[u8]>>
Line
Count
Source
31
2.90M
pub fn char<I, Error: ParseError<I>>(c: char) -> impl Fn(I) -> IResult<I, char, Error>
32
2.90M
where
33
2.90M
  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
34
2.90M
  <I as InputIter>::Item: AsChar,
35
2.90M
{
36
  move |i: I| match (i).iter_elements().next().map(|t| {
37
    let b = t.as_char() == c;
38
    (&c, b)
39
  }) {
40
    None => Err(Err::Incomplete(Needed::new(c.len() - i.input_len()))),
41
    Some((_, false)) => Err(Err::Error(Error::from_char(i, c))),
42
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
43
  }
44
2.90M
}
Unexecuted instantiation: nom::character::streaming::char::<_, _>
nom::character::streaming::char::<&[u8], nom::error::Error<&[u8]>>
Line
Count
Source
31
1.66M
pub fn char<I, Error: ParseError<I>>(c: char) -> impl Fn(I) -> IResult<I, char, Error>
32
1.66M
where
33
1.66M
  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
34
1.66M
  <I as InputIter>::Item: AsChar,
35
1.66M
{
36
  move |i: I| match (i).iter_elements().next().map(|t| {
37
    let b = t.as_char() == c;
38
    (&c, b)
39
  }) {
40
    None => Err(Err::Incomplete(Needed::new(c.len() - i.input_len()))),
41
    Some((_, false)) => Err(Err::Error(Error::from_char(i, c))),
42
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
43
  }
44
1.66M
}
Unexecuted instantiation: nom::character::streaming::char::<_, _>
45
46
/// Recognizes one character and checks that it satisfies a predicate
47
///
48
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
49
/// # Example
50
///
51
/// ```
52
/// # use nom::{Err, error::{ErrorKind, Error}, Needed, IResult};
53
/// # use nom::character::streaming::satisfy;
54
/// fn parser(i: &str) -> IResult<&str, char> {
55
///     satisfy(|c| c == 'a' || c == 'b')(i)
56
/// }
57
/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
58
/// assert_eq!(parser("cd"), Err(Err::Error(Error::new("cd", ErrorKind::Satisfy))));
59
/// assert_eq!(parser(""), Err(Err::Incomplete(Needed::Unknown)));
60
/// ```
61
0
pub fn satisfy<F, I, Error: ParseError<I>>(cond: F) -> impl Fn(I) -> IResult<I, char, Error>
62
0
where
63
0
  I: Slice<RangeFrom<usize>> + InputIter,
64
0
  <I as InputIter>::Item: AsChar,
65
0
  F: Fn(char) -> bool,
66
0
{
67
0
  move |i: I| match (i).iter_elements().next().map(|t| {
68
0
    let c = t.as_char();
69
0
    let b = cond(c);
70
0
    (c, b)
71
0
  }) {
Unexecuted instantiation: nom::character::streaming::satisfy::<_, _, _>::{closure#0}::{closure#0}
Unexecuted instantiation: nom::character::streaming::satisfy::<_, _, _>::{closure#0}::{closure#0}
72
0
    None => Err(Err::Incomplete(Needed::Unknown)),
73
0
    Some((_, false)) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::Satisfy))),
74
0
    Some((c, true)) => Ok((i.slice(c.len()..), c)),
75
0
  }
Unexecuted instantiation: nom::character::streaming::satisfy::<_, _, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::satisfy::<_, _, _>::{closure#0}
76
0
}
Unexecuted instantiation: nom::character::streaming::satisfy::<_, _, _>
Unexecuted instantiation: nom::character::streaming::satisfy::<_, _, _>
77
78
/// Recognizes one of the provided characters.
79
///
80
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
81
/// # Example
82
///
83
/// ```
84
/// # use nom::{Err, error::ErrorKind, Needed};
85
/// # use nom::character::streaming::one_of;
86
/// assert_eq!(one_of::<_, _, (_, ErrorKind)>("abc")("b"), Ok(("", 'b')));
87
/// assert_eq!(one_of::<_, _, (_, ErrorKind)>("a")("bc"), Err(Err::Error(("bc", ErrorKind::OneOf))));
88
/// assert_eq!(one_of::<_, _, (_, ErrorKind)>("a")(""), Err(Err::Incomplete(Needed::new(1))));
89
/// ```
90
0
pub fn one_of<I, T, Error: ParseError<I>>(list: T) -> impl Fn(I) -> IResult<I, char, Error>
91
0
where
92
0
  I: Slice<RangeFrom<usize>> + InputIter,
93
0
  <I as InputIter>::Item: AsChar + Copy,
94
0
  T: FindToken<<I as InputIter>::Item>,
95
0
{
96
0
  move |i: I| match (i).iter_elements().next().map(|c| (c, list.find_token(c))) {
Unexecuted instantiation: nom::character::streaming::one_of::<_, _, _>::{closure#0}::{closure#0}
Unexecuted instantiation: nom::character::streaming::one_of::<_, _, _>::{closure#0}::{closure#0}
97
0
    None => Err(Err::Incomplete(Needed::new(1))),
98
0
    Some((_, false)) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::OneOf))),
99
0
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
100
0
  }
Unexecuted instantiation: nom::character::streaming::one_of::<_, _, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::one_of::<_, _, _>::{closure#0}
101
0
}
Unexecuted instantiation: nom::character::streaming::one_of::<_, _, _>
Unexecuted instantiation: nom::character::streaming::one_of::<_, _, _>
102
103
/// Recognizes a character that is not in the provided characters.
104
///
105
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
106
/// # Example
107
///
108
/// ```
109
/// # use nom::{Err, error::ErrorKind, Needed};
110
/// # use nom::character::streaming::none_of;
111
/// assert_eq!(none_of::<_, _, (_, ErrorKind)>("abc")("z"), Ok(("", 'z')));
112
/// assert_eq!(none_of::<_, _, (_, ErrorKind)>("ab")("a"), Err(Err::Error(("a", ErrorKind::NoneOf))));
113
/// assert_eq!(none_of::<_, _, (_, ErrorKind)>("a")(""), Err(Err::Incomplete(Needed::new(1))));
114
/// ```
115
0
pub fn none_of<I, T, Error: ParseError<I>>(list: T) -> impl Fn(I) -> IResult<I, char, Error>
116
0
where
117
0
  I: Slice<RangeFrom<usize>> + InputIter,
118
0
  <I as InputIter>::Item: AsChar + Copy,
119
0
  T: FindToken<<I as InputIter>::Item>,
120
0
{
121
0
  move |i: I| match (i).iter_elements().next().map(|c| (c, !list.find_token(c))) {
Unexecuted instantiation: nom::character::streaming::none_of::<_, _, _>::{closure#0}::{closure#0}
Unexecuted instantiation: nom::character::streaming::none_of::<_, _, _>::{closure#0}::{closure#0}
122
0
    None => Err(Err::Incomplete(Needed::new(1))),
123
0
    Some((_, false)) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::NoneOf))),
124
0
    Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
125
0
  }
Unexecuted instantiation: nom::character::streaming::none_of::<_, _, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::none_of::<_, _, _>::{closure#0}
126
0
}
Unexecuted instantiation: nom::character::streaming::none_of::<_, _, _>
Unexecuted instantiation: nom::character::streaming::none_of::<_, _, _>
127
128
/// Recognizes the string "\r\n".
129
///
130
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
131
/// # Example
132
///
133
/// ```
134
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
135
/// # use nom::character::streaming::crlf;
136
/// assert_eq!(crlf::<_, (_, ErrorKind)>("\r\nc"), Ok(("c", "\r\n")));
137
/// assert_eq!(crlf::<_, (_, ErrorKind)>("ab\r\nc"), Err(Err::Error(("ab\r\nc", ErrorKind::CrLf))));
138
/// assert_eq!(crlf::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(2))));
139
/// ```
140
6.24M
pub fn crlf<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
141
6.24M
where
142
6.24M
  T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
143
6.24M
  T: InputIter,
144
6.24M
  T: Compare<&'static str>,
145
6.24M
{
146
6.24M
  match input.compare("\r\n") {
147
    //FIXME: is this the right index?
148
4.84M
    CompareResult::Ok => Ok((input.slice(2..), input.slice(0..2))),
149
4.28k
    CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(2))),
150
    CompareResult::Error => {
151
1.39M
      let e: ErrorKind = ErrorKind::CrLf;
152
1.39M
      Err(Err::Error(E::from_error_kind(input, e)))
153
    }
154
  }
155
6.24M
}
nom::character::streaming::crlf::<&[u8], nom::error::Error<&[u8]>>
Line
Count
Source
140
4.66M
pub fn crlf<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
141
4.66M
where
142
4.66M
  T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
143
4.66M
  T: InputIter,
144
4.66M
  T: Compare<&'static str>,
145
4.66M
{
146
4.66M
  match input.compare("\r\n") {
147
    //FIXME: is this the right index?
148
3.91M
    CompareResult::Ok => Ok((input.slice(2..), input.slice(0..2))),
149
4.07k
    CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(2))),
150
    CompareResult::Error => {
151
750k
      let e: ErrorKind = ErrorKind::CrLf;
152
750k
      Err(Err::Error(E::from_error_kind(input, e)))
153
    }
154
  }
155
4.66M
}
Unexecuted instantiation: nom::character::streaming::crlf::<_, _>
nom::character::streaming::crlf::<&[u8], nom::error::Error<&[u8]>>
Line
Count
Source
140
1.57M
pub fn crlf<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
141
1.57M
where
142
1.57M
  T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
143
1.57M
  T: InputIter,
144
1.57M
  T: Compare<&'static str>,
145
1.57M
{
146
1.57M
  match input.compare("\r\n") {
147
    //FIXME: is this the right index?
148
934k
    CompareResult::Ok => Ok((input.slice(2..), input.slice(0..2))),
149
209
    CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(2))),
150
    CompareResult::Error => {
151
644k
      let e: ErrorKind = ErrorKind::CrLf;
152
644k
      Err(Err::Error(E::from_error_kind(input, e)))
153
    }
154
  }
155
1.57M
}
Unexecuted instantiation: nom::character::streaming::crlf::<_, _>
156
157
/// Recognizes a string of any char except '\r\n' or '\n'.
158
///
159
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
160
/// # Example
161
///
162
/// ```
163
/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
164
/// # use nom::character::streaming::not_line_ending;
165
/// assert_eq!(not_line_ending::<_, (_, ErrorKind)>("ab\r\nc"), Ok(("\r\nc", "ab")));
166
/// assert_eq!(not_line_ending::<_, (_, ErrorKind)>("abc"), Err(Err::Incomplete(Needed::Unknown)));
167
/// assert_eq!(not_line_ending::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Unknown)));
168
/// assert_eq!(not_line_ending::<_, (_, ErrorKind)>("a\rb\nc"), Err(Err::Error(("a\rb\nc", ErrorKind::Tag ))));
169
/// assert_eq!(not_line_ending::<_, (_, ErrorKind)>("a\rbc"), Err(Err::Error(("a\rbc", ErrorKind::Tag ))));
170
/// ```
171
0
pub fn not_line_ending<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
172
0
where
173
0
  T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
174
0
  T: InputIter + InputLength,
175
0
  T: Compare<&'static str>,
176
0
  <T as InputIter>::Item: AsChar,
177
0
  <T as InputIter>::Item: AsChar,
178
0
{
179
0
  match input.position(|item| {
180
0
    let c = item.as_char();
181
0
    c == '\r' || c == '\n'
182
0
  }) {
Unexecuted instantiation: nom::character::streaming::not_line_ending::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::not_line_ending::<_, _>::{closure#0}
183
0
    None => Err(Err::Incomplete(Needed::Unknown)),
184
0
    Some(index) => {
185
0
      let mut it = input.slice(index..).iter_elements();
186
0
      let nth = it.next().unwrap().as_char();
187
0
      if nth == '\r' {
188
0
        let sliced = input.slice(index..);
189
0
        let comp = sliced.compare("\r\n");
190
0
        match comp {
191
          //FIXME: calculate the right index
192
0
          CompareResult::Incomplete => Err(Err::Incomplete(Needed::Unknown)),
193
          CompareResult::Error => {
194
0
            let e: ErrorKind = ErrorKind::Tag;
195
0
            Err(Err::Error(E::from_error_kind(input, e)))
196
          }
197
0
          CompareResult::Ok => Ok((input.slice(index..), input.slice(..index))),
198
        }
199
      } else {
200
0
        Ok((input.slice(index..), input.slice(..index)))
201
      }
202
    }
203
  }
204
0
}
Unexecuted instantiation: nom::character::streaming::not_line_ending::<_, _>
Unexecuted instantiation: nom::character::streaming::not_line_ending::<_, _>
205
206
/// Recognizes an end of line (both '\n' and '\r\n').
207
///
208
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
209
/// # Example
210
///
211
/// ```
212
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
213
/// # use nom::character::streaming::line_ending;
214
/// assert_eq!(line_ending::<_, (_, ErrorKind)>("\r\nc"), Ok(("c", "\r\n")));
215
/// assert_eq!(line_ending::<_, (_, ErrorKind)>("ab\r\nc"), Err(Err::Error(("ab\r\nc", ErrorKind::CrLf))));
216
/// assert_eq!(line_ending::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
217
/// ```
218
0
pub fn line_ending<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
219
0
where
220
0
  T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
221
0
  T: InputIter + InputLength,
222
0
  T: Compare<&'static str>,
223
0
{
224
0
  match input.compare("\n") {
225
0
    CompareResult::Ok => Ok((input.slice(1..), input.slice(0..1))),
226
0
    CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(1))),
227
    CompareResult::Error => {
228
0
      match input.compare("\r\n") {
229
        //FIXME: is this the right index?
230
0
        CompareResult::Ok => Ok((input.slice(2..), input.slice(0..2))),
231
0
        CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(2))),
232
0
        CompareResult::Error => Err(Err::Error(E::from_error_kind(input, ErrorKind::CrLf))),
233
      }
234
    }
235
  }
236
0
}
Unexecuted instantiation: nom::character::streaming::line_ending::<_, _>
Unexecuted instantiation: nom::character::streaming::line_ending::<_, _>
237
238
/// Matches a newline character '\\n'.
239
///
240
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
241
/// # Example
242
///
243
/// ```
244
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
245
/// # use nom::character::streaming::newline;
246
/// assert_eq!(newline::<_, (_, ErrorKind)>("\nc"), Ok(("c", '\n')));
247
/// assert_eq!(newline::<_, (_, ErrorKind)>("\r\nc"), Err(Err::Error(("\r\nc", ErrorKind::Char))));
248
/// assert_eq!(newline::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
249
/// ```
250
0
pub fn newline<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
251
0
where
252
0
  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
253
0
  <I as InputIter>::Item: AsChar,
254
0
{
255
0
  char('\n')(input)
256
0
}
Unexecuted instantiation: nom::character::streaming::newline::<_, _>
Unexecuted instantiation: nom::character::streaming::newline::<_, _>
257
258
/// Matches a tab character '\t'.
259
///
260
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
261
/// # Example
262
///
263
/// ```
264
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
265
/// # use nom::character::streaming::tab;
266
/// assert_eq!(tab::<_, (_, ErrorKind)>("\tc"), Ok(("c", '\t')));
267
/// assert_eq!(tab::<_, (_, ErrorKind)>("\r\nc"), Err(Err::Error(("\r\nc", ErrorKind::Char))));
268
/// assert_eq!(tab::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
269
/// ```
270
0
pub fn tab<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
271
0
where
272
0
  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
273
0
  <I as InputIter>::Item: AsChar,
274
0
{
275
0
  char('\t')(input)
276
0
}
Unexecuted instantiation: nom::character::streaming::tab::<_, _>
Unexecuted instantiation: nom::character::streaming::tab::<_, _>
277
278
/// Matches one byte as a character. Note that the input type will
279
/// accept a `str`, but not a `&[u8]`, unlike many other nom parsers.
280
///
281
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
282
/// # Example
283
///
284
/// ```
285
/// # use nom::{character::streaming::anychar, Err, error::ErrorKind, IResult, Needed};
286
/// assert_eq!(anychar::<_, (_, ErrorKind)>("abc"), Ok(("bc",'a')));
287
/// assert_eq!(anychar::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
288
/// ```
289
0
pub fn anychar<T, E: ParseError<T>>(input: T) -> IResult<T, char, E>
290
0
where
291
0
  T: InputIter + InputLength + Slice<RangeFrom<usize>>,
292
0
  <T as InputIter>::Item: AsChar,
293
0
{
294
0
  let mut it = input.iter_indices();
295
0
  match it.next() {
296
0
    None => Err(Err::Incomplete(Needed::new(1))),
297
0
    Some((_, c)) => match it.next() {
298
0
      None => Ok((input.slice(input.input_len()..), c.as_char())),
299
0
      Some((idx, _)) => Ok((input.slice(idx..), c.as_char())),
300
    },
301
  }
302
0
}
Unexecuted instantiation: nom::character::streaming::anychar::<_, _>
Unexecuted instantiation: nom::character::streaming::anychar::<_, _>
303
304
/// Recognizes zero or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
305
///
306
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
307
/// or if no terminating token is found (a non alphabetic character).
308
/// # Example
309
///
310
/// ```
311
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
312
/// # use nom::character::streaming::alpha0;
313
/// assert_eq!(alpha0::<_, (_, ErrorKind)>("ab1c"), Ok(("1c", "ab")));
314
/// assert_eq!(alpha0::<_, (_, ErrorKind)>("1c"), Ok(("1c", "")));
315
/// assert_eq!(alpha0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
316
/// ```
317
0
pub fn alpha0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
318
0
where
319
0
  T: InputTakeAtPosition,
320
0
  <T as InputTakeAtPosition>::Item: AsChar,
321
0
{
322
0
  input.split_at_position(|item| !item.is_alpha())
Unexecuted instantiation: nom::character::streaming::alpha0::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::alpha0::<_, _>::{closure#0}
323
0
}
Unexecuted instantiation: nom::character::streaming::alpha0::<_, _>
Unexecuted instantiation: nom::character::streaming::alpha0::<_, _>
324
325
/// Recognizes one or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
326
///
327
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
328
/// or if no terminating token is found (a non alphabetic character).
329
/// # Example
330
///
331
/// ```
332
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
333
/// # use nom::character::streaming::alpha1;
334
/// assert_eq!(alpha1::<_, (_, ErrorKind)>("aB1c"), Ok(("1c", "aB")));
335
/// assert_eq!(alpha1::<_, (_, ErrorKind)>("1c"), Err(Err::Error(("1c", ErrorKind::Alpha))));
336
/// assert_eq!(alpha1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
337
/// ```
338
0
pub fn alpha1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
339
0
where
340
0
  T: InputTakeAtPosition,
341
0
  <T as InputTakeAtPosition>::Item: AsChar,
342
0
{
343
0
  input.split_at_position1(|item| !item.is_alpha(), ErrorKind::Alpha)
Unexecuted instantiation: nom::character::streaming::alpha1::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::alpha1::<_, _>::{closure#0}
344
0
}
Unexecuted instantiation: nom::character::streaming::alpha1::<_, _>
Unexecuted instantiation: nom::character::streaming::alpha1::<_, _>
345
346
/// Recognizes zero or more ASCII numerical characters: 0-9
347
///
348
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
349
/// or if no terminating token is found (a non digit character).
350
/// # Example
351
///
352
/// ```
353
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
354
/// # use nom::character::streaming::digit0;
355
/// assert_eq!(digit0::<_, (_, ErrorKind)>("21c"), Ok(("c", "21")));
356
/// assert_eq!(digit0::<_, (_, ErrorKind)>("a21c"), Ok(("a21c", "")));
357
/// assert_eq!(digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
358
/// ```
359
0
pub fn digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
360
0
where
361
0
  T: InputTakeAtPosition,
362
0
  <T as InputTakeAtPosition>::Item: AsChar,
363
0
{
364
0
  input.split_at_position(|item| !item.is_dec_digit())
Unexecuted instantiation: nom::character::streaming::digit0::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::digit0::<_, _>::{closure#0}
365
0
}
Unexecuted instantiation: nom::character::streaming::digit0::<_, _>
Unexecuted instantiation: nom::character::streaming::digit0::<_, _>
366
367
/// Recognizes one or more ASCII numerical characters: 0-9
368
///
369
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
370
/// or if no terminating token is found (a non digit character).
371
/// # Example
372
///
373
/// ```
374
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
375
/// # use nom::character::streaming::digit1;
376
/// assert_eq!(digit1::<_, (_, ErrorKind)>("21c"), Ok(("c", "21")));
377
/// assert_eq!(digit1::<_, (_, ErrorKind)>("c1"), Err(Err::Error(("c1", ErrorKind::Digit))));
378
/// assert_eq!(digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
379
/// ```
380
0
pub fn digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
381
0
where
382
0
  T: InputTakeAtPosition,
383
0
  <T as InputTakeAtPosition>::Item: AsChar,
384
0
{
385
0
  input.split_at_position1(|item| !item.is_dec_digit(), ErrorKind::Digit)
Unexecuted instantiation: nom::character::streaming::digit1::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::digit1::<_, _>::{closure#0}
386
0
}
Unexecuted instantiation: nom::character::streaming::digit1::<_, _>
Unexecuted instantiation: nom::character::streaming::digit1::<_, _>
387
388
/// Recognizes zero or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
389
///
390
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
391
/// or if no terminating token is found (a non hexadecimal digit character).
392
/// # Example
393
///
394
/// ```
395
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
396
/// # use nom::character::streaming::hex_digit0;
397
/// assert_eq!(hex_digit0::<_, (_, ErrorKind)>("21cZ"), Ok(("Z", "21c")));
398
/// assert_eq!(hex_digit0::<_, (_, ErrorKind)>("Z21c"), Ok(("Z21c", "")));
399
/// assert_eq!(hex_digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
400
/// ```
401
0
pub fn hex_digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
402
0
where
403
0
  T: InputTakeAtPosition,
404
0
  <T as InputTakeAtPosition>::Item: AsChar,
405
0
{
406
0
  input.split_at_position(|item| !item.is_hex_digit())
Unexecuted instantiation: nom::character::streaming::hex_digit0::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::hex_digit0::<_, _>::{closure#0}
407
0
}
Unexecuted instantiation: nom::character::streaming::hex_digit0::<_, _>
Unexecuted instantiation: nom::character::streaming::hex_digit0::<_, _>
408
409
/// Recognizes one or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
410
///
411
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
412
/// or if no terminating token is found (a non hexadecimal digit character).
413
/// # Example
414
///
415
/// ```
416
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
417
/// # use nom::character::streaming::hex_digit1;
418
/// assert_eq!(hex_digit1::<_, (_, ErrorKind)>("21cZ"), Ok(("Z", "21c")));
419
/// assert_eq!(hex_digit1::<_, (_, ErrorKind)>("H2"), Err(Err::Error(("H2", ErrorKind::HexDigit))));
420
/// assert_eq!(hex_digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
421
/// ```
422
0
pub fn hex_digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
423
0
where
424
0
  T: InputTakeAtPosition,
425
0
  <T as InputTakeAtPosition>::Item: AsChar,
426
0
{
427
0
  input.split_at_position1(|item| !item.is_hex_digit(), ErrorKind::HexDigit)
Unexecuted instantiation: nom::character::streaming::hex_digit1::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::hex_digit1::<_, _>::{closure#0}
428
0
}
Unexecuted instantiation: nom::character::streaming::hex_digit1::<_, _>
Unexecuted instantiation: nom::character::streaming::hex_digit1::<_, _>
429
430
/// Recognizes zero or more octal characters: 0-7
431
///
432
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
433
/// or if no terminating token is found (a non octal digit character).
434
/// # Example
435
///
436
/// ```
437
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
438
/// # use nom::character::streaming::oct_digit0;
439
/// assert_eq!(oct_digit0::<_, (_, ErrorKind)>("21cZ"), Ok(("cZ", "21")));
440
/// assert_eq!(oct_digit0::<_, (_, ErrorKind)>("Z21c"), Ok(("Z21c", "")));
441
/// assert_eq!(oct_digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
442
/// ```
443
0
pub fn oct_digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
444
0
where
445
0
  T: InputTakeAtPosition,
446
0
  <T as InputTakeAtPosition>::Item: AsChar,
447
0
{
448
0
  input.split_at_position(|item| !item.is_oct_digit())
Unexecuted instantiation: nom::character::streaming::oct_digit0::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::oct_digit0::<_, _>::{closure#0}
449
0
}
Unexecuted instantiation: nom::character::streaming::oct_digit0::<_, _>
Unexecuted instantiation: nom::character::streaming::oct_digit0::<_, _>
450
451
/// Recognizes one or more octal characters: 0-7
452
///
453
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
454
/// or if no terminating token is found (a non octal digit character).
455
/// # Example
456
///
457
/// ```
458
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
459
/// # use nom::character::streaming::oct_digit1;
460
/// assert_eq!(oct_digit1::<_, (_, ErrorKind)>("21cZ"), Ok(("cZ", "21")));
461
/// assert_eq!(oct_digit1::<_, (_, ErrorKind)>("H2"), Err(Err::Error(("H2", ErrorKind::OctDigit))));
462
/// assert_eq!(oct_digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
463
/// ```
464
0
pub fn oct_digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
465
0
where
466
0
  T: InputTakeAtPosition,
467
0
  <T as InputTakeAtPosition>::Item: AsChar,
468
0
{
469
0
  input.split_at_position1(|item| !item.is_oct_digit(), ErrorKind::OctDigit)
Unexecuted instantiation: nom::character::streaming::oct_digit1::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::oct_digit1::<_, _>::{closure#0}
470
0
}
Unexecuted instantiation: nom::character::streaming::oct_digit1::<_, _>
Unexecuted instantiation: nom::character::streaming::oct_digit1::<_, _>
471
472
/// Recognizes zero or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
473
///
474
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
475
/// or if no terminating token is found (a non alphanumerical character).
476
/// # Example
477
///
478
/// ```
479
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
480
/// # use nom::character::streaming::alphanumeric0;
481
/// assert_eq!(alphanumeric0::<_, (_, ErrorKind)>("21cZ%1"), Ok(("%1", "21cZ")));
482
/// assert_eq!(alphanumeric0::<_, (_, ErrorKind)>("&Z21c"), Ok(("&Z21c", "")));
483
/// assert_eq!(alphanumeric0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
484
/// ```
485
0
pub fn alphanumeric0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
486
0
where
487
0
  T: InputTakeAtPosition,
488
0
  <T as InputTakeAtPosition>::Item: AsChar,
489
0
{
490
0
  input.split_at_position(|item| !item.is_alphanum())
Unexecuted instantiation: nom::character::streaming::alphanumeric0::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::alphanumeric0::<_, _>::{closure#0}
491
0
}
Unexecuted instantiation: nom::character::streaming::alphanumeric0::<_, _>
Unexecuted instantiation: nom::character::streaming::alphanumeric0::<_, _>
492
493
/// Recognizes one or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
494
///
495
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
496
/// or if no terminating token is found (a non alphanumerical character).
497
/// # Example
498
///
499
/// ```
500
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
501
/// # use nom::character::streaming::alphanumeric1;
502
/// assert_eq!(alphanumeric1::<_, (_, ErrorKind)>("21cZ%1"), Ok(("%1", "21cZ")));
503
/// assert_eq!(alphanumeric1::<_, (_, ErrorKind)>("&H2"), Err(Err::Error(("&H2", ErrorKind::AlphaNumeric))));
504
/// assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
505
/// ```
506
73.2k
pub fn alphanumeric1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
507
73.2k
where
508
73.2k
  T: InputTakeAtPosition,
509
73.2k
  <T as InputTakeAtPosition>::Item: AsChar,
510
73.2k
{
511
277k
  input.split_at_position1(|item| !item.is_alphanum(), ErrorKind::AlphaNumeric)
nom::character::streaming::alphanumeric1::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>::{closure#0}
Line
Count
Source
511
112k
  input.split_at_position1(|item| !item.is_alphanum(), ErrorKind::AlphaNumeric)
Unexecuted instantiation: nom::character::streaming::alphanumeric1::<_, _>::{closure#0}
nom::character::streaming::alphanumeric1::<&[u8], nom::error::Error<&[u8]>>::{closure#0}
Line
Count
Source
511
165k
  input.split_at_position1(|item| !item.is_alphanum(), ErrorKind::AlphaNumeric)
Unexecuted instantiation: nom::character::streaming::alphanumeric1::<_, _>::{closure#0}
512
73.2k
}
nom::character::streaming::alphanumeric1::<&[u8], suricata::pgsql::parser::PgsqlParseError<&[u8]>>
Line
Count
Source
506
30.4k
pub fn alphanumeric1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
507
30.4k
where
508
30.4k
  T: InputTakeAtPosition,
509
30.4k
  <T as InputTakeAtPosition>::Item: AsChar,
510
30.4k
{
511
30.4k
  input.split_at_position1(|item| !item.is_alphanum(), ErrorKind::AlphaNumeric)
512
30.4k
}
Unexecuted instantiation: nom::character::streaming::alphanumeric1::<_, _>
nom::character::streaming::alphanumeric1::<&[u8], nom::error::Error<&[u8]>>
Line
Count
Source
506
42.8k
pub fn alphanumeric1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
507
42.8k
where
508
42.8k
  T: InputTakeAtPosition,
509
42.8k
  <T as InputTakeAtPosition>::Item: AsChar,
510
42.8k
{
511
42.8k
  input.split_at_position1(|item| !item.is_alphanum(), ErrorKind::AlphaNumeric)
512
42.8k
}
Unexecuted instantiation: nom::character::streaming::alphanumeric1::<_, _>
513
514
/// Recognizes zero or more spaces and tabs.
515
///
516
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
517
/// or if no terminating token is found (a non space character).
518
/// # Example
519
///
520
/// ```
521
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
522
/// # use nom::character::streaming::space0;
523
/// assert_eq!(space0::<_, (_, ErrorKind)>(" \t21c"), Ok(("21c", " \t")));
524
/// assert_eq!(space0::<_, (_, ErrorKind)>("Z21c"), Ok(("Z21c", "")));
525
/// assert_eq!(space0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
526
/// ```
527
10.4M
pub fn space0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
528
10.4M
where
529
10.4M
  T: InputTakeAtPosition,
530
10.4M
  <T as InputTakeAtPosition>::Item: AsChar + Clone,
531
10.4M
{
532
11.6M
  input.split_at_position(|item| {
533
11.6M
    let c = item.as_char();
534
11.6M
    !(c == ' ' || c == '\t')
535
11.6M
  })
nom::character::streaming::space0::<&[u8], nom::error::Error<&[u8]>>::{closure#0}
Line
Count
Source
532
11.6M
  input.split_at_position(|item| {
533
11.6M
    let c = item.as_char();
534
11.6M
    !(c == ' ' || c == '\t')
535
11.6M
  })
Unexecuted instantiation: nom::character::streaming::space0::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::space0::<_, _>::{closure#0}
536
10.4M
}
nom::character::streaming::space0::<&[u8], nom::error::Error<&[u8]>>
Line
Count
Source
527
10.4M
pub fn space0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
528
10.4M
where
529
10.4M
  T: InputTakeAtPosition,
530
10.4M
  <T as InputTakeAtPosition>::Item: AsChar + Clone,
531
10.4M
{
532
10.4M
  input.split_at_position(|item| {
533
    let c = item.as_char();
534
    !(c == ' ' || c == '\t')
535
10.4M
  })
536
10.4M
}
Unexecuted instantiation: nom::character::streaming::space0::<_, _>
Unexecuted instantiation: nom::character::streaming::space0::<_, _>
537
/// Recognizes one or more spaces and tabs.
538
///
539
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
540
/// or if no terminating token is found (a non space character).
541
/// # Example
542
///
543
/// ```
544
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
545
/// # use nom::character::streaming::space1;
546
/// assert_eq!(space1::<_, (_, ErrorKind)>(" \t21c"), Ok(("21c", " \t")));
547
/// assert_eq!(space1::<_, (_, ErrorKind)>("H2"), Err(Err::Error(("H2", ErrorKind::Space))));
548
/// assert_eq!(space1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
549
/// ```
550
0
pub fn space1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
551
0
where
552
0
  T: InputTakeAtPosition,
553
0
  <T as InputTakeAtPosition>::Item: AsChar + Clone,
554
0
{
555
0
  input.split_at_position1(
556
0
    |item| {
557
0
      let c = item.as_char();
558
0
      !(c == ' ' || c == '\t')
559
0
    },
Unexecuted instantiation: nom::character::streaming::space1::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::space1::<_, _>::{closure#0}
560
0
    ErrorKind::Space,
561
0
  )
562
0
}
Unexecuted instantiation: nom::character::streaming::space1::<_, _>
Unexecuted instantiation: nom::character::streaming::space1::<_, _>
563
564
/// Recognizes zero or more spaces, tabs, carriage returns and line feeds.
565
///
566
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
567
/// or if no terminating token is found (a non space character).
568
/// # Example
569
///
570
/// ```
571
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
572
/// # use nom::character::streaming::multispace0;
573
/// assert_eq!(multispace0::<_, (_, ErrorKind)>(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
574
/// assert_eq!(multispace0::<_, (_, ErrorKind)>("Z21c"), Ok(("Z21c", "")));
575
/// assert_eq!(multispace0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
576
/// ```
577
0
pub fn multispace0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
578
0
where
579
0
  T: InputTakeAtPosition,
580
0
  <T as InputTakeAtPosition>::Item: AsChar + Clone,
581
0
{
582
0
  input.split_at_position(|item| {
583
0
    let c = item.as_char();
584
0
    !(c == ' ' || c == '\t' || c == '\r' || c == '\n')
585
0
  })
Unexecuted instantiation: nom::character::streaming::multispace0::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::multispace0::<_, _>::{closure#0}
586
0
}
Unexecuted instantiation: nom::character::streaming::multispace0::<_, _>
Unexecuted instantiation: nom::character::streaming::multispace0::<_, _>
587
588
/// Recognizes one or more spaces, tabs, carriage returns and line feeds.
589
///
590
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
591
/// or if no terminating token is found (a non space character).
592
/// # Example
593
///
594
/// ```
595
/// # use nom::{Err, error::ErrorKind, IResult, Needed};
596
/// # use nom::character::streaming::multispace1;
597
/// assert_eq!(multispace1::<_, (_, ErrorKind)>(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
598
/// assert_eq!(multispace1::<_, (_, ErrorKind)>("H2"), Err(Err::Error(("H2", ErrorKind::MultiSpace))));
599
/// assert_eq!(multispace1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
600
/// ```
601
0
pub fn multispace1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
602
0
where
603
0
  T: InputTakeAtPosition,
604
0
  <T as InputTakeAtPosition>::Item: AsChar + Clone,
605
0
{
606
0
  input.split_at_position1(
607
0
    |item| {
608
0
      let c = item.as_char();
609
0
      !(c == ' ' || c == '\t' || c == '\r' || c == '\n')
610
0
    },
Unexecuted instantiation: nom::character::streaming::multispace1::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::multispace1::<_, _>::{closure#0}
611
0
    ErrorKind::MultiSpace,
612
0
  )
613
0
}
Unexecuted instantiation: nom::character::streaming::multispace1::<_, _>
Unexecuted instantiation: nom::character::streaming::multispace1::<_, _>
614
615
0
pub(crate) fn sign<T, E: ParseError<T>>(input: T) -> IResult<T, bool, E>
616
0
where
617
0
  T: Clone + InputTake + InputLength,
618
0
  T: for<'a> Compare<&'a [u8]>,
619
0
{
620
  use crate::bytes::streaming::tag;
621
  use crate::combinator::value;
622
623
0
  let (i, opt_sign) = opt(alt((
624
0
    value(false, tag(&b"-"[..])),
625
0
    value(true, tag(&b"+"[..])),
626
0
  )))(input)?;
627
0
  let sign = opt_sign.unwrap_or(true);
628
0
629
0
  Ok((i, sign))
630
0
}
Unexecuted instantiation: nom::character::streaming::sign::<_, _>
Unexecuted instantiation: nom::character::streaming::sign::<_, _>
631
632
#[doc(hidden)]
633
macro_rules! ints {
634
    ($($t:tt)+) => {
635
        $(
636
        /// will parse a number in text form to a number
637
        ///
638
        /// *Complete version*: can parse until the end of input.
639
0
        pub fn $t<T, E: ParseError<T>>(input: T) -> IResult<T, $t, E>
640
0
            where
641
0
            T: InputIter + Slice<RangeFrom<usize>> + InputLength + InputTake + Clone,
642
0
            <T as InputIter>::Item: AsChar,
643
0
            T: for <'a> Compare<&'a[u8]>,
644
0
            {
645
0
              let (i, sign) = sign(input.clone())?;
646
647
0
                if i.input_len() == 0 {
648
0
                    return Err(Err::Incomplete(Needed::new(1)));
649
0
                }
650
0
651
0
                let mut value: $t = 0;
652
0
                if sign {
653
0
                    for (pos, c) in i.iter_indices() {
654
0
                        match c.as_char().to_digit(10) {
655
                            None => {
656
0
                                if pos == 0 {
657
0
                                    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit)));
658
                                } else {
659
0
                                    return Ok((i.slice(pos..), value));
660
                                }
661
                            },
662
0
                            Some(d) => match value.checked_mul(10).and_then(|v| v.checked_add(d as $t)) {
Unexecuted instantiation: nom::character::streaming::i8::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i16::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i32::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i64::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i128::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i8::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i16::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i32::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i64::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::i128::<_, _>::{closure#0}
663
0
                                None => return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit))),
664
0
                                Some(v) => value = v,
665
                            }
666
                        }
667
                    }
668
                } else {
669
0
                    for (pos, c) in i.iter_indices() {
670
0
                        match c.as_char().to_digit(10) {
671
                            None => {
672
0
                                if pos == 0 {
673
0
                                    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit)));
674
                                } else {
675
0
                                    return Ok((i.slice(pos..), value));
676
                                }
677
                            },
678
0
                            Some(d) => match value.checked_mul(10).and_then(|v| v.checked_sub(d as $t)) {
Unexecuted instantiation: nom::character::streaming::i8::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i16::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i32::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i64::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i128::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i8::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i16::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i32::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i64::<_, _>::{closure#1}
Unexecuted instantiation: nom::character::streaming::i128::<_, _>::{closure#1}
679
0
                                None => return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit))),
680
0
                                Some(v) => value = v,
681
                            }
682
                        }
683
                    }
684
                }
685
686
0
                Err(Err::Incomplete(Needed::new(1)))
687
0
            }
Unexecuted instantiation: nom::character::streaming::i8::<_, _>
Unexecuted instantiation: nom::character::streaming::i16::<_, _>
Unexecuted instantiation: nom::character::streaming::i32::<_, _>
Unexecuted instantiation: nom::character::streaming::i64::<_, _>
Unexecuted instantiation: nom::character::streaming::i128::<_, _>
Unexecuted instantiation: nom::character::streaming::i8::<_, _>
Unexecuted instantiation: nom::character::streaming::i16::<_, _>
Unexecuted instantiation: nom::character::streaming::i32::<_, _>
Unexecuted instantiation: nom::character::streaming::i64::<_, _>
Unexecuted instantiation: nom::character::streaming::i128::<_, _>
688
        )+
689
    }
690
}
691
692
ints! { i8 i16 i32 i64 i128 }
693
694
#[doc(hidden)]
695
macro_rules! uints {
696
    ($($t:tt)+) => {
697
        $(
698
        /// will parse a number in text form to a number
699
        ///
700
        /// *Complete version*: can parse until the end of input.
701
0
        pub fn $t<T, E: ParseError<T>>(input: T) -> IResult<T, $t, E>
702
0
            where
703
0
            T: InputIter + Slice<RangeFrom<usize>> + InputLength,
704
0
            <T as InputIter>::Item: AsChar,
705
0
            {
706
0
                let i = input;
707
0
708
0
                if i.input_len() == 0 {
709
0
                    return Err(Err::Incomplete(Needed::new(1)));
710
0
                }
711
0
712
0
                let mut value: $t = 0;
713
0
                for (pos, c) in i.iter_indices() {
714
0
                    match c.as_char().to_digit(10) {
715
                        None => {
716
0
                            if pos == 0 {
717
0
                                return Err(Err::Error(E::from_error_kind(i, ErrorKind::Digit)));
718
                            } else {
719
0
                                return Ok((i.slice(pos..), value));
720
                            }
721
                        },
722
0
                        Some(d) => match value.checked_mul(10).and_then(|v| v.checked_add(d as $t)) {
Unexecuted instantiation: nom::character::streaming::u8::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u16::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u32::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u64::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u128::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u8::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u16::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u32::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u64::<_, _>::{closure#0}
Unexecuted instantiation: nom::character::streaming::u128::<_, _>::{closure#0}
723
0
                            None => return Err(Err::Error(E::from_error_kind(i, ErrorKind::Digit))),
724
0
                            Some(v) => value = v,
725
                        }
726
                    }
727
                }
728
729
0
                Err(Err::Incomplete(Needed::new(1)))
730
0
            }
Unexecuted instantiation: nom::character::streaming::u8::<_, _>
Unexecuted instantiation: nom::character::streaming::u16::<_, _>
Unexecuted instantiation: nom::character::streaming::u32::<_, _>
Unexecuted instantiation: nom::character::streaming::u64::<_, _>
Unexecuted instantiation: nom::character::streaming::u128::<_, _>
Unexecuted instantiation: nom::character::streaming::u8::<_, _>
Unexecuted instantiation: nom::character::streaming::u16::<_, _>
Unexecuted instantiation: nom::character::streaming::u32::<_, _>
Unexecuted instantiation: nom::character::streaming::u64::<_, _>
Unexecuted instantiation: nom::character::streaming::u128::<_, _>
731
        )+
732
    }
733
}
734
735
uints! { u8 u16 u32 u64 u128 }
736
737
#[cfg(test)]
738
mod tests {
739
  use super::*;
740
  use crate::error::ErrorKind;
741
  use crate::internal::{Err, Needed};
742
  use crate::sequence::pair;
743
  use crate::traits::ParseTo;
744
  use proptest::prelude::*;
745
746
  macro_rules! assert_parse(
747
    ($left: expr, $right: expr) => {
748
      let res: $crate::IResult<_, _, (_, ErrorKind)> = $left;
749
      assert_eq!(res, $right);
750
    };
751
  );
752
753
  #[test]
754
  fn anychar_str() {
755
    use super::anychar;
756
    assert_eq!(anychar::<_, (&str, ErrorKind)>("Ә"), Ok(("", 'Ә')));
757
  }
758
759
  #[test]
760
  fn character() {
761
    let a: &[u8] = b"abcd";
762
    let b: &[u8] = b"1234";
763
    let c: &[u8] = b"a123";
764
    let d: &[u8] = "azé12".as_bytes();
765
    let e: &[u8] = b" ";
766
    let f: &[u8] = b" ;";
767
    //assert_eq!(alpha1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::new(1))));
768
    assert_parse!(alpha1(a), Err(Err::Incomplete(Needed::new(1))));
769
    assert_eq!(alpha1(b), Err(Err::Error((b, ErrorKind::Alpha))));
770
    assert_eq!(alpha1::<_, (_, ErrorKind)>(c), Ok((&c[1..], &b"a"[..])));
771
    assert_eq!(
772
      alpha1::<_, (_, ErrorKind)>(d),
773
      Ok(("é12".as_bytes(), &b"az"[..]))
774
    );
775
    assert_eq!(digit1(a), Err(Err::Error((a, ErrorKind::Digit))));
776
    assert_eq!(
777
      digit1::<_, (_, ErrorKind)>(b),
778
      Err(Err::Incomplete(Needed::new(1)))
779
    );
780
    assert_eq!(digit1(c), Err(Err::Error((c, ErrorKind::Digit))));
781
    assert_eq!(digit1(d), Err(Err::Error((d, ErrorKind::Digit))));
782
    assert_eq!(
783
      hex_digit1::<_, (_, ErrorKind)>(a),
784
      Err(Err::Incomplete(Needed::new(1)))
785
    );
786
    assert_eq!(
787
      hex_digit1::<_, (_, ErrorKind)>(b),
788
      Err(Err::Incomplete(Needed::new(1)))
789
    );
790
    assert_eq!(
791
      hex_digit1::<_, (_, ErrorKind)>(c),
792
      Err(Err::Incomplete(Needed::new(1)))
793
    );
794
    assert_eq!(
795
      hex_digit1::<_, (_, ErrorKind)>(d),
796
      Ok(("zé12".as_bytes(), &b"a"[..]))
797
    );
798
    assert_eq!(hex_digit1(e), Err(Err::Error((e, ErrorKind::HexDigit))));
799
    assert_eq!(oct_digit1(a), Err(Err::Error((a, ErrorKind::OctDigit))));
800
    assert_eq!(
801
      oct_digit1::<_, (_, ErrorKind)>(b),
802
      Err(Err::Incomplete(Needed::new(1)))
803
    );
804
    assert_eq!(oct_digit1(c), Err(Err::Error((c, ErrorKind::OctDigit))));
805
    assert_eq!(oct_digit1(d), Err(Err::Error((d, ErrorKind::OctDigit))));
806
    assert_eq!(
807
      alphanumeric1::<_, (_, ErrorKind)>(a),
808
      Err(Err::Incomplete(Needed::new(1)))
809
    );
810
    //assert_eq!(fix_error!(b,(), alphanumeric1), Ok((empty, b)));
811
    assert_eq!(
812
      alphanumeric1::<_, (_, ErrorKind)>(c),
813
      Err(Err::Incomplete(Needed::new(1)))
814
    );
815
    assert_eq!(
816
      alphanumeric1::<_, (_, ErrorKind)>(d),
817
      Ok(("é12".as_bytes(), &b"az"[..]))
818
    );
819
    assert_eq!(
820
      space1::<_, (_, ErrorKind)>(e),
821
      Err(Err::Incomplete(Needed::new(1)))
822
    );
823
    assert_eq!(space1::<_, (_, ErrorKind)>(f), Ok((&b";"[..], &b" "[..])));
824
  }
825
826
  #[cfg(feature = "alloc")]
827
  #[test]
828
  fn character_s() {
829
    let a = "abcd";
830
    let b = "1234";
831
    let c = "a123";
832
    let d = "azé12";
833
    let e = " ";
834
    assert_eq!(
835
      alpha1::<_, (_, ErrorKind)>(a),
836
      Err(Err::Incomplete(Needed::new(1)))
837
    );
838
    assert_eq!(alpha1(b), Err(Err::Error((b, ErrorKind::Alpha))));
839
    assert_eq!(alpha1::<_, (_, ErrorKind)>(c), Ok((&c[1..], &"a"[..])));
840
    assert_eq!(alpha1::<_, (_, ErrorKind)>(d), Ok(("é12", &"az"[..])));
841
    assert_eq!(digit1(a), Err(Err::Error((a, ErrorKind::Digit))));
842
    assert_eq!(
843
      digit1::<_, (_, ErrorKind)>(b),
844
      Err(Err::Incomplete(Needed::new(1)))
845
    );
846
    assert_eq!(digit1(c), Err(Err::Error((c, ErrorKind::Digit))));
847
    assert_eq!(digit1(d), Err(Err::Error((d, ErrorKind::Digit))));
848
    assert_eq!(
849
      hex_digit1::<_, (_, ErrorKind)>(a),
850
      Err(Err::Incomplete(Needed::new(1)))
851
    );
852
    assert_eq!(
853
      hex_digit1::<_, (_, ErrorKind)>(b),
854
      Err(Err::Incomplete(Needed::new(1)))
855
    );
856
    assert_eq!(
857
      hex_digit1::<_, (_, ErrorKind)>(c),
858
      Err(Err::Incomplete(Needed::new(1)))
859
    );
860
    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(d), Ok(("zé12", &"a"[..])));
861
    assert_eq!(hex_digit1(e), Err(Err::Error((e, ErrorKind::HexDigit))));
862
    assert_eq!(oct_digit1(a), Err(Err::Error((a, ErrorKind::OctDigit))));
863
    assert_eq!(
864
      oct_digit1::<_, (_, ErrorKind)>(b),
865
      Err(Err::Incomplete(Needed::new(1)))
866
    );
867
    assert_eq!(oct_digit1(c), Err(Err::Error((c, ErrorKind::OctDigit))));
868
    assert_eq!(oct_digit1(d), Err(Err::Error((d, ErrorKind::OctDigit))));
869
    assert_eq!(
870
      alphanumeric1::<_, (_, ErrorKind)>(a),
871
      Err(Err::Incomplete(Needed::new(1)))
872
    );
873
    //assert_eq!(fix_error!(b,(), alphanumeric1), Ok((empty, b)));
874
    assert_eq!(
875
      alphanumeric1::<_, (_, ErrorKind)>(c),
876
      Err(Err::Incomplete(Needed::new(1)))
877
    );
878
    assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(d), Ok(("é12", "az")));
879
    assert_eq!(
880
      space1::<_, (_, ErrorKind)>(e),
881
      Err(Err::Incomplete(Needed::new(1)))
882
    );
883
  }
884
885
  use crate::traits::Offset;
886
  #[test]
887
  fn offset() {
888
    let a = &b"abcd;"[..];
889
    let b = &b"1234;"[..];
890
    let c = &b"a123;"[..];
891
    let d = &b" \t;"[..];
892
    let e = &b" \t\r\n;"[..];
893
    let f = &b"123abcDEF;"[..];
894
895
    match alpha1::<_, (_, ErrorKind)>(a) {
896
      Ok((i, _)) => {
897
        assert_eq!(a.offset(i) + i.len(), a.len());
898
      }
899
      _ => panic!("wrong return type in offset test for alpha"),
900
    }
901
    match digit1::<_, (_, ErrorKind)>(b) {
902
      Ok((i, _)) => {
903
        assert_eq!(b.offset(i) + i.len(), b.len());
904
      }
905
      _ => panic!("wrong return type in offset test for digit"),
906
    }
907
    match alphanumeric1::<_, (_, ErrorKind)>(c) {
908
      Ok((i, _)) => {
909
        assert_eq!(c.offset(i) + i.len(), c.len());
910
      }
911
      _ => panic!("wrong return type in offset test for alphanumeric"),
912
    }
913
    match space1::<_, (_, ErrorKind)>(d) {
914
      Ok((i, _)) => {
915
        assert_eq!(d.offset(i) + i.len(), d.len());
916
      }
917
      _ => panic!("wrong return type in offset test for space"),
918
    }
919
    match multispace1::<_, (_, ErrorKind)>(e) {
920
      Ok((i, _)) => {
921
        assert_eq!(e.offset(i) + i.len(), e.len());
922
      }
923
      _ => panic!("wrong return type in offset test for multispace"),
924
    }
925
    match hex_digit1::<_, (_, ErrorKind)>(f) {
926
      Ok((i, _)) => {
927
        assert_eq!(f.offset(i) + i.len(), f.len());
928
      }
929
      _ => panic!("wrong return type in offset test for hex_digit"),
930
    }
931
    match oct_digit1::<_, (_, ErrorKind)>(f) {
932
      Ok((i, _)) => {
933
        assert_eq!(f.offset(i) + i.len(), f.len());
934
      }
935
      _ => panic!("wrong return type in offset test for oct_digit"),
936
    }
937
  }
938
939
  #[test]
940
  fn is_not_line_ending_bytes() {
941
    let a: &[u8] = b"ab12cd\nefgh";
942
    assert_eq!(
943
      not_line_ending::<_, (_, ErrorKind)>(a),
944
      Ok((&b"\nefgh"[..], &b"ab12cd"[..]))
945
    );
946
947
    let b: &[u8] = b"ab12cd\nefgh\nijkl";
948
    assert_eq!(
949
      not_line_ending::<_, (_, ErrorKind)>(b),
950
      Ok((&b"\nefgh\nijkl"[..], &b"ab12cd"[..]))
951
    );
952
953
    let c: &[u8] = b"ab12cd\r\nefgh\nijkl";
954
    assert_eq!(
955
      not_line_ending::<_, (_, ErrorKind)>(c),
956
      Ok((&b"\r\nefgh\nijkl"[..], &b"ab12cd"[..]))
957
    );
958
959
    let d: &[u8] = b"ab12cd";
960
    assert_eq!(
961
      not_line_ending::<_, (_, ErrorKind)>(d),
962
      Err(Err::Incomplete(Needed::Unknown))
963
    );
964
  }
965
966
  #[test]
967
  fn is_not_line_ending_str() {
968
    /*
969
    let a: &str = "ab12cd\nefgh";
970
    assert_eq!(not_line_ending(a), Ok((&"\nefgh"[..], &"ab12cd"[..])));
971
972
    let b: &str = "ab12cd\nefgh\nijkl";
973
    assert_eq!(not_line_ending(b), Ok((&"\nefgh\nijkl"[..], &"ab12cd"[..])));
974
975
    let c: &str = "ab12cd\r\nefgh\nijkl";
976
    assert_eq!(not_line_ending(c), Ok((&"\r\nefgh\nijkl"[..], &"ab12cd"[..])));
977
978
    let d = "βèƒôřè\nÂßÇáƒƭèř";
979
    assert_eq!(not_line_ending(d), Ok((&"\nÂßÇáƒƭèř"[..], &"βèƒôřè"[..])));
980
981
    let e = "βèƒôřè\r\nÂßÇáƒƭèř";
982
    assert_eq!(not_line_ending(e), Ok((&"\r\nÂßÇáƒƭèř"[..], &"βèƒôřè"[..])));
983
    */
984
985
    let f = "βèƒôřè\rÂßÇáƒƭèř";
986
    assert_eq!(not_line_ending(f), Err(Err::Error((f, ErrorKind::Tag))));
987
988
    let g2: &str = "ab12cd";
989
    assert_eq!(
990
      not_line_ending::<_, (_, ErrorKind)>(g2),
991
      Err(Err::Incomplete(Needed::Unknown))
992
    );
993
  }
994
995
  #[test]
996
  fn hex_digit_test() {
997
    let i = &b"0123456789abcdefABCDEF;"[..];
998
    assert_parse!(hex_digit1(i), Ok((&b";"[..], &i[..i.len() - 1])));
999
1000
    let i = &b"g"[..];
1001
    assert_parse!(
1002
      hex_digit1(i),
1003
      Err(Err::Error(error_position!(i, ErrorKind::HexDigit)))
1004
    );
1005
1006
    let i = &b"G"[..];
1007
    assert_parse!(
1008
      hex_digit1(i),
1009
      Err(Err::Error(error_position!(i, ErrorKind::HexDigit)))
1010
    );
1011
1012
    assert!(crate::character::is_hex_digit(b'0'));
1013
    assert!(crate::character::is_hex_digit(b'9'));
1014
    assert!(crate::character::is_hex_digit(b'a'));
1015
    assert!(crate::character::is_hex_digit(b'f'));
1016
    assert!(crate::character::is_hex_digit(b'A'));
1017
    assert!(crate::character::is_hex_digit(b'F'));
1018
    assert!(!crate::character::is_hex_digit(b'g'));
1019
    assert!(!crate::character::is_hex_digit(b'G'));
1020
    assert!(!crate::character::is_hex_digit(b'/'));
1021
    assert!(!crate::character::is_hex_digit(b':'));
1022
    assert!(!crate::character::is_hex_digit(b'@'));
1023
    assert!(!crate::character::is_hex_digit(b'\x60'));
1024
  }
1025
1026
  #[test]
1027
  fn oct_digit_test() {
1028
    let i = &b"01234567;"[..];
1029
    assert_parse!(oct_digit1(i), Ok((&b";"[..], &i[..i.len() - 1])));
1030
1031
    let i = &b"8"[..];
1032
    assert_parse!(
1033
      oct_digit1(i),
1034
      Err(Err::Error(error_position!(i, ErrorKind::OctDigit)))
1035
    );
1036
1037
    assert!(crate::character::is_oct_digit(b'0'));
1038
    assert!(crate::character::is_oct_digit(b'7'));
1039
    assert!(!crate::character::is_oct_digit(b'8'));
1040
    assert!(!crate::character::is_oct_digit(b'9'));
1041
    assert!(!crate::character::is_oct_digit(b'a'));
1042
    assert!(!crate::character::is_oct_digit(b'A'));
1043
    assert!(!crate::character::is_oct_digit(b'/'));
1044
    assert!(!crate::character::is_oct_digit(b':'));
1045
    assert!(!crate::character::is_oct_digit(b'@'));
1046
    assert!(!crate::character::is_oct_digit(b'\x60'));
1047
  }
1048
1049
  #[test]
1050
  fn full_line_windows() {
1051
    fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
1052
      pair(not_line_ending, line_ending)(i)
1053
    }
1054
    let input = b"abc\r\n";
1055
    let output = take_full_line(input);
1056
    assert_eq!(output, Ok((&b""[..], (&b"abc"[..], &b"\r\n"[..]))));
1057
  }
1058
1059
  #[test]
1060
  fn full_line_unix() {
1061
    fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
1062
      pair(not_line_ending, line_ending)(i)
1063
    }
1064
    let input = b"abc\n";
1065
    let output = take_full_line(input);
1066
    assert_eq!(output, Ok((&b""[..], (&b"abc"[..], &b"\n"[..]))));
1067
  }
1068
1069
  #[test]
1070
  fn check_windows_lineending() {
1071
    let input = b"\r\n";
1072
    let output = line_ending(&input[..]);
1073
    assert_parse!(output, Ok((&b""[..], &b"\r\n"[..])));
1074
  }
1075
1076
  #[test]
1077
  fn check_unix_lineending() {
1078
    let input = b"\n";
1079
    let output = line_ending(&input[..]);
1080
    assert_parse!(output, Ok((&b""[..], &b"\n"[..])));
1081
  }
1082
1083
  #[test]
1084
  fn cr_lf() {
1085
    assert_parse!(crlf(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
1086
    assert_parse!(crlf(&b"\r"[..]), Err(Err::Incomplete(Needed::new(2))));
1087
    assert_parse!(
1088
      crlf(&b"\ra"[..]),
1089
      Err(Err::Error(error_position!(&b"\ra"[..], ErrorKind::CrLf)))
1090
    );
1091
1092
    assert_parse!(crlf("\r\na"), Ok(("a", "\r\n")));
1093
    assert_parse!(crlf("\r"), Err(Err::Incomplete(Needed::new(2))));
1094
    assert_parse!(
1095
      crlf("\ra"),
1096
      Err(Err::Error(error_position!("\ra", ErrorKind::CrLf)))
1097
    );
1098
  }
1099
1100
  #[test]
1101
  fn end_of_line() {
1102
    assert_parse!(line_ending(&b"\na"[..]), Ok((&b"a"[..], &b"\n"[..])));
1103
    assert_parse!(line_ending(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
1104
    assert_parse!(
1105
      line_ending(&b"\r"[..]),
1106
      Err(Err::Incomplete(Needed::new(2)))
1107
    );
1108
    assert_parse!(
1109
      line_ending(&b"\ra"[..]),
1110
      Err(Err::Error(error_position!(&b"\ra"[..], ErrorKind::CrLf)))
1111
    );
1112
1113
    assert_parse!(line_ending("\na"), Ok(("a", "\n")));
1114
    assert_parse!(line_ending("\r\na"), Ok(("a", "\r\n")));
1115
    assert_parse!(line_ending("\r"), Err(Err::Incomplete(Needed::new(2))));
1116
    assert_parse!(
1117
      line_ending("\ra"),
1118
      Err(Err::Error(error_position!("\ra", ErrorKind::CrLf)))
1119
    );
1120
  }
1121
1122
  fn digit_to_i16(input: &str) -> IResult<&str, i16> {
1123
    let i = input;
1124
    let (i, opt_sign) = opt(alt((char('+'), char('-'))))(i)?;
1125
    let sign = match opt_sign {
1126
      Some('+') => true,
1127
      Some('-') => false,
1128
      _ => true,
1129
    };
1130
1131
    let (i, s) = match digit1::<_, crate::error::Error<_>>(i) {
1132
      Ok((i, s)) => (i, s),
1133
      Err(Err::Incomplete(i)) => return Err(Err::Incomplete(i)),
1134
      Err(_) => {
1135
        return Err(Err::Error(crate::error::Error::from_error_kind(
1136
          input,
1137
          ErrorKind::Digit,
1138
        )))
1139
      }
1140
    };
1141
    match s.parse_to() {
1142
      Some(n) => {
1143
        if sign {
1144
          Ok((i, n))
1145
        } else {
1146
          Ok((i, -n))
1147
        }
1148
      }
1149
      None => Err(Err::Error(crate::error::Error::from_error_kind(
1150
        i,
1151
        ErrorKind::Digit,
1152
      ))),
1153
    }
1154
  }
1155
1156
  fn digit_to_u32(i: &str) -> IResult<&str, u32> {
1157
    let (i, s) = digit1(i)?;
1158
    match s.parse_to() {
1159
      Some(n) => Ok((i, n)),
1160
      None => Err(Err::Error(crate::error::Error::from_error_kind(
1161
        i,
1162
        ErrorKind::Digit,
1163
      ))),
1164
    }
1165
  }
1166
1167
  proptest! {
1168
    #[test]
1169
    fn ints(s in "\\PC*") {
1170
        let res1 = digit_to_i16(&s);
1171
        let res2 = i16(s.as_str());
1172
        assert_eq!(res1, res2);
1173
    }
1174
1175
    #[test]
1176
    fn uints(s in "\\PC*") {
1177
        let res1 = digit_to_u32(&s);
1178
        let res2 = u32(s.as_str());
1179
        assert_eq!(res1, res2);
1180
    }
1181
  }
1182
}