summaryrefslogtreecommitdiffstats
path: root/vendor/nom/src/number/complete.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/nom/src/number/complete.rs')
-rw-r--r--vendor/nom/src/number/complete.rs91
1 files changed, 37 insertions, 54 deletions
diff --git a/vendor/nom/src/number/complete.rs b/vendor/nom/src/number/complete.rs
index d23079e76..98b8b3abf 100644
--- a/vendor/nom/src/number/complete.rs
+++ b/vendor/nom/src/number/complete.rs
@@ -13,26 +13,6 @@ use crate::traits::{
AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice,
};
-#[doc(hidden)]
-macro_rules! map(
- // Internal parser, do not use directly
- (__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
- $crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i)
- );
- ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
- map!(__impl $i, $submac!($($args)*), $g)
- );
- ($i:expr, $f:expr, $g:expr) => (
- map!(__impl $i, call!($f), $g)
- );
-);
-
-#[doc(hidden)]
-macro_rules! call (
- ($i:expr, $fun:expr) => ( $fun( $i ) );
- ($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) );
-);
-
/// Recognizes an unsigned 1 byte integer.
///
/// *Complete version*: Returns an error if there is not enough input data.
@@ -211,7 +191,6 @@ where
/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
/// ```
#[inline]
-#[cfg(stable_i128)]
pub fn be_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
@@ -249,7 +228,7 @@ pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, be_u8, |x| x as i8)
+ be_u8.map(|x| x as i8).parse(input)
}
/// Recognizes a big endian signed 2 bytes integer.
@@ -272,7 +251,7 @@ pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, be_u16, |x| x as i16)
+ be_u16.map(|x| x as i16).parse(input)
}
/// Recognizes a big endian signed 3 bytes integer.
@@ -296,16 +275,20 @@ where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
// Same as the unsigned version but we need to sign-extend manually here
- map!(input, be_u24, |x| if x & 0x80_00_00 != 0 {
- (x | 0xff_00_00_00) as i32
- } else {
- x as i32
- })
+ be_u24
+ .map(|x| {
+ if x & 0x80_00_00 != 0 {
+ (x | 0xff_00_00_00) as i32
+ } else {
+ x as i32
+ }
+ })
+ .parse(input)
}
/// Recognizes a big endian signed 4 bytes integer.
///
-/// *Complete version*: Teturns an error if there is not enough input data.
+/// *Complete version*: Returns an error if there is not enough input data.
/// ```rust
/// # use nom::{Err, error::ErrorKind, Needed};
/// # use nom::Needed::Size;
@@ -323,7 +306,7 @@ pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, be_u32, |x| x as i32)
+ be_u32.map(|x| x as i32).parse(input)
}
/// Recognizes a big endian signed 8 bytes integer.
@@ -346,7 +329,7 @@ pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, be_u64, |x| x as i64)
+ be_u64.map(|x| x as i64).parse(input)
}
/// Recognizes a big endian signed 16 bytes integer.
@@ -365,12 +348,11 @@ where
/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
/// ```
#[inline]
-#[cfg(stable_i128)]
pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, be_u128, |x| x as i128)
+ be_u128.map(|x| x as i128).parse(input)
}
/// Recognizes an unsigned 1 byte integer.
@@ -551,7 +533,6 @@ where
/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
/// ```
#[inline]
-#[cfg(stable_i128)]
pub fn le_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
@@ -589,7 +570,7 @@ pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, be_u8, |x| x as i8)
+ be_u8.map(|x| x as i8).parse(input)
}
/// Recognizes a little endian signed 2 bytes integer.
@@ -612,7 +593,7 @@ pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, le_u16, |x| x as i16)
+ le_u16.map(|x| x as i16).parse(input)
}
/// Recognizes a little endian signed 3 bytes integer.
@@ -636,11 +617,15 @@ where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
// Same as the unsigned version but we need to sign-extend manually here
- map!(input, le_u24, |x| if x & 0x80_00_00 != 0 {
- (x | 0xff_00_00_00) as i32
- } else {
- x as i32
- })
+ le_u24
+ .map(|x| {
+ if x & 0x80_00_00 != 0 {
+ (x | 0xff_00_00_00) as i32
+ } else {
+ x as i32
+ }
+ })
+ .parse(input)
}
/// Recognizes a little endian signed 4 bytes integer.
@@ -663,7 +648,7 @@ pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, le_u32, |x| x as i32)
+ le_u32.map(|x| x as i32).parse(input)
}
/// Recognizes a little endian signed 8 bytes integer.
@@ -686,7 +671,7 @@ pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, le_u64, |x| x as i64)
+ le_u64.map(|x| x as i64).parse(input)
}
/// Recognizes a little endian signed 16 bytes integer.
@@ -705,12 +690,11 @@ where
/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
/// ```
#[inline]
-#[cfg(stable_i128)]
pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(input, le_u128, |x| x as i128)
+ le_u128.map(|x| x as i128).parse(input)
}
/// Recognizes an unsigned 1 byte integer
@@ -926,7 +910,6 @@ where
/// assert_eq!(le_u128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
/// ```
#[inline]
-#[cfg(stable_i128)]
pub fn u128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u128, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
@@ -962,7 +945,7 @@ pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
{
- map!(i, u8, |x| x as i8)
+ u8.map(|x| x as i8).parse(i)
}
/// Recognizes a signed 2 byte integer
@@ -1146,7 +1129,6 @@ where
/// assert_eq!(le_i128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
/// ```
#[inline]
-#[cfg(stable_i128)]
pub fn i128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i128, E>
where
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
@@ -1460,7 +1442,10 @@ where
))(input)
}
-/// Recognizes a floating point number in text format and returns the integer, fraction and exponent parts of the input data
+/// Recognizes a floating point number in text format
+///
+/// It returns a tuple of (`sign`, `integer part`, `fraction part` and `exponent`) of the input
+/// data.
///
/// *Complete version*: Can parse until the end of input.
///
@@ -1598,7 +1583,7 @@ where
*/
let (i, s) = recognize_float_or_exceptions(input)?;
match s.parse_to() {
- Some(f) => (Ok((i, f))),
+ Some(f) => Ok((i, f)),
None => Err(crate::Err::Error(E::from_error_kind(
i,
crate::error::ErrorKind::Float,
@@ -1651,7 +1636,7 @@ where
*/
let (i, s) = recognize_float_or_exceptions(input)?;
match s.parse_to() {
- Some(f) => (Ok((i, f))),
+ Some(f) => Ok((i, f)),
None => Err(crate::Err::Error(E::from_error_kind(
i,
crate::error::ErrorKind::Float,
@@ -1752,7 +1737,6 @@ mod tests {
}
#[test]
- #[cfg(stable_i128)]
fn be_i128_tests() {
assert_parse!(
be_i128(
@@ -1869,7 +1853,6 @@ mod tests {
}
#[test]
- #[cfg(stable_i128)]
fn le_i128_tests() {
assert_parse!(
le_i128(
@@ -2116,7 +2099,7 @@ mod tests {
#[cfg(feature = "std")]
fn parse_f64(i: &str) -> IResult<&str, f64, ()> {
- match recognize_float(i) {
+ match recognize_float_or_exceptions(i) {
Err(e) => Err(e),
Ok((i, s)) => {
if s.is_empty() {