[librsvg] CoordUnits: use a cssparser
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] CoordUnits: use a cssparser
- Date: Thu, 14 Jun 2018 01:20:37 +0000 (UTC)
commit ee38b6c6b3e8e49e21dd9befbe5e346f2c4e9877
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jun 12 18:12:20 2018 -0500
CoordUnits: use a cssparser
We'll refactor the Parse trait later.
rsvg_internals/src/coord_units.rs | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/rsvg_internals/src/coord_units.rs b/rsvg_internals/src/coord_units.rs
index 60f2700d..5f9931aa 100644
--- a/rsvg_internals/src/coord_units.rs
+++ b/rsvg_internals/src/coord_units.rs
@@ -1,3 +1,5 @@
+use cssparser::{CowRcStr, Parser, ParserInput, Token};
+
use error::AttributeError;
use parsers::{Parse, ParseError};
@@ -18,13 +20,26 @@ impl Parse for CoordUnits {
type Err = AttributeError;
fn parse(s: &str, _: ()) -> Result<CoordUnits, AttributeError> {
- match s {
- "userSpaceOnUse" => Ok(CoordUnits::UserSpaceOnUse),
- "objectBoundingBox" => Ok(CoordUnits::ObjectBoundingBox),
- _ => Err(AttributeError::Parse(ParseError::new(
- "expected 'userSpaceOnUse' or 'objectBoundingBox'",
- ))),
- }
+ let mut input = ParserInput::new(s);
+ let mut parser = Parser::new(&mut input);
+ let loc = parser.current_source_location();
+
+ parser
+ .expect_ident()
+ .and_then(|cow| match cow.as_ref() {
+ "userSpaceOnUse" => Ok(CoordUnits::UserSpaceOnUse),
+ "objectBoundingBox" => Ok(CoordUnits::ObjectBoundingBox),
+ _ => Err(
+ loc.new_basic_unexpected_token_error(Token::Ident(CowRcStr::from(
+ cow.as_ref().to_string(),
+ ))),
+ ),
+ })
+ .map_err(|_| {
+ AttributeError::Parse(ParseError::new(
+ "expected 'userSpaceOnUse' or 'objectBoundingBox'",
+ ))
+ })
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]