From f374e8f420594177b92724b170f6ca39f351c90b Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 14 Feb 2016 22:42:07 +0000 Subject: [PATCH] #9640 Refactor: Move util::str::is_token to script::dom::bindings::str --- components/script/dom/bindings/str.rs | 36 ++++++++++++++++++++++++++- components/script/dom/websocket.rs | 4 +-- components/util/str.rs | 34 ------------------------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 26c8568eadf..3f3c14bf854 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -10,7 +10,6 @@ use std::hash::{Hash, Hasher}; use std::ops; use std::str; use std::str::FromStr; -use util::str::is_token; /// Encapsulates the IDL `ByteString` type. #[derive(JSTraceable, Clone, Eq, PartialEq, HeapSizeOf)] @@ -142,3 +141,38 @@ impl ops::Deref for ByteString { /// A string that is constructed from a UCS-2 buffer by replacing invalid code /// points with the replacement character. pub struct USVString(pub String); + + +/// Returns whether `s` is a `token`, as defined by +/// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-17). +pub fn is_token(s: &[u8]) -> bool { + if s.is_empty() { + return false; // A token must be at least a single character + } + s.iter().all(|&x| { + // http://tools.ietf.org/html/rfc2616#section-2.2 + match x { + 0...31 | 127 => false, // CTLs + 40 | + 41 | + 60 | + 62 | + 64 | + 44 | + 59 | + 58 | + 92 | + 34 | + 47 | + 91 | + 93 | + 63 | + 61 | + 123 | + 125 | + 32 => false, // separators + x if x > 127 => false, // non-CHARs + _ => true, + } + }) +} diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 192c793906f..949f1c683a2 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -16,7 +16,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::refcounted::Trusted; use dom::bindings::reflector::{Reflectable, reflect_dom_object}; -use dom::bindings::str::USVString; +use dom::bindings::str::{USVString, is_token}; use dom::bindings::trace::JSTraceable; use dom::blob::Blob; use dom::closeevent::CloseEvent; @@ -41,7 +41,7 @@ use std::borrow::ToOwned; use std::cell::Cell; use std::ptr; use std::thread; -use util::str::{DOMString, is_token}; +use util::str::DOMString; use websocket::client::request::Url; use websocket::header::{Headers, WebSocketProtocol}; use websocket::ws::util::url::parse_url; diff --git a/components/util/str.rs b/components/util/str.rs index 8ffcf67b0e9..86f5d77cdc8 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -565,37 +565,3 @@ pub fn search_index(index: usize, indices: CharIndices) -> isize { } character_count } - -/// Returns whether `s` is a `token`, as defined by -/// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-17). -pub fn is_token(s: &[u8]) -> bool { - if s.is_empty() { - return false; // A token must be at least a single character - } - s.iter().all(|&x| { - // http://tools.ietf.org/html/rfc2616#section-2.2 - match x { - 0...31 | 127 => false, // CTLs - 40 | - 41 | - 60 | - 62 | - 64 | - 44 | - 59 | - 58 | - 92 | - 34 | - 47 | - 91 | - 93 | - 63 | - 61 | - 123 | - 125 | - 32 => false, // separators - x if x > 127 => false, // non-CHARs - _ => true, - } - }) -}