diff options
author | David Robillard <d@drobilla.net> | 2021-02-28 14:24:24 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:06 -0500 |
commit | d9ea0564d0954967788b688a224cf81f7892c4a7 (patch) | |
tree | d43e38888e5dd14d0439f76ea57017bf6e954be9 /src/uri.c | |
parent | 8f1192bb2361fcd7907b926e86c41a171ed04ad0 (diff) | |
download | serd-d9ea0564d0954967788b688a224cf81f7892c4a7.tar.gz serd-d9ea0564d0954967788b688a224cf81f7892c4a7.tar.bz2 serd-d9ea0564d0954967788b688a224cf81f7892c4a7.zip |
Make serd_uri_string_length() precise and add it to public API
Diffstat (limited to 'src/uri.c')
-rw-r--r-- | src/uri.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -410,6 +410,44 @@ serd_uri_is_within(const SerdURIView uri, const SerdURIView base) return true; } +size_t +serd_uri_string_length(const SerdURIView uri) +{ + size_t len = 0; + + if (uri.scheme.buf) { + len += uri.scheme.len + 1; + } + + if (uri.authority.buf) { + const bool needs_extra_slash = + (uri.authority.len > 0 && uri_path_len(&uri) > 0 && + uri_path_at(&uri, 0) != '/'); + + len += 2 + uri.authority.len + needs_extra_slash; + } + + if (uri.path_prefix.buf) { + len += uri.path_prefix.len; + } else if (uri.path_prefix.len) { + len += 3 * uri.path_prefix.len; + } + + if (uri.path.buf) { + len += uri.path.len; + } + + if (uri.query.buf) { + len += uri.query.len + 1; + } + + if (uri.fragment.buf) { + len += uri.fragment.len; + } + + return len; +} + /// See http://tools.ietf.org/html/rfc3986#section-5.3 size_t serd_write_uri(const SerdURIView uri, SerdWriteFunc sink, void* stream) |