[librsvg] RsvgLength::check_nonnegative(): New method
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] RsvgLength::check_nonnegative(): New method
- Date: Mon, 4 Sep 2017 21:54:45 +0000 (UTC)
commit e75d807011f9ed46ab8545dfe534a76f11fd26ab
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Sep 4 12:29:48 2017 -0500
RsvgLength::check_nonnegative(): New method
rust/src/length.rs | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/length.rs b/rust/src/length.rs
index 6562cf5..4f5e00d 100644
--- a/rust/src/length.rs
+++ b/rust/src/length.rs
@@ -190,6 +190,14 @@ impl RsvgLength {
Ok (length)
}
+ pub fn check_nonnegative (&self) -> Result <RsvgLength, AttributeError> {
+ if self.length >= 0.0 {
+ Ok (*self)
+ } else {
+ Err (AttributeError::Value ("value must be non-negative".to_string ()))
+ }
+ }
+
pub fn normalize (&self, draw_ctx: *const RsvgDrawingCtx) -> f64 {
match self.unit {
LengthUnit::Default => {
@@ -425,4 +433,10 @@ mod tests {
// to move this test to that type later.
assert! (is_parse_error (&RsvgLength::parse ("furlong", LengthDir::Both)));
}
+
+ #[test]
+ fn check_nonnegative_works () {
+ assert! (RsvgLength::parse ("0", LengthDir::Both).and_then (|l| l.check_nonnegative ()).is_ok ());
+ assert! (RsvgLength::parse ("-10", LengthDir::Both).and_then (|l| l.check_nonnegative ()).is_err ());
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]