update value preparation, add comments

This commit is contained in:
yggverse 2024-12-03 18:33:26 +02:00
parent 4741365154
commit 2e0a1ae3ef

View file

@ -1,10 +1,12 @@
use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
/// [List item](https://geminiprotocol.net/docs/gemtext-specification.gmi#list-items)
pub struct List {
pub value: String,
}
impl List {
/// Parse `Self` from string
pub fn from(line: &str) -> Option<Self> {
// Parse line
let regex = Regex::split_simple(
@ -14,12 +16,10 @@ impl List {
RegexMatchFlags::DEFAULT,
);
// Detect value
let value = regex.get(1)?.trim();
// Extract formatted value
let value = regex.get(1)?.trim().to_string();
// Result
Some(Self {
value: String::from(value),
})
Some(Self { value })
}
}