Handle the case where links are delimited from alts by a tab

This commit is contained in:
Martin Keegan 2025-08-24 18:29:39 +01:00
parent 2a51b67387
commit a358bcbd61

View file

@ -1,4 +1,5 @@
use glib::{DateTime, TimeZone, Uri, UriFlags};
const SEP: [char; 2] = [' ', '\t'];
const S: char = ' ';
pub const TAG: &str = "=>";
@ -18,8 +19,8 @@ impl Link {
/// Parse `Self` from line string
pub fn parse(line: &str) -> Option<Self> {
let l = line.strip_prefix(TAG)?.trim();
let u = l.find(S).map_or(l, |i| &l[..i]);
let l = line.strip_prefix(TAG)?.trim_matches(&SEP);
let u = l.find(|c: char| SEP.contains(&c)).map_or(l, |i| &l[..i]);
if u.is_empty() {
return None;
}
@ -117,3 +118,14 @@ fn test() {
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/");
}