aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-07-27 09:52:15 +0000
committerCorey Farwell <coreyf@rwell.org>2017-07-29 09:58:09 +0000
commitbefe5384725bdc20f16b2eff76009c67d01b6bac (patch)
tree99734a8e15142133e54eec5a8f1eefbd2f9039a7
parent6238035612a45ae3757739f6a0c17b7b6feda8ec (diff)
downloadservo-befe5384725bdc20f16b2eff76009c67d01b6bac.tar.gz
servo-befe5384725bdc20f16b2eff76009c67d01b6bac.zip
Utilize match_ignore_ascii_case! in more places.
-rw-r--r--components/script/dom/document.rs20
-rw-r--r--components/script/dom/htmlareaelement.rs15
-rw-r--r--components/script/dom/request.rs20
-rw-r--r--components/selectors/parser.rs8
-rw-r--r--components/style/media_queries.rs24
5 files changed, 40 insertions, 47 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index f9475b7cac0..6cbfebdd61f 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -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,
}
}
diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs
index c7d83ebd702..4e227491d01 100644
--- a/components/script/dom/htmlareaelement.rs
+++ b/components/script/dom/htmlareaelement.rs
@@ -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()) {
diff --git a/components/script/dom/request.rs b/components/script/dom/request.rs
index 82b7773fc3e..9abfb4b0eb4 100644
--- a/components/script/dom/request.rs
+++ b/components/script/dom/request.rs
@@ -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
diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs
index 490399ce38c..e9b59f7f831 100644
--- a/components/selectors/parser.rs
+++ b/components/selectors/parser.rs
@@ -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.
diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs
index 5f71ddf974f..b6bde057b3c 100644
--- a/components/style/media_queries.rs
+++ b/components/style/media_queries.rs
@@ -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),