Skip to content

Commit

Permalink
Use define_encode_set
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Nov 6, 2018
1 parent 20bebc2 commit 827cc63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ assert_eq!(css_url.as_str(), "http://servo.github.io/rust-url/main.css");
#[cfg(feature="heapsize")] #[macro_use] extern crate heapsize;

pub extern crate idna;
#[macro_use]
pub extern crate percent_encoding;

use encoding::EncodingOverride;
Expand Down
19 changes: 5 additions & 14 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,13 @@ use host::{Host, HostInternal};
use percent_encoding::{
utf8_percent_encode, percent_encode,
SIMPLE_ENCODE_SET, DEFAULT_ENCODE_SET, USERINFO_ENCODE_SET, QUERY_ENCODE_SET,
PATH_SEGMENT_ENCODE_SET, EncodeSet
PATH_SEGMENT_ENCODE_SET
};

// The backslash (\) character is treated as a path separator in special URLs
// so it needs to be additionally escaped in that case.
#[derive(Clone)]
struct SPECIAL_PATH_SEGMENT_ENCODE_SET;

impl EncodeSet for SPECIAL_PATH_SEGMENT_ENCODE_SET {
#[inline]
fn contains(&self, byte: u8) -> bool {
match byte {
b'\\' => true,
_ => PATH_SEGMENT_ENCODE_SET.contains(byte)
}
}
define_encode_set! {
// The backslash (\) character is treated as a path separator in special URLs
// so it needs to be additionally escaped in that case.
pub SPECIAL_PATH_SEGMENT_ENCODE_SET = [PATH_SEGMENT_ENCODE_SET] | {'\\'}
}

pub type ParseResult<T> = Result<T, ParseError>;
Expand Down

0 comments on commit 827cc63

Please sign in to comment.