aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-09-30 17:31:10 +0200
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:05 -0500
commitab89a23a350016ba6633d4584584f23767977fb4 (patch)
treef527628774b1d76ac2a49301949e2b3d153544aa /src
parentab699377c12033a5b4d562b37f4a56fbe4505a21 (diff)
downloadserd-ab89a23a350016ba6633d4584584f23767977fb4.tar.gz
serd-ab89a23a350016ba6633d4584584f23767977fb4.tar.bz2
serd-ab89a23a350016ba6633d4584584f23767977fb4.zip
Add serd_env_copy() and serd_env_equals()
Diffstat (limited to 'src')
-rw-r--r--src/env.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/env.c b/src/env.c
index 6ff8e3f5..29df5286 100644
--- a/src/env.c
+++ b/src/env.c
@@ -48,6 +48,26 @@ serd_env_new(const SerdStringView base_uri)
return env;
}
+SerdEnv*
+serd_env_copy(const SerdEnv* env)
+{
+ if (!env) {
+ return NULL;
+ }
+
+ SerdEnv* copy = (SerdEnv*)calloc(1, sizeof(struct SerdEnvImpl));
+
+ copy->n_prefixes = env->n_prefixes;
+ copy->prefixes = (SerdPrefix*)malloc(copy->n_prefixes * sizeof(SerdPrefix));
+ for (size_t i = 0; i < copy->n_prefixes; ++i) {
+ copy->prefixes[i].name = serd_node_copy(env->prefixes[i].name);
+ copy->prefixes[i].uri = serd_node_copy(env->prefixes[i].uri);
+ }
+
+ serd_env_set_base_uri(copy, serd_node_string_view(serd_env_base_uri(env)));
+ return copy;
+}
+
void
serd_env_free(SerdEnv* env)
{
@@ -64,6 +84,28 @@ serd_env_free(SerdEnv* env)
free(env);
}
+bool
+serd_env_equals(const SerdEnv* a, const SerdEnv* b)
+{
+ if (!a || !b) {
+ return !a == !b;
+ }
+
+ if (a->n_prefixes != b->n_prefixes ||
+ !serd_node_equals(a->base_uri_node, b->base_uri_node)) {
+ return false;
+ }
+
+ for (size_t i = 0; i < a->n_prefixes; ++i) {
+ if (!serd_node_equals(a->prefixes[i].name, b->prefixes[i].name) ||
+ !serd_node_equals(a->prefixes[i].uri, b->prefixes[i].uri)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
SerdURIView
serd_env_base_uri_view(const SerdEnv* env)
{