[librsvg/rustify-rsvg-convert] PathOrUrl: extract function to do the UTF8-to-PathOrUrl heuristic
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustify-rsvg-convert] PathOrUrl: extract function to do the UTF8-to-PathOrUrl heuristic
- Date: Thu, 21 Jan 2021 20:06:55 +0000 (UTC)
commit 829d3acbeee9ddfffa60e4cc674255d2c1919c98
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Jan 21 13:19:54 2021 -0600
PathOrUrl: extract function to do the UTF8-to-PathOrUrl heuristic
src/c_api/handle.rs | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/src/c_api/handle.rs b/src/c_api/handle.rs
index 8bcf0208..3e5df6c7 100644
--- a/src/c_api/handle.rs
+++ b/src/c_api/handle.rs
@@ -2145,16 +2145,19 @@ impl PathOrUrl {
Ok(cstr
.to_str()
.map_err(|_| ())
- .and_then(|utf8| Url::parse(utf8).map_err(|_| ()))
- .and_then(|url| {
- if url.origin().is_tuple() || url.scheme() == "file" {
- Ok(PathOrUrl::Url(url))
- } else {
- Ok(PathOrUrl::Path(url.to_file_path()?))
- }
- })
+ .and_then(Self::try_from_str)
.unwrap_or_else(|_| PathOrUrl::Path(PathBuf::from_glib_none(s))))
}
+
+ fn try_from_str(s: &str) -> Result<PathOrUrl, ()> {
+ Url::parse(s).map_err(|_| ()).and_then(|url| {
+ if url.origin().is_tuple() || url.scheme() == "file" {
+ Ok(PathOrUrl::Url(url))
+ } else {
+ Ok(PathOrUrl::Path(url.to_file_path()?))
+ }
+ })
+ }
}
fn check_cairo_context(cr: &cairo::Context) -> Result<(), RenderingError> {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]