.
This commit is contained in:
@@ -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}"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user