From c5c0fcf6d46f03f741d5f377244fb638a6ae651f Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 12 Jun 2024 13:40:15 +0200 Subject: [PATCH] feat: add function to resolve database id --- src/lkrexport.rs | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/lkrexport.rs b/src/lkrexport.rs index e01ea6a..ad187d4 100644 --- a/src/lkrexport.rs +++ b/src/lkrexport.rs @@ -105,28 +105,31 @@ impl Meldung { None } + #[allow(unused)] pub fn database_id(&self) -> Option { - return match self.id() { - Some(id) => { - let re1 = Regex::new(r"^(?[0-9A-F]+)").unwrap(); - let re2 = Regex::new(r"(?[0-9]+)$").unwrap(); - - if re1.is_match(&id) { - match re1.find(&id).map(|m| m.as_str().to_string()) { - Some(val) => match u64::from_str_radix(&val, 16) { - Ok(val) => Some(val.to_string()), - _ => None, - }, - _ => None, - } - } else if re2.is_match(&id) { - re2.find(&id).map(|m| m.as_str().to_string()) - } else { - None - } - } + match self.id() { + Some(id) => to_database_id(&id), _ => None, - }; + } + } +} + +pub fn to_database_id(id: &str) -> Option { + let re1 = Regex::new(r"^(?[0-9A-F]+)").unwrap(); + let re2 = Regex::new(r"(?[0-9]+)$").unwrap(); + + if re1.is_match(id) { + match re1.find(id).map(|m| m.as_str().to_string()) { + Some(val) => match u64::from_str_radix(&val, 16) { + Ok(val) => Some(val.to_string()), + _ => None, + }, + _ => None, + } + } else if re2.is_match(id) { + re2.find(id).map(|m| m.as_str().to_string()) + } else { + None } }