aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-12-20 09:47:26 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit530edb265fbbed20e6d3a6fd7a36461ff83d9b46 (patch)
tree0f67206d7631bcff366c02cbedcd7f20b405dcb7 /src
parent0f9816d67bc67a396607291f845ca2a33c2285a7 (diff)
downloadserd-530edb265fbbed20e6d3a6fd7a36461ff83d9b46.tar.gz
serd-530edb265fbbed20e6d3a6fd7a36461ff83d9b46.tar.bz2
serd-530edb265fbbed20e6d3a6fd7a36461ff83d9b46.zip
Add serd_env_unset_prefix()
Diffstat (limited to 'src')
-rw-r--r--src/env.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/env.c b/src/env.c
index a63f2126..0a1d0d5b 100644
--- a/src/env.c
+++ b/src/env.c
@@ -315,6 +315,43 @@ serd_env_set_prefix(SerdEnv* const env,
}
SerdStatus
+serd_env_unset_prefix(SerdEnv* const env, const ZixStringView name)
+{
+ // Find matching prefix
+ SerdPrefix* const prefix = serd_env_find(env, name.data, name.length);
+ if (!prefix) {
+ return SERD_SUCCESS;
+ }
+
+ // Drop prefix's URI node and clear if it's the only one
+ serd_nodes_deref(env->nodes, prefix->uri);
+ if (env->n_prefixes == 1U) {
+ zix_free(env->allocator, env->prefixes);
+ env->prefixes = NULL;
+ env->n_prefixes = 0U;
+ return SERD_SUCCESS;
+ }
+
+ // Replace the prefix entry with the last one (if applicable)
+ const size_t index = (size_t)(prefix - env->prefixes);
+ const size_t new_n_prefixes = env->n_prefixes - 1U;
+ if (index < new_n_prefixes) {
+ env->prefixes[index] = env->prefixes[new_n_prefixes];
+ }
+
+ // Shrink prefixes array
+ SerdPrefix* const new_prefixes = (SerdPrefix*)zix_realloc(
+ env->allocator, env->prefixes, new_n_prefixes * sizeof(SerdPrefix));
+
+ if (new_prefixes) {
+ env->prefixes = new_prefixes;
+ env->n_prefixes = new_n_prefixes;
+ }
+
+ return new_prefixes ? SERD_SUCCESS : SERD_BAD_ALLOC;
+}
+
+SerdStatus
serd_env_qualify(const SerdEnv* const env,
const ZixStringView uri,
ZixStringView* const prefix,