mirror of
https://github.com/YGGverse/ggemtext.git
synced 2026-04-02 01:55:36 +00:00
29 lines
613 B
Rust
29 lines
613 B
Rust
use gtk::glib::{GString, Regex, RegexCompileFlags, RegexMatchFlags};
|
|
|
|
pub struct Quote {
|
|
pub value: GString,
|
|
}
|
|
|
|
impl Quote {
|
|
pub fn from(line: &str) -> Option<Self> {
|
|
// Parse line
|
|
let regex = Regex::split_simple(
|
|
r"^>\s*(.+)$",
|
|
line,
|
|
RegexCompileFlags::DEFAULT,
|
|
RegexMatchFlags::DEFAULT,
|
|
);
|
|
|
|
// Detect value
|
|
let value = regex.get(1)?;
|
|
|
|
if value.trim().is_empty() {
|
|
return None;
|
|
}
|
|
|
|
// Result
|
|
Some(Self {
|
|
value: GString::from(value.as_str()),
|
|
})
|
|
}
|
|
}
|