aboutsummaryrefslogtreecommitdiffstats
path: root/src/uri_utils.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-02-20 16:47:55 -0500
committerDavid Robillard <d@drobilla.net>2021-03-07 15:32:24 -0500
commit941b14a0ab8f7c80f94e04762e65a48f9ed02f6e (patch)
treea7e89d7d2bb0150728c5eec3d4d9e6730f9af016 /src/uri_utils.h
parentd243368f8e2f79a125a5858223f71fb40fe84525 (diff)
downloadserd-941b14a0ab8f7c80f94e04762e65a48f9ed02f6e.tar.gz
serd-941b14a0ab8f7c80f94e04762e65a48f9ed02f6e.tar.bz2
serd-941b14a0ab8f7c80f94e04762e65a48f9ed02f6e.zip
Simplify URI API and implementation
Diffstat (limited to 'src/uri_utils.h')
-rw-r--r--src/uri_utils.h22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/uri_utils.h b/src/uri_utils.h
index 6b07ec48..fa1619d9 100644
--- a/src/uri_utils.h
+++ b/src/uri_utils.h
@@ -33,17 +33,14 @@ slice_equals(const SerdStringView* a, const SerdStringView* b)
static inline size_t
uri_path_len(const SerdURIView* uri)
{
- return uri->path_base.len + uri->path.len;
+ return uri->path_prefix.len + uri->path.len;
}
static inline char
uri_path_at(const SerdURIView* uri, size_t i)
{
- if (i < uri->path_base.len) {
- return uri->path_base.buf[i];
- }
-
- return uri->path.buf[i - uri->path_base.len];
+ return (i < uri->path_prefix.len) ? uri->path_prefix.buf[i]
+ : uri->path.buf[i - uri->path_prefix.len];
}
/**
@@ -60,10 +57,11 @@ uri_rooted_index(const SerdURIView* uri, const SerdURIView* root)
return 0;
}
- bool differ = false;
- const size_t path_len = uri_path_len(uri);
- const size_t root_len = uri_path_len(root);
- size_t last_root_slash = 0;
+ bool differ = false;
+ const size_t path_len = uri_path_len(uri);
+ const size_t root_len = uri_path_len(root);
+
+ size_t last_root_slash = 0;
for (size_t i = 0; i < path_len && i < root_len; ++i) {
const char u = uri_path_at(uri, i);
const char r = uri_path_at(root, i);
@@ -85,7 +83,9 @@ static inline SERD_PURE_FUNC
bool
uri_is_related(const SerdURIView* uri, const SerdURIView* root)
{
- return uri_rooted_index(uri, root) > 0;
+ return root && root->scheme.len &&
+ slice_equals(&root->scheme, &uri->scheme) &&
+ slice_equals(&root->authority, &uri->authority);
}
/** Return true iff `uri` is within the base of `root` */