@@ -12,26 +12,6 @@ use crate::traits::{
1212 AsBytes , AsChar , Compare , InputIter , InputLength , InputTake , InputTakeAtPosition , Offset , Slice ,
1313} ;
1414
15- #[ doc( hidden) ]
16- macro_rules! map(
17- // Internal parser, do not use directly
18- ( __impl $i: expr, $submac: ident!( $( $args: tt) * ) , $g: expr) => (
19- $crate:: combinator:: map( move |i| { $submac!( i, $( $args) * ) } , $g) . parse( $i)
20- ) ;
21- ( $i: expr, $submac: ident!( $( $args: tt) * ) , $g: expr) => (
22- map!( __impl $i, $submac!( $( $args) * ) , $g)
23- ) ;
24- ( $i: expr, $f: expr, $g: expr) => (
25- map!( __impl $i, call!( $f) , $g)
26- ) ;
27- ) ;
28-
29- #[ doc( hidden) ]
30- macro_rules! call (
31- ( $i: expr, $fun: expr) => ( $fun( $i ) ) ;
32- ( $i: expr, $fun: expr, $( $args: expr) ,* ) => ( $fun( $i, $( $args) ,* ) ) ;
33- ) ;
34-
3515/// Recognizes an unsigned 1 byte integer.
3616///
3717/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
@@ -242,7 +222,7 @@ pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
242222where
243223 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
244224{
245- map ! ( input , be_u8 , |x| x as i8 )
225+ be_u8 . map ( |x| x as i8 ) . parse ( input )
246226}
247227
248228/// Recognizes a big endian signed 2 bytes integer.
@@ -262,7 +242,7 @@ pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
262242where
263243 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
264244{
265- map ! ( input , be_u16 , |x| x as i16 )
245+ be_u16 . map ( |x| x as i16 ) . parse ( input )
266246}
267247
268248/// Recognizes a big endian signed 3 bytes integer.
@@ -283,11 +263,15 @@ where
283263 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
284264{
285265 // Same as the unsigned version but we need to sign-extend manually here
286- map ! ( input, be_u24, |x| if x & 0x80_00_00 != 0 {
287- ( x | 0xff_00_00_00 ) as i32
288- } else {
289- x as i32
290- } )
266+ be_u24
267+ . map ( |x| {
268+ if x & 0x80_00_00 != 0 {
269+ ( x | 0xff_00_00_00 ) as i32
270+ } else {
271+ x as i32
272+ }
273+ } )
274+ . parse ( input)
291275}
292276
293277/// Recognizes a big endian signed 4 bytes integer.
@@ -307,7 +291,7 @@ pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
307291where
308292 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
309293{
310- map ! ( input , be_u32 , |x| x as i32 )
294+ be_u32 . map ( |x| x as i32 ) . parse ( input )
311295}
312296
313297/// Recognizes a big endian signed 8 bytes integer.
@@ -328,7 +312,7 @@ pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
328312where
329313 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
330314{
331- map ! ( input , be_u64 , |x| x as i64 )
315+ be_u64 . map ( |x| x as i64 ) . parse ( input )
332316}
333317
334318/// Recognizes a big endian signed 16 bytes integer.
@@ -348,7 +332,7 @@ pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
348332where
349333 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
350334{
351- map ! ( input , be_u128 , |x| x as i128 )
335+ be_u128 . map ( |x| x as i128 ) . parse ( input )
352336}
353337
354338/// Recognizes an unsigned 1 byte integer.
@@ -560,7 +544,7 @@ pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
560544where
561545 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
562546{
563- map ! ( input , le_u8 , |x| x as i8 )
547+ le_u8 . map ( |x| x as i8 ) . parse ( input )
564548}
565549
566550/// Recognizes a little endian signed 2 bytes integer.
@@ -583,7 +567,7 @@ pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
583567where
584568 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
585569{
586- map ! ( input , le_u16 , |x| x as i16 )
570+ le_u16 . map ( |x| x as i16 ) . parse ( input )
587571}
588572
589573/// Recognizes a little endian signed 3 bytes integer.
@@ -607,11 +591,15 @@ where
607591 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
608592{
609593 // Same as the unsigned version but we need to sign-extend manually here
610- map ! ( input, le_u24, |x| if x & 0x80_00_00 != 0 {
611- ( x | 0xff_00_00_00 ) as i32
612- } else {
613- x as i32
614- } )
594+ le_u24
595+ . map ( |x| {
596+ if x & 0x80_00_00 != 0 {
597+ ( x | 0xff_00_00_00 ) as i32
598+ } else {
599+ x as i32
600+ }
601+ } )
602+ . parse ( input)
615603}
616604
617605/// Recognizes a little endian signed 4 bytes integer.
@@ -634,7 +622,7 @@ pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
634622where
635623 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
636624{
637- map ! ( input , le_u32 , |x| x as i32 )
625+ le_u32 . map ( |x| x as i32 ) . parse ( input )
638626}
639627
640628/// Recognizes a little endian signed 8 bytes integer.
@@ -657,7 +645,7 @@ pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
657645where
658646 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
659647{
660- map ! ( input , le_u64 , |x| x as i64 )
648+ le_u64 . map ( |x| x as i64 ) . parse ( input )
661649}
662650
663651/// Recognizes a little endian signed 16 bytes integer.
@@ -680,7 +668,7 @@ pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
680668where
681669 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
682670{
683- map ! ( input , le_u128 , |x| x as i128 )
671+ le_u128 . map ( |x| x as i128 ) . parse ( input )
684672}
685673
686674/// Recognizes an unsigned 1 byte integer
@@ -931,7 +919,7 @@ pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E>
931919where
932920 I : Slice < RangeFrom < usize > > + InputIter < Item = u8 > + InputLength ,
933921{
934- map ! ( i , u8 , |x| x as i8 )
922+ u8 . map ( |x| x as i8 ) . parse ( i )
935923}
936924
937925/// Recognizes a signed 2 byte integer
0 commit comments