From a25c9927ce648bc83064bb8ea91c9ca8b8a9582f 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/writer.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/writer.c') diff --git a/src/writer.c b/src/writer.c index abfe327b..f0bd11eb 100644 --- a/src/writer.c +++ b/src/writer.c @@ -614,20 +614,21 @@ write_uri_node(SerdWriter* const writer, write_sep(writer, SEP_URI_BEGIN); if (writer->flags & SERD_WRITE_RESOLVED) { + const SerdURIView uri = serd_parse_uri(node_str); + 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(&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); + + const SerdURIView abs_uri = serd_resolve_uri(uri, in_base_uri); + const bool rooted = uri_is_under(&in_base_uri, &writer->root_uri); + const SerdURIView* root = rooted ? &writer->root_uri : &in_base_uri; + + if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS || + !uri_is_under(&abs_uri, root) || + !uri_is_related(&abs_uri, &in_base_uri)) { + serd_write_uri(abs_uri, uri_sink, writer); } else { - serd_uri_serialise_relative( - &uri, &writer->base_uri, root, uri_sink, writer); + serd_write_uri(serd_relative_uri(uri, in_base_uri), uri_sink, writer); } } else { write_uri_from_node(writer, node); @@ -1026,7 +1027,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; -- cgit v1.2.1