mirror of
https://github.com/pcvolkmer/bzkf-rwdp-check.git
synced 2025-04-19 19:16:51 +00:00
feat: add function to resolve database id
This commit is contained in:
parent
ac2f73d0bb
commit
c5c0fcf6d4
@ -105,29 +105,32 @@ impl Meldung {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub fn database_id(&self) -> Option<String> {
|
pub fn database_id(&self) -> Option<String> {
|
||||||
return match self.id() {
|
match self.id() {
|
||||||
Some(id) => {
|
Some(id) => to_database_id(&id),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_database_id(id: &str) -> Option<String> {
|
||||||
let re1 = Regex::new(r"^(?<id>[0-9A-F]+)").unwrap();
|
let re1 = Regex::new(r"^(?<id>[0-9A-F]+)").unwrap();
|
||||||
let re2 = Regex::new(r"(?<id>[0-9]+)$").unwrap();
|
let re2 = Regex::new(r"(?<id>[0-9]+)$").unwrap();
|
||||||
|
|
||||||
if re1.is_match(&id) {
|
if re1.is_match(id) {
|
||||||
match re1.find(&id).map(|m| m.as_str().to_string()) {
|
match re1.find(id).map(|m| m.as_str().to_string()) {
|
||||||
Some(val) => match u64::from_str_radix(&val, 16) {
|
Some(val) => match u64::from_str_radix(&val, 16) {
|
||||||
Ok(val) => Some(val.to_string()),
|
Ok(val) => Some(val.to_string()),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
} else if re2.is_match(&id) {
|
} else if re2.is_match(id) {
|
||||||
re2.find(&id).map(|m| m.as_str().to_string())
|
re2.find(id).map(|m| m.as_str().to_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user