[librsvg: 2/3] parsers: implement Parse for NumberList
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/3] parsers: implement Parse for NumberList
- Date: Mon, 3 May 2021 17:18:27 +0000 (UTC)
commit 4b483199173391b436c8ea71f8e26f618bb9395d
Author: Paolo Borelli <pborelli gnome org>
Date: Sun May 2 16:38:20 2021 +0200
parsers: implement Parse for NumberList
src/filters/color_matrix.rs | 3 +--
src/filters/component_transfer.rs | 3 +--
src/filters/convolve_matrix.rs | 3 +--
src/parsers.rs | 13 ++-----------
4 files changed, 5 insertions(+), 17 deletions(-)
---
diff --git a/src/filters/color_matrix.rs b/src/filters/color_matrix.rs
index 46f5257c..ac5f937b 100644
--- a/src/filters/color_matrix.rs
+++ b/src/filters/color_matrix.rs
@@ -95,8 +95,7 @@ impl SetAttributes for FeColorMatrix {
let new_matrix = match operation_type {
OperationType::LuminanceToAlpha => unreachable!(),
OperationType::Matrix => {
- let NumberList::<20, 20>(v) = NumberList::parse_str(value)
- .attribute(attr)?;
+ let NumberList::<20, 20>(v) = attr.parse(value)?;
let matrix = Matrix4x5::from_row_slice(&v);
let mut matrix = matrix.fixed_resize(0.0);
matrix[(4, 4)] = 1.0;
diff --git a/src/filters/component_transfer.rs b/src/filters/component_transfer.rs
index e38f3991..f879f1f5 100644
--- a/src/filters/component_transfer.rs
+++ b/src/filters/component_transfer.rs
@@ -220,8 +220,7 @@ macro_rules! func_x {
expanded_name!("", "type") => self.function_type = attr.parse(value)?,
expanded_name!("", "tableValues") => {
// #691: Limit list to 256 to mitigate malicious SVGs
- let NumberList::<0, 256>(v) =
- NumberList::parse_str(value).attribute(attr)?;
+ let NumberList::<0, 256>(v) = attr.parse(value)?;
self.table_values = v;
}
expanded_name!("", "slope") => self.slope = attr.parse(value)?,
diff --git a/src/filters/convolve_matrix.rs b/src/filters/convolve_matrix.rs
index 8f77d2d8..afb7265c 100644
--- a/src/filters/convolve_matrix.rs
+++ b/src/filters/convolve_matrix.rs
@@ -107,8 +107,7 @@ impl SetAttributes for FeConvolveMatrix {
// #352: Parse as an unbounded list rather than exact length to prevent aborts due
// to huge allocation attempts by underlying Vec::with_capacity().
// #691: Limit list to 400 (20x20) to mitigate malicious SVGs
- let NumberList::<0, 400>(v) =
- NumberList::parse_str(value).attribute(attr.clone())?;
+ let NumberList::<0, 400>(v) = attr.parse(value)?;
// #691: Update check as v.len can be different than number of elements because
// of the above limit (and will = 400 if that happens)
if v.len() != number_of_elements && v.len() != 400 {
diff --git a/src/parsers.rs b/src/parsers.rs
index 75b1db48..c1bb1b3a 100644
--- a/src/parsers.rs
+++ b/src/parsers.rs
@@ -135,8 +135,8 @@ impl Parse for u32 {
#[derive(Debug, PartialEq)]
pub struct NumberList<const REQUIRED: usize, const MAX: usize>(pub Vec<f64>);
-impl<const REQUIRED: usize, const MAX: usize> NumberList<REQUIRED, MAX> {
- pub fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
+impl<const REQUIRED: usize, const MAX: usize> Parse for NumberList<REQUIRED, MAX> {
+ fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
let loc = parser.current_source_location();
let mut v = Vec::<f64>::with_capacity(MAX);
for i in 0..MAX {
@@ -157,15 +157,6 @@ impl<const REQUIRED: usize, const MAX: usize> NumberList<REQUIRED, MAX> {
Ok(NumberList(v))
}
}
-
- pub fn parse_str(s: &str) -> Result<Self, ParseError<'_>> {
- let mut input = ParserInput::new(s);
- let mut parser = Parser::new(&mut input);
-
- let res = Self::parse(&mut parser)?;
- parser.expect_exhausted()?;
- Ok(res)
- }
}
/// Parses a list of identifiers from a `cssparser::Parser`
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]