diff options
author | David Robillard <d@drobilla.net> | 2021-07-22 19:51:49 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-14 19:37:51 -0500 |
commit | 64e81dfd6ec04995fd396269deb6b32fe2d1192d (patch) | |
tree | 61d7414edf008afb4d002813265787dad27ff2c4 /src | |
parent | 4584e03fce0d702160f8fde910bb3f24647d4036 (diff) | |
download | serd-64e81dfd6ec04995fd396269deb6b32fe2d1192d.tar.gz serd-64e81dfd6ec04995fd396269deb6b32fe2d1192d.tar.bz2 serd-64e81dfd6ec04995fd396269deb6b32fe2d1192d.zip |
Remove serd_new_resolved_uri()
Diffstat (limited to 'src')
-rw-r--r-- | src/env.c | 72 | ||||
-rw-r--r-- | src/node.c | 36 | ||||
-rw-r--r-- | src/node.h | 4 |
3 files changed, 36 insertions, 76 deletions
@@ -199,10 +199,16 @@ serd_env_set_prefix(SerdEnv* const env, return SERD_ERR_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.buf); + const SerdURIView abs_uri_view = serd_resolve_uri(uri_view, env->base_uri); + assert(abs_uri_view.scheme.len); - // Set prefix to resolved (absolute) URI + // Serialise absolute URI to a new node + 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)); serd_node_free(abs_uri); return SERD_SUCCESS; @@ -248,22 +254,15 @@ serd_env_expand_in_place(const SerdEnv* const env, const size_t name_len = (size_t)(colon - str); const SerdPrefix* const prefix = serd_env_find(env, str, name_len); - if (prefix) { - uri_prefix->buf = serd_node_string(prefix->uri); - uri_prefix->len = prefix->uri ? prefix->uri->length : 0; - uri_suffix->buf = colon + 1; - uri_suffix->len = curie.len - name_len - 1; - return SERD_SUCCESS; + if (!prefix || !prefix->uri) { + return SERD_ERR_BAD_CURIE; } - return SERD_ERR_BAD_CURIE; -} -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); + uri_prefix->buf = serd_node_string(prefix->uri); + uri_prefix->len = prefix->uri ? prefix->uri->length : 0; + uri_suffix->buf = colon + 1; + uri_suffix->len = curie.len - name_len - 1; + return SERD_SUCCESS; } SerdNode* @@ -273,39 +272,40 @@ serd_env_expand_curie(const SerdEnv* const env, const SerdStringView curie) return NULL; } - SerdStringView prefix; - SerdStringView suffix; - if (serd_env_expand_in_place(env, curie, &prefix, &suffix)) { + SerdStringView prefix = SERD_EMPTY_STRING(); + SerdStringView suffix = SERD_EMPTY_STRING(); + SerdStatus st = serd_env_expand_in_place(env, curie, &prefix, &suffix); + if (st || !prefix.buf || !suffix.buf) { return NULL; } - const size_t len = prefix.len + suffix.len; - SerdNode* ret = serd_node_malloc(len, 0, SERD_URI); - char* buf = serd_node_buffer(ret); + const size_t len = prefix.len + suffix.len; + SerdNode* const ret = serd_node_malloc(len, 0u, SERD_URI); + if (!ret) { + return NULL; + } + + char* const string = serd_node_buffer(ret); + assert(string); + assert(prefix.buf); + + memcpy(string, prefix.buf, prefix.len); + memcpy(string + prefix.len, suffix.buf, suffix.len); - snprintf(buf, len + 1, "%s%s", prefix.buf, suffix.buf); - ret->length = len; return ret; } 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.len ? serd_new_parsed_uri(abs_uri) : NULL; } void @@ -38,9 +38,6 @@ typedef struct { 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, @@ -479,39 +476,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.buf); - 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) { @@ -71,10 +71,6 @@ serd_node_total_size(const SerdNode* SERD_NULLABLE node); void serd_node_zero_pad(SerdNode* SERD_NONNULL node); -/// Create a new URI from a string, resolved against a base URI -SerdNode* SERD_ALLOCATED -serd_new_resolved_uri(SerdStringView string, SerdURIView base_uri); - ExessResult serd_node_get_value_as(const SerdNode* SERD_NONNULL node, ExessDatatype value_type, |