diff options
Diffstat (limited to 'src/env.c')
-rw-r--r-- | src/env.c | 33 |
1 files changed, 12 insertions, 21 deletions
@@ -209,8 +209,14 @@ serd_env_set_prefix(SerdEnv* const env, return SERD_BAD_ARG; } - // Resolve relative URI and create a new node and URI for it - SerdNode* const abs_uri = serd_new_resolved_uri(uri, env->base_uri); + // Resolve potentially relative URI reference to an absolute URI + const SerdURIView uri_view = serd_parse_uri(uri.data); + const SerdURIView abs_uri_view = serd_resolve_uri(uri_view, env->base_uri); + assert(abs_uri_view.scheme.length); + + // Create a new node for the absolute URI + SerdNode* const abs_uri = serd_new_parsed_uri(abs_uri_view); + assert(serd_uri_string_has_scheme(serd_node_string(abs_uri))); // Set prefix to resolved (absolute) URI serd_env_add(env, name, serd_node_string_view(abs_uri)); @@ -269,14 +275,6 @@ serd_env_expand_in_place(const SerdEnv* const env, return SERD_SUCCESS; } -static SerdNode* -expand_uri(const SerdEnv* env, const SerdNode* node) -{ - assert(serd_node_type(node) == SERD_URI); - - return serd_new_resolved_uri(serd_node_string_view(node), env->base_uri); -} - SerdNode* serd_env_expand_curie(const SerdEnv* const env, const SerdStringView curie) { @@ -305,21 +303,14 @@ serd_env_expand_curie(const SerdEnv* const env, const SerdStringView curie) SerdNode* serd_env_expand_node(const SerdEnv* const env, const SerdNode* const node) { - if (!env || !node) { + if (!env || !node || node->type != SERD_URI) { return NULL; } - switch (node->type) { - case SERD_LITERAL: - break; - case SERD_URI: - return expand_uri(env, node); - case SERD_BLANK: - case SERD_VARIABLE: - break; - } + const SerdURIView uri = serd_node_uri_view(node); + const SerdURIView abs_uri = serd_resolve_uri(uri, env->base_uri); - return NULL; + return abs_uri.scheme.length ? serd_new_parsed_uri(abs_uri) : NULL; } SerdStatus |