[librsvg: 5/17] parse_property(): Implement in terms of a parse_input() that uses cssparser
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/17] parse_property(): Implement in terms of a parse_input() that uses cssparser
- Date: Fri, 3 May 2019 01:29:03 +0000 (UTC)
commit c8e3980eab22ad845d1222c3b3daedaf3294b80b
Author: Federico Mena Quintero <federico gnome org>
Date: Thu May 2 16:59:42 2019 -0500
parse_property(): Implement in terms of a parse_input() that uses cssparser
rsvg_internals/src/properties.rs | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 7114b405..f974e52d 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -1,4 +1,4 @@
-use cssparser::{self, Parser, Token};
+use cssparser::{self, Parser, ParserInput, Token};
use std::collections::HashSet;
use std::str::FromStr;
@@ -656,17 +656,26 @@ impl SpecifiedValues {
}
// Parses the `value` for the type `T` of the property, including `inherit` values.
-//
-// If the `value` is `inherit`, returns `Ok(None)`; otherwise returns
-// `Ok(Some(T))`.
fn parse_property<T>(value: &str) -> Result<SpecifiedValue<T>, <T as Parse>::Err>
where
T: Property<ComputedValues> + Clone + Default + Parse,
{
- if value.trim() == "inherit" {
+ let mut input = ParserInput::new(value);
+ let mut parser = Parser::new(&mut input);
+
+ parse_input(&mut parser)
+}
+
+pub fn parse_input<T>(
+ input: &mut Parser,
+) -> Result<SpecifiedValue<T>, <T as Parse>::Err>
+where
+ T: Property<ComputedValues> + Clone + Default + Parse,
+{
+ if input.try_parse(|p| p.expect_ident_matching("inherit")).is_ok() {
Ok(SpecifiedValue::Inherit)
} else {
- Parse::parse_str(value).map(SpecifiedValue::Specified)
+ Parse::parse(input).map(SpecifiedValue::Specified)
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]