From a749f3455678848e97208dd13fa2dcf64e4e28e5 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Wed, 21 May 2025 11:57:36 +1200 Subject: Initial commit --- src/template.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/template.rs (limited to 'src/template.rs') diff --git a/src/template.rs b/src/template.rs new file mode 100644 index 0000000..67eaceb --- /dev/null +++ b/src/template.rs @@ -0,0 +1,25 @@ +use fancy_regex::*; + + +pub struct Template { + pub tag: String, + pub subtags: Vec, + pub expression: Regex, +} + +impl Template { + pub fn from_str(pattern: &str, tag: String) -> Self { + let pattern = format!("^(?:{pattern})"); + let expression = Regex::new(&pattern).unwrap(); + + if let Some((head, tail)) = tag.split_once('(') { + if let Some(tail) = tail.strip_suffix(')') { + let tag = head.trim().to_string(); + let subtags = tail.split(',').map(|t| t.trim().to_string()).collect(); + return Self { tag, subtags, expression }; + } + } + let subtags = Vec::new(); + return Self { tag, subtags, expression }; + } +} -- cgit v1.2.3-70-g09d2