mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
Utilize match_ignore_ascii_case! in more places.
This commit is contained in:
parent
6238035612
commit
befe538472
5 changed files with 39 additions and 46 deletions
|
@ -3875,16 +3875,16 @@ fn update_with_current_time_ms(marker: &Cell<u64>) {
|
|||
|
||||
/// https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token
|
||||
pub fn determine_policy_for_token(token: &str) -> Option<ReferrerPolicy> {
|
||||
match token {
|
||||
t if t.eq_ignore_ascii_case("never") | t.eq_ignore_ascii_case("no-referrer") => Some(ReferrerPolicy::NoReferrer),
|
||||
t if t.eq_ignore_ascii_case("default") | t.eq_ignore_ascii_case("no-referrer-when-downgrade") => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
|
||||
t if t.eq_ignore_ascii_case("origin") => Some(ReferrerPolicy::Origin),
|
||||
t if t.eq_ignore_ascii_case("same-origin") => Some(ReferrerPolicy::SameOrigin),
|
||||
t if t.eq_ignore_ascii_case("strict-origin") => Some(ReferrerPolicy::StrictOrigin),
|
||||
t if t.eq_ignore_ascii_case("strict-origin-when-cross-origin") => Some(ReferrerPolicy::StrictOriginWhenCrossOrigin),
|
||||
t if t.eq_ignore_ascii_case("origin-when-cross-origin") => Some(ReferrerPolicy::OriginWhenCrossOrigin),
|
||||
t if t.eq_ignore_ascii_case("always") | t.eq_ignore_ascii_case("unsafe-url") => Some(ReferrerPolicy::UnsafeUrl),
|
||||
t if t.eq_ignore_ascii_case("") => Some(ReferrerPolicy::NoReferrer),
|
||||
match_ignore_ascii_case! { token,
|
||||
"never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer),
|
||||
"default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoReferrerWhenDowngrade),
|
||||
"origin" => Some(ReferrerPolicy::Origin),
|
||||
"same-origin" => Some(ReferrerPolicy::SameOrigin),
|
||||
"strict-origin" => Some(ReferrerPolicy::StrictOrigin),
|
||||
"strict-origin-when-cross-origin" => Some(ReferrerPolicy::StrictOriginWhenCrossOrigin),
|
||||
"origin-when-cross-origin" => Some(ReferrerPolicy::OriginWhenCrossOrigin),
|
||||
"always" | "unsafe-url" => Some(ReferrerPolicy::UnsafeUrl),
|
||||
"" => Some(ReferrerPolicy::NoReferrer),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::activation::Activatable;
|
||||
use std::ascii::AsciiExt;
|
||||
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
|
||||
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods;
|
||||
|
@ -241,13 +240,13 @@ impl HTMLAreaElement {
|
|||
pub fn get_shape_from_coords(&self) -> Option<Area> {
|
||||
let elem = self.upcast::<Element>();
|
||||
let shape = elem.get_string_attribute(&"shape".into());
|
||||
let shp: Shape = match &shape {
|
||||
s if s.eq_ignore_ascii_case("circle") => Shape::Circle,
|
||||
s if s.eq_ignore_ascii_case("circ") => Shape::Circle,
|
||||
s if s.eq_ignore_ascii_case("rectangle") => Shape::Rectangle,
|
||||
s if s.eq_ignore_ascii_case("rect") => Shape::Rectangle,
|
||||
s if s.eq_ignore_ascii_case("polygon") => Shape::Rectangle,
|
||||
s if s.eq_ignore_ascii_case("poly") => Shape::Polygon,
|
||||
let shp: Shape = match_ignore_ascii_case! { &shape,
|
||||
"circle" => Shape::Circle,
|
||||
"circ" => Shape::Circle,
|
||||
"rectangle" => Shape::Rectangle,
|
||||
"rect" => Shape::Rectangle,
|
||||
"polygon" => Shape::Rectangle,
|
||||
"poly" => Shape::Polygon,
|
||||
_ => return None,
|
||||
};
|
||||
if elem.has_attribute(&"coords".into()) {
|
||||
|
|
|
@ -38,7 +38,6 @@ use net_traits::request::Request as NetTraitsRequest;
|
|||
use net_traits::request::RequestMode as NetTraitsRequestMode;
|
||||
use net_traits::request::Type as NetTraitsRequestType;
|
||||
use servo_url::ServoUrl;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::cell::{Cell, Ref};
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -453,15 +452,16 @@ fn net_request_from_global(global: &GlobalScope,
|
|||
|
||||
// https://fetch.spec.whatwg.org/#concept-method-normalize
|
||||
fn normalize_method(m: &str) -> HttpMethod {
|
||||
match m {
|
||||
m if m.eq_ignore_ascii_case("DELETE") => HttpMethod::Delete,
|
||||
m if m.eq_ignore_ascii_case("GET") => HttpMethod::Get,
|
||||
m if m.eq_ignore_ascii_case("HEAD") => HttpMethod::Head,
|
||||
m if m.eq_ignore_ascii_case("OPTIONS") => HttpMethod::Options,
|
||||
m if m.eq_ignore_ascii_case("POST") => HttpMethod::Post,
|
||||
m if m.eq_ignore_ascii_case("PUT") => HttpMethod::Put,
|
||||
m => HttpMethod::Extension(m.to_string()),
|
||||
match_ignore_ascii_case! { m,
|
||||
"delete" => return HttpMethod::Delete,
|
||||
"get" => return HttpMethod::Get,
|
||||
"head" => return HttpMethod::Head,
|
||||
"options" => return HttpMethod::Options,
|
||||
"post" => return HttpMethod::Post,
|
||||
"put" => return HttpMethod::Put,
|
||||
_ => (),
|
||||
}
|
||||
HttpMethod::Extension(m.to_string())
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-method
|
||||
|
|
|
@ -1586,10 +1586,10 @@ where Impl: SelectorImpl, F: FnOnce(i32, i32) -> Component<Impl> {
|
|||
/// double-colon syntax, which can be used for all pseudo-elements).
|
||||
pub fn is_css2_pseudo_element<'i>(name: &CowRcStr<'i>) -> bool {
|
||||
// ** Do not add to this list! **
|
||||
return name.eq_ignore_ascii_case("before") ||
|
||||
name.eq_ignore_ascii_case("after") ||
|
||||
name.eq_ignore_ascii_case("first-line") ||
|
||||
name.eq_ignore_ascii_case("first-letter");
|
||||
match_ignore_ascii_case! { name,
|
||||
"before" | "after" | "first-line" | "first-letter" => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a simple selector other than a type selector.
|
||||
|
|
|
@ -12,7 +12,6 @@ use cssparser::{Delimiter, Parser, Token, ParserInput};
|
|||
use parser::ParserContext;
|
||||
use selectors::parser::SelectorParseError;
|
||||
use serialize_comma_separated_list;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::fmt;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
|
||||
|
@ -146,20 +145,15 @@ pub enum MediaQueryType {
|
|||
|
||||
impl MediaQueryType {
|
||||
fn parse(ident: &str) -> Result<Self, ()> {
|
||||
if ident.eq_ignore_ascii_case("all") {
|
||||
return Ok(MediaQueryType::All);
|
||||
}
|
||||
|
||||
// From https://drafts.csswg.org/mediaqueries/#mq-syntax:
|
||||
//
|
||||
// The <media-type> production does not include the keywords only,
|
||||
// not, and, and or.
|
||||
if ident.eq_ignore_ascii_case("not") ||
|
||||
ident.eq_ignore_ascii_case("or") ||
|
||||
ident.eq_ignore_ascii_case("and") ||
|
||||
ident.eq_ignore_ascii_case("only") {
|
||||
return Err(())
|
||||
}
|
||||
match_ignore_ascii_case! { ident,
|
||||
"all" => return Ok(MediaQueryType::All),
|
||||
// From https://drafts.csswg.org/mediaqueries/#mq-syntax:
|
||||
//
|
||||
// The <media-type> production does not include the keywords only,
|
||||
// not, and, and or.
|
||||
"not" | "or" | "and" | "only" => return Err(()),
|
||||
_ => (),
|
||||
};
|
||||
|
||||
Ok(match MediaType::parse(ident) {
|
||||
Some(media_type) => MediaQueryType::Known(media_type),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue