diff options
author | David Robillard <d@drobilla.net> | 2018-09-30 17:31:10 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-12-31 11:37:48 -0500 |
commit | dcf231a70418c978bd827eceb1e7714c9eac8357 (patch) | |
tree | fcbba4ea8c77b6701d703bb5c00086613e56b3b8 /src | |
parent | 8e5dbd1d5b62f66888dbf74929240da0b7ab465b (diff) | |
download | serd-dcf231a70418c978bd827eceb1e7714c9eac8357.tar.gz serd-dcf231a70418c978bd827eceb1e7714c9eac8357.tar.bz2 serd-dcf231a70418c978bd827eceb1e7714c9eac8357.zip |
Add serd_env_copy() and serd_env_equals()
Diffstat (limited to 'src')
-rw-r--r-- | src/env.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -48,6 +48,22 @@ serd_env_new(const SerdNode* base_uri) return env; } +SerdEnv* +serd_env_copy(const SerdEnv* env) +{ + 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_env_get_base_uri(env)); + return copy; +} + void serd_env_free(SerdEnv* env) { @@ -60,6 +76,26 @@ serd_env_free(SerdEnv* env) free(env); } +bool +serd_env_equals(const SerdEnv* a, const SerdEnv* b) +{ + if (!a || !b) { + return !a == !b; + } else 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; +} + const SerdURI* serd_env_get_parsed_base_uri(const SerdEnv* env) { |