From 941b14a0ab8f7c80f94e04762e65a48f9ed02f6e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 20 Feb 2021 16:47:55 -0500 Subject: Simplify URI API and implementation --- src/uri_utils.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/uri_utils.h') 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` */ -- cgit v1.2.1