-
Notifications
You must be signed in to change notification settings - Fork 347
Changes needed for gecko-integration #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
use std::ops::{Range, RangeFrom, RangeTo, RangeFull, Index}; | ||
use Url; | ||
use std::mem; | ||
|
||
impl Index<RangeFull> for Url { | ||
type Output = str; | ||
|
@@ -77,6 +78,7 @@ impl Index<Range<Position>> for Url { | |
/// `BeforeScheme` and `AfterFragment` are always the start and end of the entire URL, | ||
/// so `&url[BeforeScheme..X]` is the same as `&url[..X]` | ||
/// and `&url[X..AfterFragment]` is the same as `&url[X..]`. | ||
#[repr(u32)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
#[derive(Copy, Clone, Debug)] | ||
pub enum Position { | ||
BeforeScheme, | ||
|
@@ -97,6 +99,14 @@ pub enum Position { | |
AfterFragment | ||
} | ||
|
||
impl From<u32> for Position { | ||
fn from(f: u32) -> Self { | ||
unsafe { | ||
mem::transmute(f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this macro_rules! c_like_enum {
( $type_name: ident: $( $variant: ident, )+ ) => {
c_like_enum! {
$type_name
[ $($variant)* ]
[ ]
next = 0
}
};
(
$type_name: ident
[ $next_variant: ident $( $variant: ident )* ]
[ $($assigned_variant: ident = $value: expr),* ]
next = $next_value: expr
) => {
c_like_enum! {
$type_name
[ $($variant)* ]
[ $($assigned_variant = $value,)* $next_variant = $next_value ]
next = $next_value + 1
}
};
(
$type_name: ident
[ ]
[ $($variant: ident = $value: expr),+ ]
next = $next_value: expr
) => {
#[derive(Copy, Clone, Debug)]
#[repr(u8)]
pub enum $type_name {
$($variant = $value,)+
}
impl $type_name {
#[allow(non_upper_case_globals)]
pub fn from_u8(value: u8) -> Option<Self> {
$(
const $variant: u8 = $value;
)+
match value {
$(
$variant => Some($type_name::$variant),
)+
_ => None
}
}
}
};
}
c_like_enum! { Position:
BeforeScheme,
AfterScheme,
BeforeUsername,
AfterUsername,
BeforePassword,
AfterPassword,
BeforeHost,
AfterHost,
BeforePort,
AfterPort,
BeforePath,
AfterPath,
BeforeQuery,
AfterQuery,
BeforeFragment,
AfterFragment,
} |
||
} | ||
} | ||
} | ||
|
||
impl Url { | ||
#[inline] | ||
fn index(&self, position: Position) -> usize { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Encode sets are normally used for percent encoding, not decoding. So I’d rather not expose this in the public API. In
after_percent_sign
you could "inline"!HOSTNAME_ENCODE_SET.contains(c)
to!(matches(c, ' ' | '!' | '"' | /* ...*/ '~') || c < '\u{20}' || c > '\u{7E}')
, or invert the logic and usematches!(c, 'a'...'z' | 'A'...'Z' | '0'...'9' | '.' | '-' | '_' | '*')
. (I think that’s the complementary set, but I’m not sure*
should be there.)