diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/env.c | 33 | ||||
-rw-r--r-- | src/node.c | 36 | ||||
-rw-r--r-- | src/node.h | 6 |
3 files changed, 12 insertions, 63 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 @@ -46,9 +46,6 @@ DEFINE_XSD_NODE(integer) static const SerdNodeFlags meta_mask = (SERD_HAS_DATATYPE | SERD_HAS_LANGUAGE); -static SerdNode* -serd_new_from_uri(SerdURIView uri, SerdURIView base); - static size_t string_sink(const void* const buf, const size_t size, @@ -491,39 +488,6 @@ serd_new_parsed_uri(const SerdURIView uri) return node; } -static SerdNode* -serd_new_from_uri(const SerdURIView uri, const SerdURIView base) -{ - const SerdURIView abs_uri = serd_resolve_uri(uri, base); - const size_t len = serd_uri_string_length(abs_uri); - SerdNode* node = serd_node_malloc(len, 0, SERD_URI); - char* ptr = serd_node_buffer(node); - const size_t actual_len = serd_write_uri(abs_uri, string_sink, &ptr); - - assert(actual_len == len); - - serd_node_buffer(node)[actual_len] = '\0'; - node->length = actual_len; - - serd_node_check_padding(node); - return node; -} - -SerdNode* -serd_new_resolved_uri(const SerdStringView string, const SerdURIView base) -{ - const SerdURIView uri = serd_parse_uri(string.data); - SerdNode* const result = serd_new_from_uri(uri, base); - - if (!serd_uri_string_has_scheme(serd_node_string(result))) { - serd_node_free(result); - return NULL; - } - - serd_node_check_padding(result); - return result; -} - SerdNode* serd_new_file_uri(const SerdStringView path, const SerdStringView hostname) { @@ -6,8 +6,6 @@ #include "exess/exess.h" #include "serd/node.h" -#include "serd/string_view.h" -#include "serd/uri.h" #include "zix/attributes.h" #include <stdbool.h> @@ -60,10 +58,6 @@ serd_node_total_size(const SerdNode* ZIX_NULLABLE node); void serd_node_zero_pad(SerdNode* ZIX_NONNULL node); -/// Create a new URI from a string, resolved against a base URI -SerdNode* ZIX_ALLOCATED -serd_new_resolved_uri(SerdStringView string, SerdURIView base_uri); - ExessResult serd_node_get_value_as(const SerdNode* ZIX_NONNULL node, ExessDatatype value_type, |