[librsvg] parsers: make optional_comma a method of the extension trait
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] parsers: make optional_comma a method of the extension trait
- Date: Sat, 29 Dec 2018 18:06:44 +0000 (UTC)
commit 9c46bc471eed2a6081fbf6fffd127f032a3b18ae
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Dec 29 18:24:28 2018 +0100
parsers: make optional_comma a method of the extension trait
rsvg_internals/src/parsers.rs | 15 ++++++++-------
rsvg_internals/src/shapes.rs | 6 +++---
rsvg_internals/src/transform.rs | 22 +++++++++++-----------
3 files changed, 22 insertions(+), 21 deletions(-)
---
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index 9c4dcf53..068eb7d8 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -41,16 +41,21 @@ pub trait Parse: Sized {
}
}
-/// Extend `cssparser::Parser` with a `expect_finite_number` method,
-/// to avoid infinities.
pub trait CssParserExt {
+ /// Avoid infinities.
fn expect_finite_number(&mut self) -> Result<f32, ValueErrorKind>;
+
+ fn optional_comma(&mut self);
}
impl<'i, 't> CssParserExt for Parser<'i, 't> {
fn expect_finite_number(&mut self) -> Result<f32, ValueErrorKind> {
finite_f32(self.expect_number()?)
}
+
+ fn optional_comma(&mut self) {
+ let _ = self.try(|p| p.expect_comma());
+ }
}
pub fn finite_f32(n: f32) -> Result<f32, ValueErrorKind> {
@@ -115,10 +120,6 @@ where
.map_err(|e| NodeError::attribute_error(Attribute::from_str(key).unwrap(), e))
}
-pub fn optional_comma(parser: &mut Parser<'_, '_>) {
- let _ = parser.try(|p| p.expect_comma());
-}
-
// number
//
// https://www.w3.org/TR/SVG11/types.html#DataTypeNumber
@@ -232,7 +233,7 @@ pub fn number_list(
for i in 0.. {
if i != 0 {
- optional_comma(parser);
+ parser.optional_comma();
}
v.push(f64::from(parser.expect_finite_number().map_err(|_| {
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index 41e1b1ec..bc4fa88c 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -11,7 +11,7 @@ use handle::RsvgHandle;
use length::*;
use marker;
use node::*;
-use parsers::{optional_comma, parse, parse_and_validate, CssParserExt, Parse};
+use parsers::{parse, parse_and_validate, CssParserExt, Parse};
use path_builder::*;
use path_parser;
use property_bag::PropertyBag;
@@ -198,7 +198,7 @@ impl Parse for Points {
loop {
let x = f64::from(parser.expect_finite_number()?);
- optional_comma(parser);
+ parser.optional_comma();
let y = f64::from(parser.expect_finite_number()?);
v.push((x, y));
@@ -209,7 +209,7 @@ impl Parse for Points {
match parser.next_including_whitespace() {
Ok(&Token::WhiteSpace(_)) => (),
- _ => optional_comma(parser),
+ _ => parser.optional_comma(),
}
}
diff --git a/rsvg_internals/src/transform.rs b/rsvg_internals/src/transform.rs
index 9bbb6692..d45ef7c4 100644
--- a/rsvg_internals/src/transform.rs
+++ b/rsvg_internals/src/transform.rs
@@ -6,7 +6,7 @@ use cairo::MatrixTrait;
use cssparser::{ParseError as CssParseError, Parser, Token};
use error::*;
-use parsers::{finite_f32, optional_comma, Parse, ParseError};
+use parsers::{finite_f32, CssParserExt, Parse, ParseError};
impl Parse for cairo::Matrix {
type Data = ();
@@ -37,7 +37,7 @@ fn parse_transform_list(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, Va
let m = parse_transform_command(parser)?;
matrix = cairo::Matrix::multiply(&m, &matrix);
- optional_comma(parser);
+ parser.optional_comma();
}
Ok(matrix)
@@ -81,19 +81,19 @@ fn parse_matrix_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, Value
parser
.parse_nested_block(|p| {
let xx = p.expect_number()?;
- optional_comma(p);
+ p.optional_comma();
let yx = p.expect_number()?;
- optional_comma(p);
+ p.optional_comma();
let xy = p.expect_number()?;
- optional_comma(p);
+ p.optional_comma();
let yy = p.expect_number()?;
- optional_comma(p);
+ p.optional_comma();
let x0 = p.expect_number()?;
- optional_comma(p);
+ p.optional_comma();
let y0 = p.expect_number()?;
@@ -120,7 +120,7 @@ fn parse_translate_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, Va
let ty = p
.try(|p| -> Result<f32, CssParseError<'_, ()>> {
- optional_comma(p);
+ p.optional_comma();
Ok(p.expect_number()?)
})
.unwrap_or(0.0);
@@ -144,7 +144,7 @@ fn parse_scale_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, ValueE
let y = p
.try(|p| -> Result<f32, CssParseError<'_, ()>> {
- optional_comma(p);
+ p.optional_comma();
Ok(p.expect_number()?)
})
.unwrap_or(x);
@@ -168,10 +168,10 @@ fn parse_rotate_args(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, Value
let (tx, ty) = p
.try(|p| -> Result<_, CssParseError<'_, ()>> {
- optional_comma(p);
+ p.optional_comma();
let tx = p.expect_number()?;
- optional_comma(p);
+ p.optional_comma();
let ty = p.expect_number()?;
Ok((tx, ty))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]