Use Result/Err(()) instead of Option/None to indicate a CSS parse error.

This commit is contained in:
Simon Sapin 2014-08-11 20:06:17 +01:00
parent 061e7e1620
commit d9278e3f6a
6 changed files with 223 additions and 212 deletions

View file

@ -7,15 +7,18 @@ use std::ascii::StrAsciiExt;
use cssparser::ast::{ComponentValue, Ident, SkipWhitespaceIterable};
pub fn one_component_value<'a>(input: &'a [ComponentValue]) -> Option<&'a ComponentValue> {
pub fn one_component_value<'a>(input: &'a [ComponentValue]) -> Result<&'a ComponentValue, ()> {
let mut iter = input.skip_whitespace();
iter.next().filtered(|_| iter.next().is_none())
}
pub fn get_ident_lower(component_value: &ComponentValue) -> Option<String> {
match component_value {
&Ident(ref value) => Some(value.as_slice().to_ascii_lower()),
_ => None,
match iter.next() {
Some(value) => if iter.next().is_none() { Ok(value) } else { Err(()) },
None => Err(())
}
}
pub fn get_ident_lower(component_value: &ComponentValue) -> Result<String, ()> {
match component_value {
&Ident(ref value) => Ok(value.as_slice().to_ascii_lower()),
_ => Err(()),
}
}