mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
#9640 Refactor: Move util::str::is_token to script::dom::bindings::str
This commit is contained in:
parent
c929dbe253
commit
f374e8f420
3 changed files with 37 additions and 37 deletions
|
@ -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,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue