[librsvg: 38/51] morphology.rs: impl Parse for Operator instead of using a custom method
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 38/51] morphology.rs: impl Parse for Operator instead of using a custom method
- Date: Thu, 19 Dec 2019 01:51:13 +0000 (UTC)
commit 6d363367e5b183cdac4900f6aff97005f4a2bee2
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Dec 18 10:24:00 2019 -0600
morphology.rs: impl Parse for Operator instead of using a custom method
rsvg_internals/src/filters/morphology.rs | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/rsvg_internals/src/filters/morphology.rs b/rsvg_internals/src/filters/morphology.rs
index e6dcb844..baad7545 100644
--- a/rsvg_internals/src/filters/morphology.rs
+++ b/rsvg_internals/src/filters/morphology.rs
@@ -1,20 +1,19 @@
use std::cmp::{max, min};
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 crate::drawing_ctx::DrawingCtx;
use crate::error::*;
use crate::node::{NodeResult, NodeTrait, RsvgNode};
-use crate::parsers;
+use crate::parsers::{self, Parse, ParseValue};
use crate::property_bag::PropertyBag;
use crate::rect::IRect;
use crate::surface_utils::{
iterators::{PixelRectangle, Pixels},
shared_surface::SharedImageSurface,
- EdgeMode,
- ImageSurfaceDataExt,
- Pixel,
+ EdgeMode, ImageSurfaceDataExt, Pixel,
};
use super::context::{FilterContext, FilterOutput, FilterResult};
@@ -54,7 +53,7 @@ impl NodeTrait for FeMorphology {
for (attr, value) in pbag.iter() {
match attr.expanded() {
- expanded_name!(svg "operator") => self.operator = Operator::parse(attr, value)?,
+ expanded_name!(svg "operator") => self.operator = attr.parse(value)?,
expanded_name!(svg "radius") => {
self.radius = parsers::number_optional_number(value)
.and_then(|(x, y)| {
@@ -63,7 +62,8 @@ impl NodeTrait for FeMorphology {
} else {
Err(ValueErrorKind::value_error("radius cannot be negative"))
}
- }).attribute(attr)?
+ })
+ .attribute(attr)?
}
_ => (),
}
@@ -159,12 +159,13 @@ impl FilterEffect for FeMorphology {
}
}
-impl Operator {
- fn parse(attr: QualName, s: &str) -> Result<Self, NodeError> {
- match s {
- "erode" => Ok(Operator::Erode),
- "dilate" => Ok(Operator::Dilate),
- _ => Err(ValueErrorKind::parse_error("invalid value")).attribute(attr),
- }
+impl Parse for Operator {
+ fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<Operator, ValueErrorKind> {
+ parse_identifiers!(
+ parser,
+ "erode" => Operator::Erode,
+ "dilate" => Operator::Dilate,
+ )
+ .map_err(|_: ParseError| ValueErrorKind::parse_error("parse error"))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]