Skip to content

Commit

Permalink
#9640 Refactor: Move util::str::is_token to script::dom::bindings::str
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Feb 14, 2016
1 parent c929dbe commit f374e8f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
36 changes: 35 additions & 1 deletion components/script/dom/bindings/str.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
}
})
}
4 changes: 2 additions & 2 deletions components/script/dom/websocket.rs
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
34 changes: 0 additions & 34 deletions components/util/str.rs
Expand Up @@ -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,
}
})
}

0 comments on commit f374e8f

Please sign in to comment.