From a63a8f19c54dfee75e092819d6622b8d36fe1d39 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 22 Jul 2021 23:39:39 -0400 Subject: Expose low-level node construction API --- src/env.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/env.c') diff --git a/src/env.c b/src/env.c index d4ae1937..434d1a3b 100644 --- a/src/env.c +++ b/src/env.c @@ -258,7 +258,7 @@ serd_env_expand_in_place(const SerdEnv* const env, return SERD_ERR_BAD_CURIE; } - uri_prefix->buf = serd_node_string(prefix->uri); + uri_prefix->buf = prefix->uri ? 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; @@ -279,20 +279,24 @@ serd_env_expand_curie(const SerdEnv* const env, const SerdStringView curie) return NULL; } - const size_t len = prefix.len + suffix.len; - SerdNode* const ret = serd_node_malloc(len, 0u, SERD_URI); - if (!ret) { - return NULL; - } + const size_t len = prefix.len + suffix.len; - char* const string = serd_node_buffer(ret); - assert(string); - assert(prefix.buf); + const size_t real_length = serd_node_pad_length(len); + const size_t node_size = sizeof(SerdNode) + real_length; + SerdNode* node = serd_node_malloc(node_size); - memcpy(string, prefix.buf, prefix.len); - memcpy(string + prefix.len, suffix.buf, suffix.len); + if (node) { + node->length = len; + node->flags = 0u; + node->type = SERD_URI; + + char* const string = (char*)(node + 1u); + assert(prefix.buf); + memcpy(string, prefix.buf, prefix.len); + memcpy(string + prefix.len, suffix.buf, suffix.len); + } - return ret; + return node; } SerdNode* -- cgit v1.2.1