[librsvg: 31/51] SpreadMethod: simplify parsing
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 31/51] SpreadMethod: simplify parsing
- Date: Thu, 19 Dec 2019 01:50:37 +0000 (UTC)
commit 3428fe797206f4fd146e499ca36acc298a40ca53
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 17 20:39:37 2019 -0600
SpreadMethod: simplify parsing
rsvg_internals/src/gradient.rs | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
---
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index b780dad1..d36e90a6 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -1,7 +1,7 @@
//! Gradient paint servers; the `linearGradient` and `radialGradient` elements.
use cairo;
-use cssparser::{self, CowRcStr, Parser, Token};
+use cssparser::{self, Parser};
use markup5ever::{expanded_name, local_name, namespace_url, ns};
use std::cell::RefCell;
@@ -45,23 +45,12 @@ enum SpreadMethod {
impl Parse for SpreadMethod {
fn parse(parser: &mut Parser<'_, '_>) -> Result<SpreadMethod, ValueErrorKind> {
- let loc = parser.current_source_location();
-
- parser
- .expect_ident()
- .and_then(|cow| match cow.as_ref() {
- "pad" => Ok(SpreadMethod::Pad),
- "reflect" => Ok(SpreadMethod::Reflect),
- "repeat" => Ok(SpreadMethod::Repeat),
- _ => Err(
- loc.new_basic_unexpected_token_error(Token::Ident(CowRcStr::from(
- cow.as_ref().to_string(),
- ))),
- ),
- })
- .map_err(|_| {
- ValueErrorKind::parse_error("expected 'pad' | 'reflect' | 'repeat'")
- })
+ parse_identifiers!(
+ parser,
+ "pad" => SpreadMethod::Pad,
+ "reflect" => SpreadMethod::Reflect,
+ "repeat" => SpreadMethod::Repeat,
+ ).map_err(|_: ParseError| ValueErrorKind::parse_error("parse error"))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]