[librsvg: 22/43] Convert Input and CustomIdent to CssParseError
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 22/43] Convert Input and CustomIdent to CssParseError
- Date: Sat, 21 Dec 2019 02:31:20 +0000 (UTC)
commit c1b12d3f04e9e0a0ac9eb15aca44cfef5030f9a6
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Dec 20 13:22:43 2019 -0600
Convert Input and CustomIdent to CssParseError
rsvg_internals/src/filters/blend.rs | 4 ++--
rsvg_internals/src/filters/composite.rs | 4 ++--
rsvg_internals/src/filters/displacement_map.rs | 4 ++--
rsvg_internals/src/filters/input.rs | 32 +++++++++++++-------------
rsvg_internals/src/filters/merge.rs | 4 ++--
rsvg_internals/src/filters/mod.rs | 6 ++---
6 files changed, 27 insertions(+), 27 deletions(-)
---
diff --git a/rsvg_internals/src/filters/blend.rs b/rsvg_internals/src/filters/blend.rs
index 2b05cdb0..bed30bc8 100755
--- a/rsvg_internals/src/filters/blend.rs
+++ b/rsvg_internals/src/filters/blend.rs
@@ -5,7 +5,7 @@ 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::{Parse, ParseValue};
+use crate::parsers::{Parse, ParseValue, ParseValueToParseError};
use crate::property_bag::PropertyBag;
use crate::surface_utils::shared_surface::SharedImageSurface;
@@ -62,7 +62,7 @@ impl NodeTrait for FeBlend {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!(svg "in2") => {
- self.in2 = Some(attr.parse(value)?);
+ self.in2 = Some(attr.parse_to_parse_error(value)?);
}
expanded_name!(svg "mode") => self.mode = attr.parse(value)?,
_ => (),
diff --git a/rsvg_internals/src/filters/composite.rs b/rsvg_internals/src/filters/composite.rs
index ff8facde..095bc584 100644
--- a/rsvg_internals/src/filters/composite.rs
+++ b/rsvg_internals/src/filters/composite.rs
@@ -5,7 +5,7 @@ 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::{Parse, ParseValue};
+use crate::parsers::{Parse, ParseValue, ParseValueToParseError};
use crate::property_bag::PropertyBag;
use crate::rect::IRect;
use crate::surface_utils::{
@@ -66,7 +66,7 @@ impl NodeTrait for FeComposite {
for (attr, value) in pbag.iter() {
match attr.expanded() {
- expanded_name!(svg "in2") => self.in2 = Some(attr.parse(value)?),
+ expanded_name!(svg "in2") => self.in2 = Some(attr.parse_to_parse_error(value)?),
expanded_name!(svg "operator") => self.operator = attr.parse(value)?,
expanded_name!(svg "k1") => self.k1 = attr.parse(value)?,
expanded_name!(svg "k2") => self.k2 = attr.parse(value)?,
diff --git a/rsvg_internals/src/filters/displacement_map.rs b/rsvg_internals/src/filters/displacement_map.rs
index 1f7ea246..977fdeea 100644
--- a/rsvg_internals/src/filters/displacement_map.rs
+++ b/rsvg_internals/src/filters/displacement_map.rs
@@ -5,7 +5,7 @@ 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::{Parse, ParseValue};
+use crate::parsers::{Parse, ParseValue, ParseValueToParseError};
use crate::property_bag::PropertyBag;
use crate::surface_utils::{iterators::Pixels, shared_surface::SharedImageSurface};
@@ -52,7 +52,7 @@ impl NodeTrait for FeDisplacementMap {
for (attr, value) in pbag.iter() {
match attr.expanded() {
- expanded_name!(svg "in2") => self.in2 = Some(attr.parse(value)?),
+ expanded_name!(svg "in2") => self.in2 = Some(attr.parse_to_parse_error(value)?),
expanded_name!(svg "scale") => self.scale = attr.parse(value)?,
expanded_name!(svg "xChannelSelector") => {
diff --git a/rsvg_internals/src/filters/input.rs b/rsvg_internals/src/filters/input.rs
index ed164269..8d1302ef 100644
--- a/rsvg_internals/src/filters/input.rs
+++ b/rsvg_internals/src/filters/input.rs
@@ -1,7 +1,7 @@
-use cssparser::{Parser, Token};
+use cssparser::{BasicParseError, Parser, Token};
use crate::error::*;
-use crate::parsers::Parse;
+use crate::parsers::ParseToParseError;
/// An enumeration of possible inputs for a filter primitive.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
@@ -19,11 +19,11 @@ pub enum Input {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CustomIdent(String);
-impl Parse for Input {
- fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, ValueErrorKind> {
+impl ParseToParseError for Input {
+ fn parse_to_parse_error<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, CssParseError<'i>> {
parser
.try_parse(|p| {
- parse_identifiers!(
+ Ok(parse_identifiers!(
p,
"SourceGraphic" => Input::SourceGraphic,
"SourceAlpha" => Input::SourceAlpha,
@@ -31,17 +31,17 @@ impl Parse for Input {
"BackgroundAlpha" => Input::BackgroundAlpha,
"FillPaint" => Input::FillPaint,
"StrokePaint" => Input::StrokePaint,
- ).map_err(|_| ValueErrorKind::parse_error("parse error"))
+ )?)
})
- .or_else(|_| {
- let ident = CustomIdent::parse(parser)?;
+ .or_else(|_: BasicParseError| {
+ let ident = CustomIdent::parse_to_parse_error(parser)?;
Ok(Input::FilterOutput(ident))
})
}
}
-impl Parse for CustomIdent {
- fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, ValueErrorKind> {
+impl ParseToParseError for CustomIdent {
+ fn parse_to_parse_error<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, CssParseError<'i>> {
let loc = parser.current_source_location();
let token = parser.next()?;
@@ -70,17 +70,17 @@ mod tests {
#[test]
fn parses_custom_ident() {
assert_eq!(
- CustomIdent::parse_str("hello"),
+ CustomIdent::parse_str_to_parse_error("hello"),
Ok(CustomIdent("hello".to_string()))
);
}
#[test]
fn invalid_custom_ident_yields_error() {
- assert!(CustomIdent::parse_str("initial").is_err());
- assert!(CustomIdent::parse_str("inherit").is_err());
- assert!(CustomIdent::parse_str("unset").is_err());
- assert!(CustomIdent::parse_str("default").is_err());
- assert!(CustomIdent::parse_str("").is_err());
+ assert!(CustomIdent::parse_str_to_parse_error("initial").is_err());
+ assert!(CustomIdent::parse_str_to_parse_error("inherit").is_err());
+ assert!(CustomIdent::parse_str_to_parse_error("unset").is_err());
+ assert!(CustomIdent::parse_str_to_parse_error("default").is_err());
+ assert!(CustomIdent::parse_str_to_parse_error("").is_err());
}
}
diff --git a/rsvg_internals/src/filters/merge.rs b/rsvg_internals/src/filters/merge.rs
index eb47e735..0f6d821e 100644
--- a/rsvg_internals/src/filters/merge.rs
+++ b/rsvg_internals/src/filters/merge.rs
@@ -3,7 +3,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::drawing_ctx::DrawingCtx;
use crate::node::{NodeResult, NodeTrait, NodeType, RsvgNode};
-use crate::parsers::ParseValue;
+use crate::parsers::ParseValueToParseError;
use crate::property_bag::PropertyBag;
use crate::rect::IRect;
use crate::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
@@ -47,7 +47,7 @@ impl NodeTrait for FeMergeNode {
fn set_atts(&mut self, _parent: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
- expanded_name!(svg "in") => self.in_ = Some(attr.parse(value)?),
+ expanded_name!(svg "in") => self.in_ = Some(attr.parse_to_parse_error(value)?),
_ => (),
}
}
diff --git a/rsvg_internals/src/filters/mod.rs b/rsvg_internals/src/filters/mod.rs
index 844f082a..71c8b638 100644
--- a/rsvg_internals/src/filters/mod.rs
+++ b/rsvg_internals/src/filters/mod.rs
@@ -13,7 +13,7 @@ use crate::error::{RenderingError, ValueErrorKind};
use crate::filter::Filter;
use crate::length::*;
use crate::node::{CascadedValues, NodeResult, NodeTrait, NodeType, RsvgNode};
-use crate::parsers::{ParseValue, ParseValueToParseError};
+use crate::parsers::ParseValueToParseError;
use crate::properties::ComputedValues;
use crate::property_bag::PropertyBag;
use crate::property_defs::ColorInterpolationFilters;
@@ -182,7 +182,7 @@ impl NodeTrait for Primitive {
check_units_vertical_and_ensure_nonnegative,
)?)
}
- expanded_name!(svg "result") => self.result = Some(attr.parse(value)?),
+ expanded_name!(svg "result") => self.result = Some(attr.parse_to_parse_error(value)?),
_ => (),
}
}
@@ -218,7 +218,7 @@ impl NodeTrait for PrimitiveWithInput {
for (attr, value) in pbag.iter() {
match attr.expanded() {
- expanded_name!(svg "in") => self.in_ = Some(attr.parse(value)?),
+ expanded_name!(svg "in") => self.in_ = Some(attr.parse_to_parse_error(value)?),
_ => (),
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]