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 } }