From 5ea69340e389163cfea54c16a466672b9b7284b8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 20 Feb 2021 13:17:03 -0500 Subject: Rename SerdURI to SerdURIView --- src/env.c | 14 +++++++------- src/node.c | 32 +++++++++++++++++--------------- src/serdi.c | 4 ++-- src/uri.c | 28 ++++++++++++++-------------- src/uri_utils.h | 10 +++++----- src/writer.c | 28 ++++++++++++++-------------- 6 files changed, 59 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/env.c b/src/env.c index c319ce54..0538db69 100644 --- a/src/env.c +++ b/src/env.c @@ -30,7 +30,7 @@ struct SerdEnvImpl { SerdPrefix* prefixes; size_t n_prefixes; SerdNode base_uri_node; - SerdURI base_uri; + SerdURIView base_uri; }; SerdEnv* @@ -62,7 +62,7 @@ serd_env_free(SerdEnv* env) } const SerdNode* -serd_env_get_base_uri(const SerdEnv* env, SerdURI* out) +serd_env_get_base_uri(const SerdEnv* env, SerdURIView* out) { if (out) { *out = env->base_uri; @@ -86,8 +86,8 @@ serd_env_set_base_uri(SerdEnv* env, const SerdNode* uri) } // Resolve base URI and create a new node and URI for it - SerdURI base_uri; - SerdNode base_uri_node = + SerdURIView base_uri; + SerdNode base_uri_node = serd_node_new_uri_from_node(uri, &env->base_uri, &base_uri); // Replace the current base URI @@ -143,8 +143,8 @@ serd_env_set_prefix(SerdEnv* env, const SerdNode* name, const SerdNode* uri) serd_env_add(env, name, uri); } else { // Resolve relative URI and create a new node and URI for it - SerdURI abs_uri; - SerdNode abs_uri_node = + SerdURIView abs_uri; + SerdNode abs_uri_node = serd_node_new_uri_from_node(uri, &env->base_uri, &abs_uri); // Set prefix to resolved (absolute) URI @@ -218,7 +218,7 @@ serd_env_expand_node(const SerdEnv* env, const SerdNode* node) case SERD_LITERAL: break; case SERD_URI: { - SerdURI ignored; + SerdURIView ignored; return serd_node_new_uri_from_node(node, &env->base_uri, &ignored); } case SERD_CURIE: { diff --git a/src/node.c b/src/node.c index 585f1443..99f15b8a 100644 --- a/src/node.c +++ b/src/node.c @@ -87,7 +87,7 @@ serd_node_equals(const SerdNode* a, const SerdNode* b) } static size_t -serd_uri_string_length(const SerdURI* uri) +serd_uri_string_length(const SerdURIView* uri) { size_t len = uri->path_base.len; @@ -115,9 +115,9 @@ string_sink(const void* buf, size_t len, void* stream) } SerdNode -serd_node_new_uri_from_node(const SerdNode* uri_node, - const SerdURI* base, - SerdURI* out) +serd_node_new_uri_from_node(const SerdNode* uri_node, + const SerdURIView* base, + SerdURIView* out) { return (uri_node->type == SERD_URI && uri_node->buf) ? serd_node_new_uri_from_string(uri_node->buf, base, out) @@ -125,16 +125,16 @@ serd_node_new_uri_from_node(const SerdNode* uri_node, } SerdNode -serd_node_new_uri_from_string(const char* str, - const SerdURI* base, - SerdURI* out) +serd_node_new_uri_from_string(const char* str, + const SerdURIView* base, + SerdURIView* out) { if (!str || str[0] == '\0') { // Empty URI => Base URI, or nothing if no base is given return base ? serd_node_new_uri(base, NULL, out) : SERD_NODE_NULL; } - SerdURI uri; + SerdURIView uri; serd_uri_parse(str, &uri); return serd_node_new_uri(&uri, base, out); // Resolve/Serialise } @@ -176,7 +176,7 @@ is_uri_path_char(const char c) } SerdNode -serd_node_new_file_uri(const char* path, const char* hostname, SerdURI* out) +serd_node_new_file_uri(const char* path, const char* hostname, SerdURIView* out) { const size_t path_len = strlen(path); const size_t hostname_len = hostname ? strlen(hostname) : 0; @@ -224,9 +224,11 @@ serd_node_new_file_uri(const char* path, const char* hostname, SerdURI* out) } SerdNode -serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out) +serd_node_new_uri(const SerdURIView* uri, + const SerdURIView* base, + SerdURIView* out) { - SerdURI abs_uri = *uri; + SerdURIView abs_uri = *uri; if (base) { serd_uri_resolve(uri, base, &abs_uri); } @@ -248,10 +250,10 @@ serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out) } SerdNode -serd_node_new_relative_uri(const SerdURI* uri, - const SerdURI* base, - const SerdURI* root, - SerdURI* out) +serd_node_new_relative_uri(const SerdURIView* uri, + const SerdURIView* base, + const SerdURIView* root, + SerdURIView* out) { const size_t uri_len = serd_uri_string_length(uri); const size_t base_len = serd_uri_string_length(base); diff --git a/src/serdi.c b/src/serdi.c index 26577ef6..c6ca4fc3 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -308,8 +308,8 @@ main(int argc, char** argv) const SerdStyle output_style = choose_style(input_syntax, output_syntax, ascii, bulk_write, full_uris); - SerdURI base_uri = SERD_URI_NULL; - SerdNode base = SERD_NODE_NULL; + SerdURIView base_uri = SERD_URI_NULL; + SerdNode base = SERD_NODE_NULL; if (a < argc) { // Base URI given on command line base = serd_node_new_uri_from_string((const char*)argv[a], NULL, &base_uri); } else if (from_file && in_fd != stdin) { // Use input file URI diff --git a/src/uri.c b/src/uri.c index 01384072..f40fde83 100644 --- a/src/uri.c +++ b/src/uri.c @@ -94,7 +94,7 @@ serd_uri_string_has_scheme(const char* utf8) } SerdStatus -serd_uri_parse(const char* utf8, SerdURI* out) +serd_uri_parse(const char* utf8, SerdURIView* out) { *out = SERD_URI_NULL; @@ -306,7 +306,7 @@ merge(SerdStringView* base, SerdStringView* path) /// See http://tools.ietf.org/html/rfc3986#section-5.2.2 void -serd_uri_resolve(const SerdURI* r, const SerdURI* base, SerdURI* t) +serd_uri_resolve(const SerdURIView* r, const SerdURIView* base, SerdURIView* t) { if (!base->scheme.len) { *t = *r; // Don't resolve against non-absolute URIs @@ -347,7 +347,7 @@ serd_uri_resolve(const SerdURI* r, const SerdURI* base, SerdURI* t) /** Write the path of `uri` starting at index `i` */ static size_t -write_path_tail(SerdSink sink, void* stream, const SerdURI* uri, size_t i) +write_path_tail(SerdSink sink, void* stream, const SerdURIView* uri, size_t i) { size_t len = 0; if (i < uri->path_base.len) { @@ -368,10 +368,10 @@ write_path_tail(SerdSink sink, void* stream, const SerdURI* uri, size_t i) /** Write the path of `uri` relative to the path of `base`. */ static size_t -write_rel_path(SerdSink sink, - void* stream, - const SerdURI* uri, - const SerdURI* base) +write_rel_path(SerdSink sink, + void* stream, + const SerdURIView* uri, + const SerdURIView* base) { const size_t path_len = uri_path_len(uri); const size_t base_len = uri_path_len(base); @@ -413,7 +413,7 @@ write_rel_path(SerdSink sink, } static uint8_t -serd_uri_path_starts_without_slash(const SerdURI* uri) +serd_uri_path_starts_without_slash(const SerdURIView* uri) { return ((uri->path_base.len || uri->path.len) && ((!uri->path_base.len || uri->path_base.buf[0] != '/') && @@ -422,11 +422,11 @@ serd_uri_path_starts_without_slash(const SerdURI* uri) /// See http://tools.ietf.org/html/rfc3986#section-5.3 size_t -serd_uri_serialise_relative(const SerdURI* uri, - const SerdURI* base, - const SerdURI* root, - SerdSink sink, - void* stream) +serd_uri_serialise_relative(const SerdURIView* uri, + const SerdURIView* base, + const SerdURIView* root, + SerdSink sink, + void* stream) { size_t len = 0; const bool relative = @@ -470,7 +470,7 @@ serd_uri_serialise_relative(const SerdURI* uri, /// See http://tools.ietf.org/html/rfc3986#section-5.3 size_t -serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream) +serd_uri_serialise(const SerdURIView* uri, SerdSink sink, void* stream) { return serd_uri_serialise_relative(uri, NULL, NULL, sink, stream); } diff --git a/src/uri_utils.h b/src/uri_utils.h index 735555c4..03d397d2 100644 --- a/src/uri_utils.h +++ b/src/uri_utils.h @@ -31,13 +31,13 @@ slice_equals(const SerdStringView* a, const SerdStringView* b) } static inline size_t -uri_path_len(const SerdURI* uri) +uri_path_len(const SerdURIView* uri) { return uri->path_base.len + uri->path.len; } static inline char -uri_path_at(const SerdURI* uri, size_t i) +uri_path_at(const SerdURIView* uri, size_t i) { if (i < uri->path_base.len) { return uri->path_base.buf[i]; @@ -51,7 +51,7 @@ uri_path_at(const SerdURI* uri, size_t i) or zero if `uri` is not under `root`. */ static inline SERD_PURE_FUNC size_t -uri_rooted_index(const SerdURI* uri, const SerdURI* root) +uri_rooted_index(const SerdURIView* uri, const SerdURIView* root) { if (!root || !root->scheme.len || !slice_equals(&root->scheme, &uri->scheme) || @@ -81,14 +81,14 @@ uri_rooted_index(const SerdURI* uri, const SerdURI* root) /** Return true iff `uri` shares path components with `root` */ static inline SERD_PURE_FUNC bool -uri_is_related(const SerdURI* uri, const SerdURI* root) +uri_is_related(const SerdURIView* uri, const SerdURIView* root) { return uri_rooted_index(uri, root) > 0; } /** Return true iff `uri` is within the base of `root` */ static inline SERD_PURE_FUNC bool -uri_is_under(const SerdURI* uri, const SerdURI* root) +uri_is_under(const SerdURIView* uri, const SerdURIView* root) { const size_t index = uri_rooted_index(uri, root); return index > 0 && uri->path.len > index; diff --git a/src/writer.c b/src/writer.c index e97af301..c365f23c 100644 --- a/src/writer.c +++ b/src/writer.c @@ -96,8 +96,8 @@ struct SerdWriterImpl { SerdStyle style; SerdEnv* env; SerdNode root_node; - SerdURI root_uri; - SerdURI base_uri; + SerdURIView root_uri; + SerdURIView base_uri; SerdStack anon_stack; SerdByteSink byte_sink; SerdErrorSink error_sink; @@ -151,7 +151,7 @@ w_err(SerdWriter* writer, SerdStatus st, const char* fmt, ...) } static inline SERD_PURE_FUNC WriteContext* -anon_stack_top(SerdWriter* writer) + anon_stack_top(SerdWriter* writer) { assert(!serd_stack_is_empty(&writer->anon_stack)); return (WriteContext*)(writer->anon_stack.buf + writer->anon_stack.size - @@ -600,14 +600,14 @@ write_uri_node(SerdWriter* const writer, write_sep(writer, SEP_URI_BEGIN); if (writer->style & SERD_STYLE_RESOLVED) { - SerdURI in_base_uri; - SerdURI uri; - SerdURI abs_uri; + SerdURIView in_base_uri; + SerdURIView uri; + SerdURIView abs_uri; serd_env_get_base_uri(writer->env, &in_base_uri); serd_uri_parse(node->buf, &uri); serd_uri_resolve(&uri, &in_base_uri, &abs_uri); - bool rooted = uri_is_under(&writer->base_uri, &writer->root_uri); - SerdURI* root = rooted ? &writer->root_uri : &writer->base_uri; + bool rooted = uri_is_under(&writer->base_uri, &writer->root_uri); + SerdURIView* root = rooted ? &writer->root_uri : &writer->base_uri; if (!uri_is_under(&abs_uri, root) || writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) { serd_uri_serialise(&abs_uri, uri_sink, writer); @@ -952,12 +952,12 @@ serd_writer_finish(SerdWriter* writer) } SerdWriter* -serd_writer_new(SerdSyntax syntax, - SerdStyle style, - SerdEnv* env, - const SerdURI* base_uri, - SerdSink ssink, - void* stream) +serd_writer_new(SerdSyntax syntax, + SerdStyle style, + SerdEnv* env, + const SerdURIView* base_uri, + SerdSink ssink, + void* stream) { const WriteContext context = WRITE_CONTEXT_NULL; SerdWriter* writer = (SerdWriter*)calloc(1, sizeof(SerdWriter)); -- cgit v1.2.1