aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-02-28 14:24:24 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commitb7cce4a24dbc544129a9fabc44cb22025767f10b (patch)
treef085e200dc7b4b8a67ffebc191e752d0be366d53 /src/node.c
parent154e33ef21d175bb97263a8318dc0cc461a64321 (diff)
downloadserd-b7cce4a24dbc544129a9fabc44cb22025767f10b.tar.gz
serd-b7cce4a24dbc544129a9fabc44cb22025767f10b.tar.bz2
serd-b7cce4a24dbc544129a9fabc44cb22025767f10b.zip
Make serd_uri_string_length() precise and add it to public API
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/src/node.c b/src/node.c
index 61d863a8..a5e2a7fa 100644
--- a/src/node.c
+++ b/src/node.c
@@ -52,25 +52,6 @@ static SerdNode*
serd_new_from_uri(SerdURIView uri, SerdURIView base);
static size_t
-serd_uri_string_length(const SerdURIView* const uri)
-{
- size_t len = uri->path_prefix.length;
-
-#define ADD_LEN(field, n_delims) \
- if ((field).length) { \
- len += (field).length + (n_delims); \
- }
-
- ADD_LEN(uri->path, 1) // + possible leading '/'
- ADD_LEN(uri->scheme, 1) // + trailing ':'
- ADD_LEN(uri->authority, 2) // + leading '//'
- ADD_LEN(uri->query, 1) // + leading '?'
- ADD_LEN(uri->fragment, 1) // + leading '#'
-
- return len + 2; // + 2 for authority '//'
-}
-
-static size_t
string_sink(const void* const buf,
const size_t size,
const size_t nmemb,
@@ -492,11 +473,13 @@ serd_new_uri(const SerdStringView string)
SerdNode*
serd_new_parsed_uri(const SerdURIView uri)
{
- const size_t len = serd_uri_string_length(&uri);
+ const size_t len = serd_uri_string_length(uri);
SerdNode* const node = serd_node_malloc(len, 0, SERD_URI);
char* ptr = serd_node_buffer(node);
const size_t actual_len = serd_write_uri(uri, string_sink, &ptr);
+ assert(actual_len == len);
+
serd_node_buffer(node)[actual_len] = '\0';
node->length = actual_len;
@@ -508,11 +491,13 @@ 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);
+ 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;