mirror of
https://gitee.com/openharmony/third_party_rust_nom
synced 2024-11-30 11:10:43 +00:00
Merge pull request #362 from Keruspe/drop-chain-4
Port benches to do_parse
This commit is contained in:
commit
c7d76f98f9
@ -65,53 +65,53 @@ fn is_version(c: u8) -> bool {
|
||||
named!(line_ending, alt!(tag!("\r\n") | tag!("\n")));
|
||||
|
||||
fn request_line<'a>(input: &'a [u8]) -> IResult<&'a[u8], Request<'a>> {
|
||||
chain!(input,
|
||||
method: take_while1!(is_token) ~
|
||||
take_while1!(is_space) ~
|
||||
url: take_while1!(is_not_space) ~
|
||||
take_while1!(is_space) ~
|
||||
version: http_version ~
|
||||
line_ending,
|
||||
do_parse!(input,
|
||||
method: take_while1!(is_token) >>
|
||||
take_while1!(is_space) >>
|
||||
url: take_while1!(is_not_space) >>
|
||||
take_while1!(is_space) >>
|
||||
version: http_version >>
|
||||
line_ending >>
|
||||
|
||||
|| Request {
|
||||
(Request {
|
||||
method: method,
|
||||
uri: url,
|
||||
version: version,
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
named!(http_version, chain!(
|
||||
tag!("HTTP/") ~
|
||||
version: take_while1!(is_version),
|
||||
|
||||
|| version));
|
||||
named!(http_version, do_parse!(
|
||||
tag!("HTTP/") >>
|
||||
version: take_while1!(is_version) >>
|
||||
|
||||
named!(message_header_value, chain!(
|
||||
take_while1!(is_horizontal_space) ~
|
||||
data: take_while1!(not_line_ending) ~
|
||||
line_ending,
|
||||
|
||||
|| data));
|
||||
(version)));
|
||||
|
||||
named!(message_header_value, do_parse!(
|
||||
take_while1!(is_horizontal_space) >>
|
||||
data: take_while1!(not_line_ending) >>
|
||||
line_ending >>
|
||||
|
||||
(data)));
|
||||
|
||||
fn message_header<'a>(input: &'a [u8]) -> IResult<&'a[u8], Header<'a>> {
|
||||
chain!(input,
|
||||
name: take_while1!(is_token) ~
|
||||
char!(':') ~
|
||||
values: many1!(message_header_value),
|
||||
do_parse!(input,
|
||||
name: take_while1!(is_token) >>
|
||||
char!(':') >>
|
||||
values: many1!(message_header_value) >>
|
||||
|
||||
|| Header {
|
||||
(Header {
|
||||
name: name,
|
||||
value: values,
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
fn request<'a>(input: &'a [u8]) -> IResult<&'a[u8], (Request<'a>, Vec<Header<'a>>)> {
|
||||
chain!(input,
|
||||
req: request_line ~
|
||||
h: many1!(message_header) ~
|
||||
line_ending,
|
||||
do_parse!(input,
|
||||
req: request_line >>
|
||||
h: many1!(message_header) >>
|
||||
line_ending >>
|
||||
|
||||
|| (req, h))
|
||||
(req, h))
|
||||
}
|
||||
|
||||
|
||||
@ -130,7 +130,7 @@ fn parse(data:&[u8]) -> Option<Vec<(Request, Vec<Header>)>> {
|
||||
break;
|
||||
}
|
||||
},
|
||||
IResult::Error(e) => return None/*panic!("{:?}", e)*/,
|
||||
IResult::Error(_) => return None/*panic!("{:?}", e)*/,
|
||||
IResult::Incomplete(_) => return None/*panic!("Incomplete!")*/,
|
||||
}
|
||||
}
|
||||
@ -183,7 +183,7 @@ fn main() {
|
||||
let _ = file.read_to_end(&mut contents).unwrap();
|
||||
}
|
||||
|
||||
let mut buf = &contents[..];
|
||||
let buf = &contents[..];
|
||||
loop { parse(buf); }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user