[librsvg: 6/8] Move all the cssparser-related impls to css.rs
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 6/8] Move all the cssparser-related impls to css.rs
- Date: Fri, 3 May 2019 19:25:52 +0000 (UTC)
commit bd4cb2b85e5289b50bd619ef36db6abf59e80a49
Author: Federico Mena Quintero <federico gnome org>
Date: Fri May 3 14:05:43 2019 -0500
Move all the cssparser-related impls to css.rs
rsvg_internals/src/css.rs | 50 +++++++++++++++++++++++++++++++++++++---
rsvg_internals/src/properties.rs | 49 ++-------------------------------------
2 files changed, 49 insertions(+), 50 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index 2a12cb2d..68d9c1a8 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -1,4 +1,6 @@
-use cssparser::{Parser, ParserInput};
+use cssparser::{
+ self, parse_important, AtRuleParser, CowRcStr, DeclarationParser, Parser, ParserInput,
+};
use std::collections::hash_map::{Entry, Iter as HashMapIter};
use std::collections::HashMap;
use std::ptr;
@@ -13,16 +15,58 @@ use glib_sys::{gboolean, gpointer, GList};
use crate::allowed_url::AllowedUrl;
use crate::attributes::Attribute;
use crate::croco::*;
-use crate::error::LoadingError;
+use crate::error::*;
use crate::io::{self, BinaryData};
-use crate::properties::{parse_attribute_value_into_parsed_property, Declaration};
+use crate::properties::{parse_attribute_value_into_parsed_property, ParsedProperty};
use crate::util::utf8_cstr;
+/// A parsed CSS declaration (`name: value [!important]`)
+pub struct Declaration {
+ pub attribute: Attribute,
+ pub property: ParsedProperty,
+ pub important: bool,
+}
+
pub struct DeclarationList {
// Maps property_name -> Declaration
declarations: HashMap<Attribute, Declaration>,
}
+pub struct DeclParser;
+
+impl<'i> DeclarationParser<'i> for DeclParser {
+ type Declaration = Declaration;
+ type Error = ValueErrorKind;
+
+ fn parse_value<'t>(
+ &mut self,
+ name: CowRcStr<'i>,
+ input: &mut Parser<'i, 't>,
+ ) -> Result<Declaration, cssparser::ParseError<'i, ValueErrorKind>> {
+ if let Ok(attribute) = Attribute::from_str(name.as_ref()) {
+ let property = parse_attribute_value_into_parsed_property(attribute, input, true)
+ .map_err(|e| input.new_custom_error(e))?;
+
+ let important = input.try_parse(parse_important).is_ok();
+
+ Ok(Declaration {
+ attribute,
+ property,
+ important,
+ })
+ } else {
+ Err(input.new_custom_error(ValueErrorKind::UnknownProperty))
+ }
+ }
+}
+
+impl<'i> AtRuleParser<'i> for DeclParser {
+ type PreludeNoBlock = ();
+ type PreludeBlock = ();
+ type AtRule = Declaration;
+ type Error = ValueErrorKind;
+}
+
type Selector = String;
/// Contains all the mappings of selectors to style declarations
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index fc78fd78..e00b3962 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -1,11 +1,8 @@
-use cssparser::{
- self, parse_important, AtRuleParser, CowRcStr, DeclarationListParser, DeclarationParser,
- Parser, ParserInput, Token,
-};
+use cssparser::{self, DeclarationListParser, Parser, ParserInput, Token};
use std::collections::HashSet;
-use std::str::FromStr;
use crate::attributes::Attribute;
+use crate::css::{Declaration, DeclParser};
use crate::error::*;
use crate::font_props::{FontSizeSpec, FontWeightSpec, LetterSpacingSpec, SingleFontFamily};
use crate::iri::IRI;
@@ -16,13 +13,6 @@ use crate::property_bag::PropertyBag;
use crate::property_macros::Property;
use crate::unit_interval::UnitInterval;
-/// A parsed CSS declaration (`name: value [!important]`)
-pub struct Declaration {
- pub attribute: Attribute,
- pub property: ParsedProperty,
- pub important: bool,
-}
-
/// Representation of a single CSS property value.
///
/// `Unspecified` is the `Default`; it means that the corresponding property is not present.
@@ -640,41 +630,6 @@ impl SpecifiedValues {
}
}
-struct DeclParser;
-
-impl<'i> DeclarationParser<'i> for DeclParser {
- type Declaration = Declaration;
- type Error = ValueErrorKind;
-
- fn parse_value<'t>(
- &mut self,
- name: CowRcStr<'i>,
- input: &mut Parser<'i, 't>,
- ) -> Result<Declaration, cssparser::ParseError<'i, ValueErrorKind>> {
- if let Ok(attribute) = Attribute::from_str(name.as_ref()) {
- let property = parse_attribute_value_into_parsed_property(attribute, input, true)
- .map_err(|e| input.new_custom_error(e))?;
-
- let important = input.try_parse(parse_important).is_ok();
-
- Ok(Declaration {
- attribute,
- property,
- important,
- })
- } else {
- Err(input.new_custom_error(ValueErrorKind::UnknownProperty))
- }
- }
-}
-
-impl<'i> AtRuleParser<'i> for DeclParser {
- type PreludeNoBlock = ();
- type PreludeBlock = ();
- type AtRule = Declaration;
- type Error = ValueErrorKind;
-}
-
// Parses the value for the type `T` of the property out of the Parser, including `inherit` values.
fn parse_input<T>(input: &mut Parser) -> Result<SpecifiedValue<T>, <T as Parse>::Err>
where
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]