[librsvg] Fragment::parse(): New convenience function
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Fragment::parse(): New convenience function
- Date: Fri, 30 Nov 2018 00:31:46 +0000 (UTC)
commit 199930a4cdc7ca57fccfb95e7165fad25b1c49be
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Nov 29 17:14:26 2018 -0600
Fragment::parse(): New convenience function
To avoid going through Href::with_fragment()
rsvg_internals/src/defs.rs | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
---
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index ee5632c0..d536b704 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -93,6 +93,16 @@ impl Fragment {
Fragment(uri, fragment)
}
+ pub fn parse(href: &str) -> Result<Fragment, HrefError> {
+ let href = Href::with_fragment(href)?;
+
+ if let Href::WithFragment(f) = href {
+ Ok(f)
+ } else {
+ unreachable!();
+ }
+ }
+
pub fn uri(&self) -> Option<&str> {
self.0.as_ref().map(|s| s.as_str())
}
@@ -301,4 +311,19 @@ mod tests {
assert_eq!(Href::with_fragment("uri"), Err(HrefError::FragmentRequired));
}
+
+ #[test]
+ fn fragment_parse() {
+ assert_eq!(
+ Fragment::parse("#foo").unwrap(),
+ Fragment::new(None, "foo".to_string())
+ );
+
+ assert_eq!(
+ Fragment::parse("uri#foo").unwrap(),
+ Fragment::new(Some("uri".to_string()), "foo".to_string())
+ );
+
+ assert_eq!(Fragment::parse("uri"), Err(HrefError::FragmentRequired));
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]