mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Remove extra definition of WHITESPACE under components/util/str.rs
This commit is contained in:
parent
bebc1dc859
commit
95bebb9945
3 changed files with 14 additions and 18 deletions
|
@ -15,7 +15,7 @@ use dom::node::Node;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
use style::values::specified;
|
use style::values::specified;
|
||||||
use util::str::{DOMString, WHITESPACE, read_numbers};
|
use util::str::{DOMString, HTML_SPACE_CHARACTERS, read_numbers};
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct HTMLFontElement {
|
pub struct HTMLFontElement {
|
||||||
|
@ -124,7 +124,7 @@ pub fn parse_legacy_font_size(mut input: &str) -> Option<&'static str> {
|
||||||
// Steps 1 & 2 are not relevant
|
// Steps 1 & 2 are not relevant
|
||||||
|
|
||||||
// Step 3
|
// Step 3
|
||||||
input = input.trim_matches(WHITESPACE);
|
input = input.trim_matches(HTML_SPACE_CHARACTERS);
|
||||||
|
|
||||||
enum ParseMode {
|
enum ParseMode {
|
||||||
RelativePlus,
|
RelativePlus,
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::ops::Deref;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use string_cache::{Atom, Namespace};
|
use string_cache::{Atom, Namespace};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::str::{DOMString, LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS, WHITESPACE};
|
use util::str::{DOMString, LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS};
|
||||||
use util::str::{read_numbers, split_html_space_chars, str_join};
|
use util::str::{read_numbers, split_html_space_chars, str_join};
|
||||||
use values::specified::{Length};
|
use values::specified::{Length};
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
input = input.trim_matches(WHITESPACE);
|
input = input.trim_matches(HTML_SPACE_CHARACTERS);
|
||||||
|
|
||||||
// Step 4.
|
// Step 4.
|
||||||
if input.eq_ignore_ascii_case("transparent") {
|
if input.eq_ignore_ascii_case("transparent") {
|
||||||
|
@ -407,7 +407,7 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
|
||||||
// Steps 1 & 2 are not relevant
|
// Steps 1 & 2 are not relevant
|
||||||
|
|
||||||
// Step 3
|
// Step 3
|
||||||
value = value.trim_left_matches(WHITESPACE);
|
value = value.trim_left_matches(HTML_SPACE_CHARACTERS);
|
||||||
|
|
||||||
// Step 4
|
// Step 4
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
|
|
|
@ -124,19 +124,6 @@ impl Extend<char> for DOMString {
|
||||||
pub type StaticCharVec = &'static [char];
|
pub type StaticCharVec = &'static [char];
|
||||||
pub type StaticStringVec = &'static [&'static str];
|
pub type StaticStringVec = &'static [&'static str];
|
||||||
|
|
||||||
/// Whitespace as defined by HTML5 § 2.4.1.
|
|
||||||
// TODO(SimonSapin) Maybe a custom Pattern can be more efficient?
|
|
||||||
pub const WHITESPACE: &'static [char] = &[' ', '\t', '\x0a', '\x0c', '\x0d'];
|
|
||||||
|
|
||||||
pub fn is_whitespace(s: &str) -> bool {
|
|
||||||
s.chars().all(char_is_whitespace)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn char_is_whitespace(c: char) -> bool {
|
|
||||||
WHITESPACE.contains(&c)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A "space character" according to:
|
/// A "space character" according to:
|
||||||
///
|
///
|
||||||
/// https://html.spec.whatwg.org/multipage/#space-character
|
/// https://html.spec.whatwg.org/multipage/#space-character
|
||||||
|
@ -148,6 +135,15 @@ pub static HTML_SPACE_CHARACTERS: StaticCharVec = &[
|
||||||
'\u{000d}',
|
'\u{000d}',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn char_is_whitespace(c: char) -> bool {
|
||||||
|
HTML_SPACE_CHARACTERS.contains(&c)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_whitespace(s: &str) -> bool {
|
||||||
|
s.chars().all(char_is_whitespace)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn split_html_space_chars<'a>(s: &'a str) ->
|
pub fn split_html_space_chars<'a>(s: &'a str) ->
|
||||||
Filter<Split<'a, StaticCharVec>, fn(&&str) -> bool> {
|
Filter<Split<'a, StaticCharVec>, fn(&&str) -> bool> {
|
||||||
fn not_empty(&split: &&str) -> bool { !split.is_empty() }
|
fn not_empty(&split: &&str) -> bool { !split.is_empty() }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue