[librsvg: 42/51] color_matrix.rs: impl Parse for OperationType instead of using a custom method
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 42/51] color_matrix.rs: impl Parse for OperationType instead of using a custom method
- Date: Thu, 19 Dec 2019 01:51:33 +0000 (UTC)
commit 34cabb86eebf3907a0a5255cb09d631c9a753f49
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Dec 18 10:43:43 2019 -0600
color_matrix.rs: impl Parse for OperationType instead of using a custom method
rsvg_internals/src/filters/color_matrix.rs | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/rsvg_internals/src/filters/color_matrix.rs b/rsvg_internals/src/filters/color_matrix.rs
index 8198667a..f64bfe44 100644
--- a/rsvg_internals/src/filters/color_matrix.rs
+++ b/rsvg_internals/src/filters/color_matrix.rs
@@ -1,12 +1,13 @@
use cairo::{self, ImageSurface};
-use markup5ever::{expanded_name, local_name, namespace_url, ns, QualName};
+use cssparser::Parser;
+use markup5ever::{expanded_name, local_name, namespace_url, ns};
use nalgebra::{Matrix3, Matrix4x5, Matrix5, Vector5};
use crate::drawing_ctx::DrawingCtx;
use crate::error::*;
use crate::node::{NodeResult, NodeTrait, RsvgNode};
use crate::number_list::{NumberList, NumberListError, NumberListLength};
-use crate::parsers;
+use crate::parsers::{self, Parse, ParseValue};
use crate::property_bag::PropertyBag;
use crate::surface_utils::{
iterators::Pixels, shared_surface::SharedImageSurface, ImageSurfaceDataExt, Pixel,
@@ -54,7 +55,7 @@ impl NodeTrait for FeColorMatrix {
.iter()
.filter(|(attr, _)| attr.expanded() == expanded_name!(svg "type"))
{
- operation_type = OperationType::parse(attr, value)?;
+ operation_type = attr.parse(value)?;
}
// Now read the matrix correspondingly.
@@ -225,14 +226,14 @@ impl FilterEffect for FeColorMatrix {
}
}
-impl OperationType {
- fn parse(attr: QualName, s: &str) -> Result<Self, NodeError> {
- match s {
- "matrix" => Ok(OperationType::Matrix),
- "saturate" => Ok(OperationType::Saturate),
- "hueRotate" => Ok(OperationType::HueRotate),
- "luminanceToAlpha" => Ok(OperationType::LuminanceToAlpha),
- _ => Err(ValueErrorKind::parse_error("invalid value")).attribute(attr),
- }
+impl Parse for OperationType {
+ fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, ValueErrorKind> {
+ parse_identifiers!(
+ parser,
+ "matrix" => OperationType::Matrix,
+ "saturate" => OperationType::Saturate,
+ "hueRotate" => OperationType::HueRotate,
+ "luminanceToAlpha" => OperationType::LuminanceToAlpha,
+ ).map_err(|_: ParseError| ValueErrorKind::parse_error("parse error"))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]