[librsvg: 32/51] MarkerUnits: simplify parsing
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 32/51] MarkerUnits: simplify parsing
- Date: Thu, 19 Dec 2019 01:50:42 +0000 (UTC)
commit 2a9b4a3a6c4fd6a4f270e02ee06bdd4b3e5a2f58
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 17 20:43:11 2019 -0600
MarkerUnits: simplify parsing
rsvg_internals/src/marker.rs | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 4749d535..5d4b2e8e 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -3,7 +3,7 @@
use std::f64::consts::*;
use std::ops::Deref;
-use cssparser::{CowRcStr, Parser, Token};
+use cssparser::Parser;
use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::allowed_url::Fragment;
@@ -38,22 +38,12 @@ impl Default for MarkerUnits {
impl Parse for MarkerUnits {
fn parse(parser: &mut Parser<'_, '_>) -> Result<MarkerUnits, ValueErrorKind> {
- let loc = parser.current_source_location();
-
- parser
- .expect_ident()
- .and_then(|cow| match cow.as_ref() {
- "userSpaceOnUse" => Ok(MarkerUnits::UserSpaceOnUse),
- "strokeWidth" => Ok(MarkerUnits::StrokeWidth),
- _ => Err(
- loc.new_basic_unexpected_token_error(Token::Ident(CowRcStr::from(
- cow.as_ref().to_string(),
- ))),
- ),
- })
- .map_err(|_| {
- ValueErrorKind::parse_error("expected \"userSpaceOnUse\" or \"strokeWidth\"")
- })
+ parse_identifiers!(
+ parser,
+ "userSpaceOnUse" => MarkerUnits::UserSpaceOnUse,
+ "strokeWidth" => MarkerUnits::StrokeWidth,
+ )
+ .map_err(|_: ParseError| ValueErrorKind::parse_error("parse error"))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]