Skip to content

Commit

Permalink
fix: use char for single char strings
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Oct 3, 2023
1 parent 9fd78b6 commit 025c775
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use nom::{
branch::alt,
bytes::complete::{tag, take_while},
character::{complete::alphanumeric0, is_alphanumeric},
character::{
complete::{alphanumeric0, char},
is_alphanumeric,
},
combinator::{map, opt},
multi::{many0, separated_list0},
sequence::{preceded, separated_pair},
Expand All @@ -26,16 +29,16 @@ fn parse_surf(input: &str) -> IResult<&str, Surf<'_>> {
let (input, _) = opt(protocol_parser)(input)?;
let (input, host) = take_while(is_letter_or_dot)(input)?;

let path_parser = many0(preceded(tag("/"), alphanumeric0));
let path_parser = many0(preceded(char('/'), alphanumeric0));
let (input, path) = map(opt(path_parser), Option::unwrap_or_default)(input)?;

let key_value = separated_pair(alphanumeric0, tag("="), alphanumeric0);
let key_value_list = separated_list0(tag("&"), key_value);
let query_parser = preceded(tag("?"), key_value_list);
let key_value = separated_pair(alphanumeric0, char('='), alphanumeric0);
let key_value_list = separated_list0(char('&'), key_value);
let query_parser = preceded(char('?'), key_value_list);
let query_hash = map(query_parser, |q| q.into_iter().collect());
let (input, query) = map(opt(query_hash), Option::unwrap_or_default)(input)?;

let fragment_parser = preceded(tag("#"), alphanumeric0);
let fragment_parser = preceded(char('#'), alphanumeric0);
let (input, fragment) = opt(fragment_parser)(input)?;

Ok((
Expand Down

0 comments on commit 025c775

Please sign in to comment.