Skip to content

Commit 83ec663

Browse files
author
yggverse
committed
skip regex operations on tag mismatch subject
1 parent 7345400 commit 83ec663

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/line/code.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ pub mod multiline;
33

44
pub use inline::Inline;
55
pub use multiline::Multiline;
6+
7+
pub const TAG: &str = "```";

src/line/code/inline.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::TAG;
12
use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
23

34
/// Inline [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
@@ -10,6 +11,12 @@ impl Inline {
1011

1112
/// Parse `Self` from line string
1213
pub fn from(line: &str) -> Option<Self> {
14+
// Skip next operations on prefix and postfix mismatch `TAG`
15+
// * replace regex implementation @TODO
16+
if !line.starts_with(TAG) && !line.ends_with(TAG) {
17+
return None;
18+
}
19+
1320
// Parse line
1421
let regex = Regex::split_simple(
1522
r"^`{3}([^`]+)`{3}$",

src/line/code/multiline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use super::TAG;
2+
13
pub mod error;
24
pub use error::Error;
35

46
// Shared defaults
57

68
pub const NEW_LINE: char = '\n';
7-
pub const TAG: &str = "```";
89

910
/// Multi-line [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
1011
pub struct Multiline {

src/line/link.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use glib::{DateTime, Regex, RegexCompileFlags, RegexMatchFlags, TimeZone, Uri, UriFlags};
22

3+
pub const TAG: &str = "=>";
4+
35
/// [Link](https://geminiprotocol.net/docs/gemtext-specification.gmi#link-lines) entity holder
46
pub struct Link {
57
pub alt: Option<String>, // [optional] alternative link description
@@ -12,6 +14,11 @@ impl Link {
1214

1315
/// Parse `Self` from line string
1416
pub fn from(line: &str, base: Option<&Uri>, timezone: Option<&TimeZone>) -> Option<Self> {
17+
// Skip next operations on prefix mismatch
18+
// * replace regex implementation @TODO
19+
if !line.starts_with(TAG) {
20+
return None;
21+
}
1522
// Define initial values
1623
let mut alt = None;
1724
let mut timestamp = None;

0 commit comments

Comments
 (0)