skip regex operations on tag mismatch subject

This commit is contained in:
yggverse 2025-03-16 19:53:29 +02:00
parent 7345400172
commit 83ec663929
4 changed files with 18 additions and 1 deletions

View file

@ -3,3 +3,5 @@ pub mod multiline;
pub use inline::Inline;
pub use multiline::Multiline;
pub const TAG: &str = "```";

View file

@ -1,3 +1,4 @@
use super::TAG;
use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
/// Inline [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
@ -10,6 +11,12 @@ impl Inline {
/// Parse `Self` from line string
pub fn from(line: &str) -> Option<Self> {
// Skip next operations on prefix and postfix mismatch `TAG`
// * replace regex implementation @TODO
if !line.starts_with(TAG) && !line.ends_with(TAG) {
return None;
}
// Parse line
let regex = Regex::split_simple(
r"^`{3}([^`]+)`{3}$",

View file

@ -1,10 +1,11 @@
use super::TAG;
pub mod error;
pub use error::Error;
// Shared defaults
pub const NEW_LINE: char = '\n';
pub const TAG: &str = "```";
/// Multi-line [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
pub struct Multiline {

View file

@ -1,5 +1,7 @@
use glib::{DateTime, Regex, RegexCompileFlags, RegexMatchFlags, TimeZone, Uri, UriFlags};
pub const TAG: &str = "=>";
/// [Link](https://geminiprotocol.net/docs/gemtext-specification.gmi#link-lines) entity holder
pub struct Link {
pub alt: Option<String>, // [optional] alternative link description
@ -12,6 +14,11 @@ impl Link {
/// Parse `Self` from line string
pub fn from(line: &str, base: Option<&Uri>, timezone: Option<&TimeZone>) -> Option<Self> {
// Skip next operations on prefix mismatch
// * replace regex implementation @TODO
if !line.starts_with(TAG) {
return None;
}
// Define initial values
let mut alt = None;
let mut timestamp = None;