aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-02-20 13:17:03 -0500
committerDavid Robillard <d@drobilla.net>2022-01-13 15:33:54 -0500
commite04877cdf389fac06f899d4d690af2fcb0d6d2c7 (patch)
treed8bebc8c55509a344aae0524e497770a621452b6
parentfaac2e52df494481dc28168a856058a414a913f2 (diff)
downloadserd-e04877cdf389fac06f899d4d690af2fcb0d6d2c7.tar.gz
serd-e04877cdf389fac06f899d4d690af2fcb0d6d2c7.tar.bz2
serd-e04877cdf389fac06f899d4d690af2fcb0d6d2c7.zip
Rename SerdURI to SerdURIView
-rw-r--r--include/serd/serd.h78
-rw-r--r--src/env.c14
-rw-r--r--src/node.c38
-rw-r--r--src/serdi.c4
-rw-r--r--src/uri.c40
-rw-r--r--src/uri_utils.h10
-rw-r--r--src/writer.c26
-rw-r--r--test/test_uri.c18
8 files changed, 115 insertions, 113 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index f971d417..fa0b2c0d 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -234,8 +234,8 @@ typedef size_t (*SerdSink)(const void* SERD_NONNULL buf,
/**
A parsed URI.
- This struct directly refers to chunks in other strings, it does not own any
- memory itself. Thus, URIs can be parsed and/or resolved against a base URI
+ This struct directly refers to slices in other strings, it does not own any
+ memory itself. This allows some URI operations like resolution to be done
in-place without allocating memory.
*/
typedef struct {
@@ -245,9 +245,9 @@ typedef struct {
SerdStringView path; ///< Path suffix
SerdStringView query; ///< Query
SerdStringView fragment; ///< Fragment
-} SerdURI;
+} SerdURIView;
-static const SerdURI SERD_URI_NULL =
+static const SerdURIView SERD_URI_NULL =
{{NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0}};
/**
@@ -272,7 +272,7 @@ serd_uri_string_has_scheme(const char* SERD_NULLABLE utf8);
/// Parse `utf8`, writing result to `out`
SERD_API
SerdStatus
-serd_uri_parse(const char* SERD_NONNULL utf8, SerdURI* SERD_NONNULL out);
+serd_uri_parse(const char* SERD_NONNULL utf8, SerdURIView* SERD_NONNULL out);
/**
Set target `t` to reference `r` resolved against `base`.
@@ -281,16 +281,16 @@ serd_uri_parse(const char* SERD_NONNULL utf8, SerdURI* SERD_NONNULL out);
*/
SERD_API
void
-serd_uri_resolve(const SerdURI* SERD_NONNULL r,
- const SerdURI* SERD_NONNULL base,
- SerdURI* SERD_NONNULL t);
+serd_uri_resolve(const SerdURIView* SERD_NONNULL r,
+ const SerdURIView* SERD_NONNULL base,
+ SerdURIView* SERD_NONNULL t);
/// Serialise `uri` with a series of calls to `sink`
SERD_API
size_t
-serd_uri_serialise(const SerdURI* SERD_NONNULL uri,
- SerdSink SERD_NONNULL sink,
- void* SERD_NONNULL stream);
+serd_uri_serialise(const SerdURIView* SERD_NONNULL uri,
+ SerdSink SERD_NONNULL sink,
+ void* SERD_NONNULL stream);
/**
Serialise `uri` relative to `base` with a series of calls to `sink`
@@ -301,11 +301,11 @@ serd_uri_serialise(const SerdURI* SERD_NONNULL uri,
*/
SERD_API
size_t
-serd_uri_serialise_relative(const SerdURI* SERD_NONNULL uri,
- const SerdURI* SERD_NULLABLE base,
- const SerdURI* SERD_NULLABLE root,
- SerdSink SERD_NONNULL sink,
- void* SERD_NONNULL stream);
+serd_uri_serialise_relative(const SerdURIView* SERD_NONNULL uri,
+ const SerdURIView* SERD_NULLABLE base,
+ const SerdURIView* SERD_NULLABLE root,
+ SerdSink SERD_NONNULL sink,
+ void* SERD_NONNULL stream);
/**
@}
@@ -401,16 +401,16 @@ serd_node_from_substring(SerdType type,
/// Simple wrapper for serd_node_new_uri() to resolve a URI node
SERD_API
SerdNode
-serd_node_new_uri_from_node(const SerdNode* SERD_NONNULL uri_node,
- const SerdURI* SERD_NULLABLE base,
- SerdURI* SERD_NULLABLE out);
+serd_node_new_uri_from_node(const SerdNode* SERD_NONNULL uri_node,
+ const SerdURIView* SERD_NULLABLE base,
+ SerdURIView* SERD_NULLABLE out);
/// Simple wrapper for serd_node_new_uri() to resolve a URI string
SERD_API
SerdNode
-serd_node_new_uri_from_string(const char* SERD_NULLABLE str,
- const SerdURI* SERD_NULLABLE base,
- SerdURI* SERD_NULLABLE out);
+serd_node_new_uri_from_string(const char* SERD_NULLABLE str,
+ const SerdURIView* SERD_NULLABLE base,
+ SerdURIView* SERD_NULLABLE out);
/**
Create a new file URI node from a file system path and optional hostname.
@@ -423,9 +423,9 @@ serd_node_new_uri_from_string(const char* SERD_NULLABLE str,
*/
SERD_API
SerdNode
-serd_node_new_file_uri(const char* SERD_NONNULL path,
- const char* SERD_NULLABLE hostname,
- SerdURI* SERD_NULLABLE out);
+serd_node_new_file_uri(const char* SERD_NONNULL path,
+ const char* SERD_NULLABLE hostname,
+ SerdURIView* SERD_NULLABLE out);
/**
Create a new node by serialising `uri` into a new string.
@@ -439,9 +439,9 @@ serd_node_new_file_uri(const char* SERD_NONNULL path,
*/
SERD_API
SerdNode
-serd_node_new_uri(const SerdURI* SERD_NONNULL uri,
- const SerdURI* SERD_NULLABLE base,
- SerdURI* SERD_NULLABLE out);
+serd_node_new_uri(const SerdURIView* SERD_NONNULL uri,
+ const SerdURIView* SERD_NULLABLE base,
+ SerdURIView* SERD_NULLABLE out);
/**
Create a new node by serialising `uri` into a new relative URI.
@@ -457,10 +457,10 @@ serd_node_new_uri(const SerdURI* SERD_NONNULL uri,
*/
SERD_API
SerdNode
-serd_node_new_relative_uri(const SerdURI* SERD_NONNULL uri,
- const SerdURI* SERD_NULLABLE base,
- const SerdURI* SERD_NULLABLE root,
- SerdURI* SERD_NULLABLE out);
+serd_node_new_relative_uri(const SerdURIView* SERD_NONNULL uri,
+ const SerdURIView* SERD_NULLABLE base,
+ const SerdURIView* SERD_NULLABLE root,
+ SerdURIView* SERD_NULLABLE out);
/**
Create a new node by serialising `d` into an xsd:decimal string.
@@ -630,7 +630,7 @@ serd_env_free(SerdEnv* SERD_NULLABLE env);
SERD_API
const SerdNode* SERD_NONNULL
serd_env_get_base_uri(const SerdEnv* SERD_NONNULL env,
- SerdURI* SERD_NULLABLE out);
+ SerdURIView* SERD_NULLABLE out);
/// Set the current base URI
SERD_API
@@ -878,12 +878,12 @@ typedef enum {
/// Create a new RDF writer
SERD_API
SerdWriter* SERD_ALLOCATED
-serd_writer_new(SerdSyntax syntax,
- SerdStyle style,
- SerdEnv* SERD_NONNULL env,
- const SerdURI* SERD_NULLABLE base_uri,
- SerdSink SERD_NONNULL ssink,
- void* SERD_NULLABLE stream);
+serd_writer_new(SerdSyntax syntax,
+ SerdStyle style,
+ SerdEnv* SERD_NONNULL env,
+ const SerdURIView* SERD_NULLABLE base_uri,
+ SerdSink SERD_NONNULL ssink,
+ void* SERD_NULLABLE stream);
/// Free `writer`
SERD_API
diff --git a/src/env.c b/src/env.c
index c06068e6..e8d80e3f 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* const env)
}
const SerdNode*
-serd_env_get_base_uri(const SerdEnv* const env, SerdURI* const out)
+serd_env_get_base_uri(const SerdEnv* const env, SerdURIView* const out)
{
if (out) {
*out = env->base_uri;
@@ -86,8 +86,8 @@ serd_env_set_base_uri(SerdEnv* const env, const SerdNode* const 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
@@ -149,8 +149,8 @@ serd_env_set_prefix(SerdEnv* const env,
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
@@ -236,7 +236,7 @@ serd_env_expand_node(const SerdEnv* const env, const SerdNode* const 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 229f7902..84793386 100644
--- a/src/node.c
+++ b/src/node.c
@@ -39,7 +39,7 @@
#endif
static size_t
-serd_uri_string_length(const SerdURI* const uri)
+serd_uri_string_length(const SerdURIView* const uri)
{
size_t len = uri->path_base.len;
@@ -117,9 +117,9 @@ serd_node_equals(const SerdNode* const a, const SerdNode* const b)
}
SerdNode
-serd_node_new_uri_from_node(const SerdNode* const uri_node,
- const SerdURI* const base,
- SerdURI* const out)
+serd_node_new_uri_from_node(const SerdNode* const uri_node,
+ const SerdURIView* const base,
+ SerdURIView* const out)
{
return (uri_node->type == SERD_URI && uri_node->buf)
? serd_node_new_uri_from_string(uri_node->buf, base, out)
@@ -127,16 +127,16 @@ serd_node_new_uri_from_node(const SerdNode* const uri_node,
}
SerdNode
-serd_node_new_uri_from_string(const char* const str,
- const SerdURI* const base,
- SerdURI* const out)
+serd_node_new_uri_from_string(const char* const str,
+ const SerdURIView* const base,
+ SerdURIView* const 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
}
@@ -178,9 +178,9 @@ is_uri_path_char(const char c)
}
SerdNode
-serd_node_new_file_uri(const char* const path,
- const char* const hostname,
- SerdURI* const out)
+serd_node_new_file_uri(const char* const path,
+ const char* const hostname,
+ SerdURIView* const out)
{
const size_t path_len = strlen(path);
const size_t hostname_len = hostname ? strlen(hostname) : 0;
@@ -228,11 +228,11 @@ serd_node_new_file_uri(const char* const path,
}
SerdNode
-serd_node_new_uri(const SerdURI* const uri,
- const SerdURI* const base,
- SerdURI* const out)
+serd_node_new_uri(const SerdURIView* const uri,
+ const SerdURIView* const base,
+ SerdURIView* const out)
{
- SerdURI abs_uri = *uri;
+ SerdURIView abs_uri = *uri;
if (base) {
serd_uri_resolve(uri, base, &abs_uri);
}
@@ -254,10 +254,10 @@ serd_node_new_uri(const SerdURI* const uri,
}
SerdNode
-serd_node_new_relative_uri(const SerdURI* const uri,
- const SerdURI* const base,
- const SerdURI* const root,
- SerdURI* const out)
+serd_node_new_relative_uri(const SerdURIView* const uri,
+ const SerdURIView* const base,
+ const SerdURIView* const root,
+ SerdURIView* const 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 de965005..1ebd5e85 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -315,8 +315,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 82221d7a..60f387b0 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -95,7 +95,7 @@ serd_uri_string_has_scheme(const char* utf8)
}
SerdStatus
-serd_uri_parse(const char* const utf8, SerdURI* const out)
+serd_uri_parse(const char* const utf8, SerdURIView* const out)
{
*out = SERD_URI_NULL;
@@ -307,9 +307,9 @@ merge(SerdStringView* const base, SerdStringView* const path)
/// See http://tools.ietf.org/html/rfc3986#section-5.2.2
void
-serd_uri_resolve(const SerdURI* const r,
- const SerdURI* const base,
- SerdURI* const t)
+serd_uri_resolve(const SerdURIView* const r,
+ const SerdURIView* const base,
+ SerdURIView* const t)
{
if (!base->scheme.len) {
*t = *r; // Don't resolve against non-absolute URIs
@@ -350,10 +350,10 @@ serd_uri_resolve(const SerdURI* const r,
/** Write the path of `uri` starting at index `i` */
static size_t
-write_path_tail(SerdSink sink,
- void* const stream,
- const SerdURI* const uri,
- const size_t i)
+write_path_tail(SerdSink sink,
+ void* const stream,
+ const SerdURIView* const uri,
+ const size_t i)
{
size_t len = 0;
if (i < uri->path_base.len) {
@@ -374,10 +374,10 @@ write_path_tail(SerdSink sink,
/** Write the path of `uri` relative to the path of `base`. */
static size_t
-write_rel_path(SerdSink sink,
- void* const stream,
- const SerdURI* const uri,
- const SerdURI* const base)
+write_rel_path(SerdSink sink,
+ void* const stream,
+ const SerdURIView* const uri,
+ const SerdURIView* const base)
{
const size_t path_len = uri_path_len(uri);
const size_t base_len = uri_path_len(base);
@@ -419,7 +419,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] != '/') &&
@@ -428,11 +428,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* const uri,
- const SerdURI* const base,
- const SerdURI* const root,
- SerdSink sink,
- void* const stream)
+serd_uri_serialise_relative(const SerdURIView* const uri,
+ const SerdURIView* const base,
+ const SerdURIView* const root,
+ SerdSink sink,
+ void* const stream)
{
size_t len = 0;
const bool relative =
@@ -476,7 +476,9 @@ serd_uri_serialise_relative(const SerdURI* const uri,
/// See http://tools.ietf.org/html/rfc3986#section-5.3
size_t
-serd_uri_serialise(const SerdURI* const uri, SerdSink sink, void* const stream)
+serd_uri_serialise(const SerdURIView* const uri,
+ SerdSink sink,
+ void* const 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 c613b00c..0d5c16f2 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;
@@ -598,14 +598,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);
@@ -935,12 +935,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));
diff --git a/test/test_uri.c b/test/test_uri.c
index 8c3ec5a4..e6933759 100644
--- a/test/test_uri.c
+++ b/test/test_uri.c
@@ -69,8 +69,8 @@ test_uri_from_string(void)
SerdNode nonsense = serd_node_new_uri_from_string(NULL, NULL, NULL);
assert(nonsense.type == SERD_NOTHING);
- SerdURI base_uri;
- SerdNode base =
+ SerdURIView base_uri;
+ SerdNode base =
serd_node_new_uri_from_string("http://example.org/", NULL, &base_uri);
SerdNode nil = serd_node_new_uri_from_string(NULL, &base_uri, NULL);
SerdNode nil2 = serd_node_new_uri_from_string("", &base_uri, NULL);
@@ -87,16 +87,16 @@ test_uri_from_string(void)
static void
test_relative_uri(void)
{
- SerdURI base_uri;
- SerdNode base =
+ SerdURIView base_uri;
+ SerdNode base =
serd_node_new_uri_from_string("http://example.org/", NULL, &base_uri);
SerdNode abs = serd_node_from_string(SERD_URI, "http://example.org/foo/bar");
- SerdURI abs_uri;
+ SerdURIView abs_uri;
serd_uri_parse(abs.buf, &abs_uri);
- SerdURI rel_uri;
- SerdNode rel =
+ SerdURIView rel_uri;
+ SerdNode rel =
serd_node_new_relative_uri(&abs_uri, &base_uri, NULL, &rel_uri);
assert(!strcmp(rel.buf, "/foo/bar"));
@@ -107,8 +107,8 @@ test_relative_uri(void)
serd_node_new_relative_uri(&base_uri, &abs_uri, &abs_uri, NULL);
assert(!strcmp(noup.buf, "http://example.org/"));
- SerdNode x = serd_node_from_string(SERD_URI, "http://example.org/foo/x");
- SerdURI x_uri;
+ SerdNode x = serd_node_from_string(SERD_URI, "http://example.org/foo/x");
+ SerdURIView x_uri;
serd_uri_parse(x.buf, &x_uri);
SerdNode x_rel = serd_node_new_relative_uri(&x_uri, &abs_uri, &abs_uri, NULL);