diff options
author | David Robillard <d@drobilla.net> | 2018-05-11 18:11:44 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-06-21 18:12:03 +0200 |
commit | 252d923fae3face245c4a8a513f20781560a9455 (patch) | |
tree | 072c0a485aa67e7dbf679e859df7331f9f3107f8 /src/env.c | |
parent | 35e2548835cd9fca003347e092de9f36d545a76a (diff) | |
download | serd-252d923fae3face245c4a8a513f20781560a9455.tar.gz serd-252d923fae3face245c4a8a513f20781560a9455.tar.bz2 serd-252d923fae3face245c4a8a513f20781560a9455.zip |
Clean up node construction API
Diffstat (limited to 'src/env.c')
-rw-r--r-- | src/env.c | 42 |
1 files changed, 23 insertions, 19 deletions
@@ -14,6 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "env.h" + #include "node.h" #include "serd/serd.h" @@ -57,13 +59,15 @@ serd_env_free(SerdEnv* env) free(env); } +const SerdURI* +serd_env_get_parsed_base_uri(const SerdEnv* env) +{ + return &env->base_uri; +} + const SerdNode* -serd_env_get_base_uri(const SerdEnv* env, - SerdURI* out) +serd_env_get_base_uri(const SerdEnv* env) { - if (out) { - *out = env->base_uri; - } return env->base_uri_node; } @@ -71,14 +75,16 @@ SerdStatus serd_env_set_base_uri(SerdEnv* env, const SerdNode* uri) { - if (!env || !uri) { + if (!env || !uri || uri->type != SERD_URI) { return SERD_ERR_BAD_ARG; } // Resolve base URI and create a new node and URI for it + SerdNode* base_uri_node = serd_node_new_resolved_uri_i( + serd_node_get_string(uri), &env->base_uri); + SerdURI base_uri; - SerdNode* base_uri_node = serd_node_new_uri_from_node( - uri, &env->base_uri, &base_uri); + serd_uri_parse(serd_node_get_string(base_uri_node), &base_uri); if (base_uri_node) { // Replace the current base URI @@ -137,13 +143,12 @@ serd_env_set_prefix(SerdEnv* env, serd_env_add(env, name, uri); } else { // Resolve relative URI and create a new node and URI for it - SerdURI abs_uri; - SerdNode* abs_uri_node = serd_node_new_uri_from_node( - uri, &env->base_uri, &abs_uri); + SerdNode* abs_uri = serd_node_new_resolved_uri_i( + serd_node_get_string(uri), &env->base_uri); // Set prefix to resolved (absolute) URI - serd_env_add(env, name, abs_uri_node); - serd_node_free(abs_uri_node); + serd_env_add(env, name, abs_uri); + serd_node_free(abs_uri); } return SERD_SUCCESS; } @@ -153,8 +158,8 @@ serd_env_set_prefix_from_strings(SerdEnv* env, const char* name, const char* uri) { - SerdNode* name_node = serd_node_new_string(SERD_LITERAL, name); - SerdNode* uri_node = serd_node_new_string(SERD_URI, uri); + SerdNode* name_node = serd_node_new_string(name); + SerdNode* uri_node = serd_node_new_uri(uri); const SerdStatus st = serd_env_set_prefix(env, name_node, uri_node); @@ -228,10 +233,9 @@ serd_env_expand_node(const SerdEnv* env, ret->n_bytes = len; return ret; } - case SERD_URI: { - SerdURI ignored; - return serd_node_new_uri_from_node(node, &env->base_uri, &ignored); - } + case SERD_URI: + return serd_node_new_resolved_uri_i( + serd_node_get_string(node), &env->base_uri); default: return NULL; } |