aboutsummaryrefslogtreecommitdiffstats
path: root/src/env.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-05-05 09:43:57 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit4711fdf527f416faee8ff19e15f050d4b48dcfb2 (patch)
tree6b18712ec44cce5713ddef1a21aec5f12651d901 /src/env.c
parent248a874d7425749d29cf900a1c3783c624ea8d8c (diff)
downloadserd-4711fdf527f416faee8ff19e15f050d4b48dcfb2.tar.gz
serd-4711fdf527f416faee8ff19e15f050d4b48dcfb2.tar.bz2
serd-4711fdf527f416faee8ff19e15f050d4b48dcfb2.zip
[WIP] Generalize node construction API
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/env.c b/src/env.c
index 90924cd2..dcffb98e 100644
--- a/src/env.c
+++ b/src/env.c
@@ -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