This commit is contained in:
Martin Keegan 2025-08-24 17:33:35 +00:00 committed by GitHub
commit fb62202902
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,5 @@
use glib::{DateTime, TimeZone, Uri, UriFlags}; use glib::{DateTime, TimeZone, Uri, UriFlags};
const SEP: [char; 2] = [' ', '\t'];
const S: char = ' '; const S: char = ' ';
pub const TAG: &str = "=>"; pub const TAG: &str = "=>";
@ -18,8 +19,8 @@ impl Link {
/// Parse `Self` from line string /// Parse `Self` from line string
pub fn parse(line: &str) -> Option<Self> { pub fn parse(line: &str) -> Option<Self> {
let l = line.strip_prefix(TAG)?.trim(); let l = line.strip_prefix(TAG)?.trim_matches(&SEP);
let u = l.find(S).map_or(l, |i| &l[..i]); let u = l.find(|c: char| SEP.contains(&c)).map_or(l, |i| &l[..i]);
if u.is_empty() { if u.is_empty() {
return None; return None;
} }
@ -117,3 +118,14 @@ fn test() {
assert_eq!(link.to_source(), SOURCE); assert_eq!(link.to_source(), SOURCE);
} }
#[test]
fn test_tab() {
use crate::line::Link;
const SOURCE: &str = "=> gemlog/\tMy gemlog - verbose ramblings";
let link = Link::parse(SOURCE).unwrap();
assert_eq!(link.alt, Some("My gemlog - verbose ramblings".to_string()));
assert_eq!(link.url, "gemlog/");
}