1
1
use crate :: {
2
2
borrowed:: { Error , Signature } ,
3
- BStr , ByteSlice , Sign , Time ,
3
+ ByteSlice , Sign , Time ,
4
4
} ;
5
+ use bstr:: { BStr , BString , ByteVec } ;
5
6
use btoi:: btoi;
6
7
use nom:: {
7
8
branch:: alt,
@@ -16,7 +17,7 @@ use nom::{
16
17
pub ( crate ) const NL : & [ u8 ] = b"\n " ;
17
18
pub ( crate ) const SPACE : & [ u8 ] = b" " ;
18
19
19
- pub ( crate ) fn header_field_multi_line < ' a > ( i : & ' a [ u8 ] , name : & ' static [ u8 ] ) -> IResult < & ' a [ u8 ] , & ' a [ u8 ] , Error > {
20
+ pub ( crate ) fn header_field_multi_line < ' a > ( i : & ' a [ u8 ] , name : & ' static [ u8 ] ) -> IResult < & ' a [ u8 ] , BString , Error > {
20
21
let ( i, o) = peek ( preceded (
21
22
terminated ( tag ( name) , tag ( SPACE ) ) ,
22
23
recognize ( tuple ( (
@@ -28,7 +29,17 @@ pub(crate) fn header_field_multi_line<'a>(i: &'a [u8], name: &'static [u8]) -> I
28
29
assert ! ( !o. is_empty( ) ) ;
29
30
let end = & o[ o. len ( ) - 1 ] as * const u8 as usize ;
30
31
let start_input = & i[ 0 ] as * const u8 as usize ;
31
- Ok ( ( & i[ end - start_input + 1 ..] , & o[ ..o. len ( ) - 1 ] ) )
32
+
33
+ let bytes = o[ ..o. len ( ) - 1 ] . as_bstr ( ) ;
34
+ let mut out = BString :: from ( Vec :: with_capacity ( bytes. len ( ) ) ) ;
35
+ let mut lines = bytes. lines ( ) ;
36
+ out. push_str ( lines. next ( ) . expect ( "first line" ) ) ;
37
+ drop ( lines. next ( ) ) ; // empty newline marker
38
+ for line in lines {
39
+ out. push ( b'\n' ) ;
40
+ out. push_str ( & line[ 1 ..] ) ; // cut leading space
41
+ }
42
+ Ok ( ( & i[ end - start_input + 1 ..] , out) )
32
43
}
33
44
34
45
pub ( crate ) fn header_field < ' a , T > (
0 commit comments