aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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.c24
6 files changed, 66 insertions, 64 deletions
diff --git a/src/env.c b/src/env.c
index 7c4aca48..81b34fc7 100644
--- a/src/env.c
+++ b/src/env.c
@@ -17,7 +17,7 @@ struct SerdEnvImpl {
SerdPrefix* prefixes;
size_t n_prefixes;
SerdNode base_uri_node;
- SerdURI base_uri;
+ SerdURIView base_uri;
};
SerdEnv*
@@ -52,7 +52,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;
@@ -76,8 +76,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
@@ -142,8 +142,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
@@ -229,7 +229,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 8f7a3aad..b2cca085 100644
--- a/src/node.c
+++ b/src/node.c
@@ -26,7 +26,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;
@@ -104,9 +104,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)
@@ -114,16 +114,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
}
@@ -175,9 +175,9 @@ is_dir_sep(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;
@@ -226,11 +226,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);
}
@@ -252,10 +252,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 cb5bbfa0..0ec6366f 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -316,8 +316,8 @@ main(int argc, char** argv)
const SerdStyle output_style = choose_style(
input_syntax, output_syntax, ascii, bulk_write, full_uris, lax);
- 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 18154329..def2b326 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -83,7 +83,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;
@@ -259,9 +259,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
@@ -302,10 +302,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) {
@@ -326,10 +326,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);
@@ -367,7 +367,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] != '/') &&
@@ -376,11 +376,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 =
@@ -428,7 +428,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 9146ee79..b275cf5f 100644
--- a/src/uri_utils.h
+++ b/src/uri_utils.h
@@ -23,13 +23,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];
@@ -47,7 +47,7 @@ uri_path_at(const SerdURI* uri, size_t i)
otherwise it may merely share some leading path components).
*/
static inline SERD_PURE_FUNC SlashIndexes
-uri_rooted_index(const SerdURI* uri, const SerdURI* root)
+uri_rooted_index(const SerdURIView* uri, const SerdURIView* root)
{
SlashIndexes indexes = {SIZE_MAX, SIZE_MAX};
@@ -85,14 +85,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).shared != SIZE_MAX;
}
/** 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 SlashIndexes indexes = uri_rooted_index(uri, root);
return indexes.shared && indexes.shared != SIZE_MAX &&
diff --git a/src/writer.c b/src/writer.c
index 8070392f..19f5d269 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -118,8 +118,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;
@@ -752,14 +752,14 @@ write_uri_node(SerdWriter* const writer,
TRY(st, esink("<", 1, writer));
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;
+ SerdURIView* root = rooted ? &writer->root_uri : &writer->base_uri;
UriSinkContext ctx = {writer, SERD_SUCCESS};
if (!uri_is_under(&abs_uri, root) || writer->syntax == SERD_NTRIPLES ||
writer->syntax == SERD_NQUADS) {
@@ -1118,12 +1118,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));