This commit is contained in:
2026-07-24 19:25:07 -04:00
parent 54253a049f
commit 2618fe0d72
5 changed files with 68 additions and 26 deletions
+14 -5
View File
@@ -12,7 +12,11 @@ impl CurieHelper {
}
}
pub fn abbreviate(&self, iri: &str) -> Option<String> {
pub fn abbreviate(&self, base: Option<&str>, iri: &str) -> Option<String> {
if let Some(base) = base && let Some(local_name) = iri.strip_prefix(base) {
return Some(format!(":{local_name}"));
}
for (name, base) in &self.prefixes {
if let Some(local_name) = iri.strip_prefix(base) {
return Some(format!("{name}:{local_name}"));
@@ -21,10 +25,15 @@ impl CurieHelper {
None
}
pub fn expand(&self, abbreviated_iri: &str) -> Option<String> {
pub fn expand(&self, base: Option<&str>, abbreviated_iri: &str) -> Option<String> {
let (prefix, name) = abbreviated_iri.split_once(':')?;
self.prefixes
.get(prefix)
.map(|base| format!("{base}{name}"))
if prefix == "" && let Some(base) = base {
Some(format!("{base}{name}"))
} else {
self.prefixes
.get(prefix)
.map(|base| format!("{base}{name}"))
}
}
}