[librsvg/rustify-rsvg-convert: 11/18] rsvg-convert: Validate resolution and zoom values
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustify-rsvg-convert: 11/18] rsvg-convert: Validate resolution and zoom values
- Date: Fri, 8 Jan 2021 14:47:54 +0000 (UTC)
commit 19945cbb77b4a4708428fe42d0b3c481e4974c29
Author: Sven Neumann <sven svenfoo org>
Date: Thu Nov 5 19:28:09 2020 +0100
rsvg-convert: Validate resolution and zoom values
src/bin/rsvg-convert/cli.rs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
---
diff --git a/src/bin/rsvg-convert/cli.rs b/src/bin/rsvg-convert/cli.rs
index a5f21b94..e59822ed 100644
--- a/src/bin/rsvg-convert/cli.rs
+++ b/src/bin/rsvg-convert/cli.rs
@@ -50,6 +50,7 @@ impl Args {
.takes_value(true)
.value_name("float")
.default_value("90")
+ .validator(is_valid_resolution)
.help("Pixels per inch"),
)
.arg(
@@ -59,6 +60,7 @@ impl Args {
.takes_value(true)
.value_name("float")
.default_value("90")
+ .validator(is_valid_resolution)
.help("Pixels per inch"),
)
.arg(
@@ -68,6 +70,7 @@ impl Args {
.takes_value(true)
.value_name("float")
.conflicts_with("zoom")
+ .validator(is_valid_zoom_factor)
.help("Horizontal zoom factor"),
)
.arg(
@@ -77,6 +80,7 @@ impl Args {
.takes_value(true)
.value_name("float")
.conflicts_with("zoom")
+ .validator(is_valid_zoom_factor)
.help("Vertical zoom factor"),
)
.arg(
@@ -85,6 +89,7 @@ impl Args {
.long("zoom")
.takes_value(true)
.value_name("float")
+ .validator(is_valid_zoom_factor)
.help("Zoom factor"),
)
.arg(
@@ -261,6 +266,22 @@ impl Args {
}
}
+fn is_valid_resolution(v: String) -> Result<(), String> {
+ match v.parse::<f64>() {
+ Ok(res) if res > 0.0 => Ok(()),
+ Ok(_) => Err(String::from("Invalid resolution")),
+ Err(e) => Err(format!("{}", e)),
+ }
+}
+
+fn is_valid_zoom_factor(v: String) -> Result<(), String> {
+ match v.parse::<f64>() {
+ Ok(res) if res > 0.0 => Ok(()),
+ Ok(_) => Err(String::from("Invalid zoom factor")),
+ Err(e) => Err(format!("{}", e)),
+ }
+}
+
trait NotFound {
type Ok;
type Error;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]