[librsvg: 2/11] 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: 2/11] PathOrUrl: extract function to do the UTF8-to-PathOrUrl heuristic
- Date: Wed, 3 Feb 2021 00:47:23 +0000 (UTC)
commit e4fa47421d7b0158a310d4864c9ac0b4d3de9869
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 c17fb73c..e29e51c3 100644
--- a/src/c_api/handle.rs
+++ b/src/c_api/handle.rs
@@ -2157,16 +2157,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]