[librsvg: 30/51] LetterSpacingSpec: simplify parsing
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 30/51] LetterSpacingSpec: simplify parsing
- Date: Thu, 19 Dec 2019 01:50:32 +0000 (UTC)
commit aa4b4f7eb434c75ca9633ebd1fcf03a49934afff
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 17 20:28:53 2019 -0600
LetterSpacingSpec: simplify parsing
rsvg_internals/src/font_props.rs | 33 +++++++++------------------------
1 file changed, 9 insertions(+), 24 deletions(-)
---
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index 48903dfb..8e0796ff 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -1,6 +1,6 @@
//! CSS font properties.
-use cssparser::{BasicParseError, Parser, Token};
+use cssparser::{BasicParseError, Parser};
use crate::drawing_ctx::ViewParams;
use crate::error::*;
@@ -173,29 +173,14 @@ impl Parse for LetterSpacingSpec {
fn parse(
parser: &mut Parser<'_, '_>,
) -> Result<LetterSpacingSpec, crate::error::ValueErrorKind> {
- let parser_state = parser.state();
-
- Length::<Horizontal>::parse(parser)
- .and_then(|s| Ok(LetterSpacingSpec::Value(s)))
- .or_else(|e| {
- parser.reset(&parser_state);
-
- {
- let token = parser.next().map_err(|_| {
- crate::error::ValueErrorKind::parse_error("expected token")
- })?;
-
- if let Token::Ident(ref cow) = token {
- if let "normal" = cow.as_ref() {
- return Ok(LetterSpacingSpec::Normal);
- }
- }
- }
-
- parser.reset(&parser_state);
-
- Err(e)
- })
+ parser.try_parse(|p| Length::<Horizontal>::parse(p))
+ .and_then(|l| Ok(LetterSpacingSpec::Value(l)))
+ .or_else(|_| {
+ parse_identifiers!(
+ parser,
+ "normal" => LetterSpacingSpec::Normal,
+ )
+ }).map_err(|_: ParseError| ValueErrorKind::parse_error("parse error"))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]