aboutsummaryrefslogtreecommitdiffstats
path: root/src/uri.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/uri.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/uri.c')
-rw-r--r--src/uri.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/uri.c b/src/uri.c
index 0c0f3736..aed669c8 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -396,6 +396,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.data) {
+ len += uri.scheme.length + 1;
+ }
+
+ if (uri.authority.data) {
+ const bool needs_extra_slash =
+ (uri.authority.length > 0 && uri_path_len(&uri) > 0 &&
+ uri_path_at(&uri, 0) != '/');
+
+ len += 2 + uri.authority.length + needs_extra_slash;
+ }
+
+ if (uri.path_prefix.data) {
+ len += uri.path_prefix.length;
+ } else if (uri.path_prefix.length) {
+ len += 3 * uri.path_prefix.length;
+ }
+
+ if (uri.path.data) {
+ len += uri.path.length;
+ }
+
+ if (uri.query.data) {
+ len += uri.query.length + 1;
+ }
+
+ if (uri.fragment.data) {
+ len += uri.fragment.length;
+ }
+
+ return len;
+}
+
/// See http://tools.ietf.org/html/rfc3986#section-5.3
size_t
serd_write_uri(const SerdURIView uri,