From 9d5b09ab38e36d993627a6fd3de3e07b7bcdd5ad Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 30 Jun 2021 16:56:46 -0400 Subject: Move local URI utility functions --- src/node.c | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/node.c') diff --git a/src/node.c b/src/node.c index 5629565a..3b125d66 100644 --- a/src/node.c +++ b/src/node.c @@ -39,6 +39,34 @@ # endif #endif +static size_t +serd_uri_string_length(const SerdURI* const uri) +{ + size_t len = uri->path_base.len; + +#define ADD_LEN(field, n_delims) \ + if ((field).len) { \ + len += (field).len + (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 len, void* const stream) +{ + uint8_t** ptr = (uint8_t**)stream; + memcpy(*ptr, buf, len); + *ptr += len; + return len; +} + SerdNode serd_node_from_string(const SerdType type, const uint8_t* const str) { @@ -94,34 +122,6 @@ serd_node_equals(const SerdNode* const a, const SerdNode* const b) !memcmp((const char*)a->buf, (const char*)b->buf, a->n_bytes + 1))); } -static size_t -serd_uri_string_length(const SerdURI* const uri) -{ - size_t len = uri->path_base.len; - -#define ADD_LEN(field, n_delims) \ - if ((field).len) { \ - len += (field).len + (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 len, void* const stream) -{ - uint8_t** ptr = (uint8_t**)stream; - memcpy(*ptr, buf, len); - *ptr += len; - return len; -} - SerdNode serd_node_new_uri_from_node(const SerdNode* const uri_node, const SerdURI* const base, -- cgit v1.2.1