This commit is contained in:
Alex Wied
2026-07-13 14:05:40 -04:00
parent 54f417c96d
commit fc970084d7
12 changed files with 253 additions and 218 deletions
+30
View File
@@ -0,0 +1,30 @@
use std::collections::BTreeMap;
#[derive(Clone)]
pub struct CurieHelper {
prefixes: BTreeMap<String, String>,
}
impl CurieHelper {
pub fn new(prefixes: BTreeMap<String, String>) -> Self {
Self {
prefixes,
}
}
pub fn abbreviate(&self, iri: &str) -> Option<String> {
for (name, base) in &self.prefixes {
if let Some(local_name) = iri.strip_prefix(base) {
return Some(format!("{name}:{local_name}"));
}
}
None
}
pub fn expand(&self, abbreviated_iri: &str) -> Option<String> {
let (prefix, name) = abbreviated_iri.split_once(':')?;
self.prefixes
.get(prefix)
.map(|base| format!("{base}{name}"))
}
}