1- use crate :: util:: { is_token, trimmed, FlagOperations } ;
1+ use crate :: util:: { is_space , is_token, trimmed, FlagOperations } ;
22use nom:: {
33 branch:: alt,
44 bytes:: complete:: tag as complete_tag,
55 bytes:: streaming:: { tag, take_till, take_while, take_while1} ,
6- character:: { is_space , streaming:: space0} ,
6+ character:: streaming:: space0,
77 combinator:: { complete, map, not, opt, peek} ,
8- sequence:: tuple,
98 Err :: Incomplete ,
109 IResult , Needed ,
10+ Parser as NomParser ,
1111} ;
1212
1313/// Helper for Parsed bytes and corresponding HeaderFlags
@@ -133,9 +133,9 @@ impl Parser {
133133 complete_tag ( "\n \r " ) ,
134134 complete_tag ( "\n " ) ,
135135 complete_tag ( "\r " ) ,
136- ) ) ( input)
136+ ) ) . parse ( input)
137137 } else {
138- alt ( ( complete_tag ( "\r \n " ) , complete_tag ( "\n " ) ) ) ( input)
138+ alt ( ( complete_tag ( "\r \n " ) , complete_tag ( "\n " ) ) ) . parse ( input)
139139 }
140140 }
141141 }
@@ -146,38 +146,38 @@ impl Parser {
146146 if self . side == Side :: Response {
147147 alt ( (
148148 map (
149- tuple ( (
149+ (
150150 complete_tag ( "\n \r \r \n " ) ,
151151 peek ( alt ( ( complete_tag ( "\n " ) , complete_tag ( "\r \n " ) ) ) ) ,
152- ) ) ,
152+ ) ,
153153 |( eol, _) | ( eol, HeaderFlags :: DEFORMED_EOL ) ,
154154 ) ,
155155 map (
156- tuple ( (
156+ (
157157 complete_tag ( "\r \n \r " ) ,
158158 take_while1 ( |c| c == b'\r' || c == b' ' || c == b'\t' ) ,
159159 opt ( complete_tag ( "\n " ) ) ,
160160 not ( alt ( ( complete_tag ( "\n " ) , complete_tag ( "\r \n " ) ) ) ) ,
161- ) ) ,
161+ ) ,
162162 |( eol1, eol2, eol3, _) : ( & [ u8 ] , & [ u8 ] , Option < & [ u8 ] > , _ ) | {
163163 (
164164 & input[ ..( eol1. len ( ) + eol2. len ( ) + eol3. unwrap_or ( b"" ) . len ( ) ) ] ,
165165 HeaderFlags :: DEFORMED_EOL ,
166166 )
167167 } ,
168168 ) ,
169- ) ) ( input)
169+ ) ) . parse ( input)
170170 } else {
171171 map (
172172 alt ( (
173- tuple ( (
173+ (
174174 complete_tag ( "\n \r \r \n " ) ,
175175 peek ( alt ( ( complete_tag ( "\n " ) , complete_tag ( "\r \n " ) ) ) ) ,
176- ) ) ,
177- tuple ( ( complete_tag ( "\n \r " ) , peek ( complete_tag ( "\r \n " ) ) ) ) ,
176+ ) ,
177+ ( complete_tag ( "\n \r " ) , peek ( complete_tag ( "\r \n " ) ) ) ,
178178 ) ) ,
179179 |( eol, _) | ( eol, HeaderFlags :: DEFORMED_EOL ) ,
180- ) ( input)
180+ ) . parse ( input)
181181 }
182182 }
183183 }
@@ -188,46 +188,46 @@ impl Parser {
188188 alt ( (
189189 self . complete_eol_deformed ( ) ,
190190 map ( self . complete_eol_regular ( ) , |eol| ( eol, 0 ) ) ,
191- ) ) ( input)
191+ ) ) . parse ( input)
192192 }
193193 }
194194
195195 /// Parse one header end of line, and guarantee that it is not folding
196196 fn eol ( & self ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , ParsedBytes > + ' _ {
197197 move |input| {
198198 map (
199- tuple ( ( self . complete_eol ( ) , not ( folding_lws) ) ) ,
199+ ( self . complete_eol ( ) , not ( folding_lws) ) ,
200200 |( end, _) | end,
201- ) ( input)
201+ ) . parse ( input)
202202 }
203203 }
204204
205205 /// Parse one null byte or one end of line, and guarantee that it is not folding
206206 fn null_or_eol ( & self ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , ParsedBytes > + ' _ {
207- move |input| alt ( ( null, self . eol ( ) ) ) ( input)
207+ move |input| alt ( ( null, self . eol ( ) ) ) . parse ( input)
208208 }
209209
210210 /// Parse one null byte or complete end of line
211211 fn complete_null_or_eol ( & self ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , ParsedBytes > + ' _ {
212- move |input| alt ( ( null, self . complete_eol ( ) ) ) ( input)
212+ move |input| alt ( ( null, self . complete_eol ( ) ) ) . parse ( input)
213213 }
214214
215215 /// Parse header folding bytes (eol + whitespace or eol + special cases)
216216 fn folding ( & self ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , FoldingBytes > + ' _ {
217217 move |input| {
218218 if self . side == Side :: Response {
219219 map (
220- tuple ( (
220+ (
221221 map ( self . complete_eol_regular ( ) , |eol| ( eol, 0 ) ) ,
222222 folding_lws,
223- ) ) ,
223+ ) ,
224224 |( ( eol, flags) , ( lws, other_flags) ) | ( eol, lws, flags | other_flags) ,
225- ) ( input)
225+ ) . parse ( input)
226226 } else {
227227 map (
228- tuple ( ( self . complete_eol ( ) , folding_lws) ) ,
228+ ( self . complete_eol ( ) , folding_lws) ,
229229 |( ( eol, flags) , ( lws, other_flags) ) | ( eol, lws, flags | other_flags) ,
230- ) ( input)
230+ ) . parse ( input)
231231 }
232232 }
233233 }
@@ -242,7 +242,7 @@ impl Parser {
242242 ( ( end, flags) , Some ( fold) )
243243 } ) ) ,
244244 map ( self . complete_null_or_eol ( ) , |end| ( end, None ) ) ,
245- ) ) ( input)
245+ ) ) . parse ( input)
246246 }
247247 }
248248
@@ -256,7 +256,7 @@ impl Parser {
256256 ( ( end, flags) , Some ( fold) )
257257 } ) ,
258258 map ( self . null_or_eol ( ) , |end| ( end, None ) ) ,
259- ) ) ( input)
259+ ) ) . parse ( input)
260260 }
261261 }
262262
@@ -297,7 +297,7 @@ impl Parser {
297297 loop {
298298 if self . side == Side :: Response {
299299 // Peek ahead for ambiguous name with lws vs. value with folding
300- match tuple ( ( token_chars, separator_regular) ) ( i) {
300+ match ( token_chars, separator_regular) . parse ( i) {
301301 Ok ( ( _, ( ( _, tokens, _) , ( _, _) ) ) ) if !tokens. is_empty ( ) => {
302302 flags. unset ( HeaderFlags :: FOLDING_SPECIAL_CASE ) ;
303303 if value. is_empty ( ) {
@@ -397,13 +397,13 @@ impl Parser {
397397
398398 /// Parse a separator between header name and value
399399 fn separator ( & self ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , u64 > + ' _ {
400- move |input| map ( separator_regular, |_| 0 ) ( input)
400+ move |input| map ( separator_regular, |_| 0 ) . parse ( input)
401401 }
402402
403403 /// Parse data before an eol with no colon as an empty name with the data as the value
404404 fn header_sans_colon ( & self ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , Header > + ' _ {
405405 move |input| {
406- let ( remaining, ( _, value) ) = tuple ( ( not ( complete_tag ( "\r \n " ) ) , self . value ( ) ) ) ( input) ?;
406+ let ( remaining, ( _, value) ) = ( not ( complete_tag ( "\r \n " ) ) , self . value ( ) ) . parse ( input) ?;
407407
408408 let flags = value. flags | HeaderFlags :: MISSING_COLON ;
409409 Ok ( (
@@ -417,19 +417,19 @@ impl Parser {
417417 fn header_with_colon ( & self ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , Header > + ' _ {
418418 move |input| {
419419 map (
420- tuple ( ( self . name ( ) , self . separator ( ) , self . value ( ) ) ) ,
420+ ( self . name ( ) , self . separator ( ) , self . value ( ) ) ,
421421 |( mut name, flag, mut value) | {
422422 name. flags |= flag;
423423 value. flags |= flag;
424424 Header :: new ( name, value)
425425 } ,
426- ) ( input)
426+ ) . parse ( input)
427427 }
428428 }
429429
430430 /// Parses a header name and value with, or without a colon separator
431431 fn header ( & self ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , Header > + ' _ {
432- move |input| alt ( ( complete ( self . header_with_colon ( ) ) , self . header_sans_colon ( ) ) ) ( input)
432+ move |input| alt ( ( complete ( self . header_with_colon ( ) ) , self . header_sans_colon ( ) ) ) . parse ( input)
433433 }
434434
435435 /// Parse multiple headers and indicate if end of headers or null was found
@@ -475,25 +475,25 @@ impl Parser {
475475fn null ( input : & [ u8 ] ) -> IResult < & [ u8 ] , ParsedBytes < ' _ > > {
476476 map ( complete_tag ( "\0 " ) , |null| {
477477 ( null, HeaderFlags :: NULL_TERMINATED )
478- } ) ( input)
478+ } ) . parse ( input)
479479}
480480
481481/// Extracts folding lws (whitespace only)
482482fn folding_lws ( input : & [ u8 ] ) -> IResult < & [ u8 ] , ParsedBytes < ' _ > > {
483483 map ( alt ( ( tag ( " " ) , tag ( "\t " ) , tag ( "\0 " ) ) ) , |fold| {
484484 ( fold, HeaderFlags :: FOLDING )
485- } ) ( input)
485+ } ) . parse ( input)
486486}
487487
488488/// Parse a regular separator (colon followed by optional spaces) between header name and value
489489fn separator_regular ( input : & [ u8 ] ) -> IResult < & [ u8 ] , ( & [ u8 ] , & [ u8 ] ) > {
490- tuple ( ( complete_tag ( ":" ) , space0) ) ( input)
490+ ( complete_tag ( ":" ) , space0) . parse ( input)
491491}
492492
493493type leading_token_trailing < ' a > = ( & ' a [ u8 ] , & ' a [ u8 ] , & ' a [ u8 ] ) ;
494494/// Parse token characters with leading and trailing whitespace
495495fn token_chars ( input : & [ u8 ] ) -> IResult < & [ u8 ] , leading_token_trailing < ' _ > > {
496- tuple ( ( space0, take_while ( is_token) , space0) ) ( input)
496+ ( space0, take_while ( is_token) , space0) . parse ( input)
497497}
498498
499499#[ cfg( test) ]
0 commit comments