diff options
Diffstat (limited to 'src/env.c')
-rw-r--r-- | src/env.c | 37 |
1 files changed, 24 insertions, 13 deletions
@@ -159,7 +159,7 @@ serd_env_set_base_uri(SerdEnv* const env, const SerdStringView uri) // Replace the current base URI if ((env->base_uri_node = - serd_new_parsed_uri(env->allocator, new_base_uri))) { + serd_node_new(env->allocator, serd_a_parsed_uri(new_base_uri)))) { env->base_uri = serd_node_uri_view(env->base_uri_node); } else { return SERD_BAD_ALLOC; @@ -209,7 +209,7 @@ serd_env_add(SerdEnv* const env, if (prefix) { if (!!strcmp(serd_node_string(prefix->uri), uri.data)) { serd_node_free(env->allocator, prefix->uri); - prefix->uri = serd_new_uri(env->allocator, uri); + prefix->uri = serd_node_new(env->allocator, serd_a_uri(uri)); } } else { SerdPrefix* const new_prefixes = @@ -222,8 +222,9 @@ serd_env_add(SerdEnv* const env, env->prefixes = new_prefixes; - SerdNode* const name_node = serd_new_string(env->allocator, name); - SerdNode* const uri_node = serd_new_uri(env->allocator, uri); + SerdNode* const name_node = + serd_node_new(env->allocator, serd_a_string_view(name)); + SerdNode* const uri_node = serd_node_new(env->allocator, serd_a_uri(uri)); if (!name_node || !uri_node) { serd_node_free(env->allocator, uri_node); serd_node_free(env->allocator, name_node); @@ -260,7 +261,8 @@ serd_env_set_prefix(SerdEnv* const env, assert(abs_uri_view.scheme.length); // Create a new node for the absolute URI - SerdNode* const abs_uri = serd_new_parsed_uri(env->allocator, abs_uri_view); + SerdNode* const abs_uri = + serd_node_new(env->allocator, serd_a_parsed_uri(abs_uri_view)); if (!abs_uri) { return SERD_BAD_ALLOC; } @@ -317,7 +319,7 @@ serd_env_expand_in_place(const SerdEnv* const env, return SERD_BAD_CURIE; } - uri_prefix->data = serd_node_string(prefix->uri); + uri_prefix->data = prefix->uri ? serd_node_string(prefix->uri) : ""; uri_prefix->length = prefix->uri ? prefix->uri->length : 0; uri_suffix->data = colon + 1; uri_suffix->length = curie.length - name_len - 1; @@ -338,15 +340,23 @@ serd_env_expand_curie(const SerdEnv* const env, const SerdStringView curie) return NULL; } - const size_t len = prefix.length + suffix.length; - SerdNode* const ret = serd_node_malloc(env->allocator, len, 0U, SERD_URI); - if (ret) { - char* const string = serd_node_buffer(ret); + const size_t len = prefix.length + suffix.length; + const size_t real_length = serd_node_pad_length(len); + const size_t node_size = sizeof(SerdNode) + real_length; + SerdNode* node = serd_node_malloc(env->allocator, node_size); + + if (node) { + node->length = len; + node->flags = 0U; + node->type = SERD_URI; + + char* const string = (char*)(node + 1U); + assert(prefix.data); memcpy(string, prefix.data, prefix.length); memcpy(string + prefix.length, suffix.data, suffix.length); } - return ret; + return node; } SerdNode* @@ -359,8 +369,9 @@ serd_env_expand_node(const SerdEnv* const env, const SerdNode* const node) const SerdURIView uri = serd_node_uri_view(node); const SerdURIView abs_uri = serd_resolve_uri(uri, env->base_uri); - return abs_uri.scheme.length ? serd_new_parsed_uri(env->allocator, abs_uri) - : NULL; + return abs_uri.scheme.length + ? serd_node_new(env->allocator, serd_a_parsed_uri(abs_uri)) + : NULL; } SerdStatus |