[librsvg: 34/51] BaselineShift: simplify parsing
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 34/51] BaselineShift: simplify parsing
- Date: Thu, 19 Dec 2019 01:50:52 +0000 (UTC)
commit 00dae7c58631630b80e5030ffa5a6603d546bbf4
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 17 21:03:02 2019 -0600
BaselineShift: simplify parsing
rsvg_internals/src/property_defs.rs | 43 +++++++++++--------------------------
1 file changed, 12 insertions(+), 31 deletions(-)
---
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index ac6c07e9..05fe23b1 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -1,10 +1,10 @@
//! Definitions for CSS property types.
-use cssparser::{self, Parser, Token};
+use cssparser::{self, Parser};
+use crate::dasharray::Dasharray;
use crate::error::*;
use crate::font_props::{FontSizeSpec, FontWeightSpec, LetterSpacingSpec, SingleFontFamily};
-use crate::dasharray::Dasharray;
use crate::iri::IRI;
use crate::length::*;
use crate::paint_server::PaintServer;
@@ -45,35 +45,16 @@ make_property!(
// These values come from Inkscape's SP_CSS_BASELINE_SHIFT_(SUB/SUPER/BASELINE);
// see sp_style_merge_baseline_shift_from_parent()
fn parse(parser: &mut Parser<'_, '_>) -> Result<BaselineShift, crate::error::ValueErrorKind> {
- let parser_state = parser.state();
-
- {
- let token = parser.next().map_err(|_| {
- crate::error::ValueErrorKind::parse_error("expected token")
- })?;
-
- if let Token::Ident(ref cow) = token {
- match cow.as_ref() {
- "baseline" => return Ok(BaselineShift(
- Length::<Both>::new(0.0, LengthUnit::Percent)
- )),
-
- "sub" => return Ok(BaselineShift(
- Length::<Both>::new(-0.2, LengthUnit::Percent)
- )),
-
- "super" => return Ok(BaselineShift(
- Length::<Both>::new(0.4, LengthUnit::Percent),
- )),
-
- _ => (),
- }
- }
- }
-
- parser.reset(&parser_state);
-
- Ok(BaselineShift(Length::<Both>::parse(parser)?))
+ parser.try_parse(|p| Ok(BaselineShift(Length::<Both>::parse(p)?)))
+ .or_else(|_: ValueErrorKind| {
+ parse_identifiers!(
+ parser,
+ "baseline" => BaselineShift(Length::<Both>::new(0.0, LengthUnit::Percent)),
+ "sub" => BaselineShift(Length::<Both>::new(-0.2, LengthUnit::Percent)),
+
+ "super" => BaselineShift(Length::<Both>::new(0.4, LengthUnit::Percent)),
+ ).map_err(|_: ParseError| ValueErrorKind::parse_error("parse error"))
+ })
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]