aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-03-29 07:28:19 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commitfff826f406e0b9975fd8672041e50dd1a342339f (patch)
tree03a22b89b83a8b26fdf18dd8700e51833b488d81 /src/writer.c
parent94d3433dcf0e77d2c867c9a2dd6928acfea4184c (diff)
downloadserd-fff826f406e0b9975fd8672041e50dd1a342339f.tar.gz
serd-fff826f406e0b9975fd8672041e50dd1a342339f.tar.bz2
serd-fff826f406e0b9975fd8672041e50dd1a342339f.zip
Simplify URI API and implementation
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/writer.c b/src/writer.c
index 2372f712..a0325243 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -770,21 +770,19 @@ write_uri_node(SerdWriter* const writer,
TRY(st, esink("<", 1, writer));
- if (writer->flags & SERD_WRITE_RESOLVED) {
- SerdURIView in_base_uri;
- SerdURIView uri;
- SerdURIView abs_uri;
- serd_env_base_uri(writer->env, &in_base_uri);
- serd_uri_parse(node_str, &uri);
- serd_uri_resolve(&uri, &in_base_uri, &abs_uri);
- bool rooted = uri_is_under(&in_base_uri, &writer->root_uri);
- SerdURIView* root = rooted ? &writer->root_uri : &in_base_uri;
- UriSinkContext ctx = {writer, SERD_SUCCESS};
- if (!uri_is_under(&abs_uri, root) || writer->syntax == SERD_NTRIPLES ||
- writer->syntax == SERD_NQUADS) {
- serd_uri_serialise(&abs_uri, uri_sink, &ctx);
+ SerdURIView base_uri = SERD_URI_NULL;
+ if ((writer->flags & SERD_WRITE_RESOLVED) &&
+ serd_env_base_uri(writer->env, &base_uri)) {
+ SerdURIView uri = serd_parse_uri(node_str);
+ SerdURIView abs_uri = serd_resolve_uri(uri, base_uri);
+ bool rooted = uri_is_under(&base_uri, &writer->root_uri);
+ const SerdURIView* root = rooted ? &writer->root_uri : &base_uri;
+ UriSinkContext ctx = {writer, SERD_SUCCESS};
+
+ if (!supports_abbrev(writer) || !uri_is_under(&abs_uri, root)) {
+ serd_write_uri(abs_uri, uri_sink, &ctx);
} else {
- serd_uri_serialise_relative(&uri, &in_base_uri, root, uri_sink, &ctx);
+ serd_write_uri(serd_relative_uri(uri, base_uri), uri_sink, &ctx);
}
} else {
TRY(st, write_uri_from_node(writer, node));
@@ -1211,7 +1209,7 @@ serd_writer_set_root_uri(SerdWriter* writer, const SerdNode* uri)
if (uri) {
writer->root_node = serd_node_copy(uri);
- serd_uri_parse(serd_node_string(writer->root_node), &writer->root_uri);
+ writer->root_uri = serd_parse_uri(serd_node_string(writer->root_node));
}
return SERD_SUCCESS;