aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-13 01:40:38 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:59 +0100
commit8563932ab3abcbf886d1ec77b3ad632aeb9a3ea1 (patch)
tree74b504ceeac4e8513c930e0df05ffd0dee94634b /src/writer.c
parenta749f75df13a56dc0649435a36ce2bc882cc134a (diff)
downloadserd-8563932ab3abcbf886d1ec77b3ad632aeb9a3ea1.tar.gz
serd-8563932ab3abcbf886d1ec77b3ad632aeb9a3ea1.tar.bz2
serd-8563932ab3abcbf886d1ec77b3ad632aeb9a3ea1.zip
Simplify abbreviated URI writing code
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/writer.c b/src/writer.c
index 3cfb8c55..fe29563b 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -643,7 +643,8 @@ write_uri_node(SerdWriter* const writer,
const SerdField field,
const SerdStatementFlags flags)
{
- SerdStatus st = SERD_SUCCESS;
+ const SerdWorld* const world = writer->world;
+ SerdStatus st = SERD_SUCCESS;
if (is_inline_start(writer, field, flags)) {
TRY(st, write_sep(writer, flags, SEP_ANON_BEGIN));
@@ -656,20 +657,21 @@ write_uri_node(SerdWriter* const writer,
SerdStringView suffix = {NULL, 0};
const char* node_str = serd_node_string(node);
const bool has_scheme = serd_uri_string_has_scheme(node_str);
- if (field == SERD_PREDICATE && supports_abbrev(writer) &&
- serd_node_equals(node, writer->world->rdf_type)) {
- return esink("a", 1, writer);
- } else if (supports_abbrev(writer) &&
- serd_node_equals(node, writer->world->rdf_nil)) {
- return esink("()", 2, writer);
- } else if (has_scheme && supports_abbrev(writer) &&
- !(writer->flags & SERD_WRITE_UNQUALIFIED) &&
- serd_env_qualify_in_place(writer->env, node, &prefix, &suffix) &&
- is_name(serd_node_string(prefix), serd_node_length(prefix)) &&
- is_name(suffix.buf, suffix.len)) {
- TRY(st, write_uri_from_node(writer, prefix));
- TRY(st, esink(":", 1, writer));
- return ewrite_uri(writer, suffix.buf, suffix.len);
+
+ if (supports_abbrev(writer)) {
+ if (field == 1 && serd_node_equals(node, world->rdf_type)) {
+ return esink("a", 1, writer);
+ } else if (serd_node_equals(node, world->rdf_nil)) {
+ return esink("()", 2, writer);
+ } else if (has_scheme &&
+ !(writer->flags & SERD_WRITE_UNQUALIFIED) &&
+ serd_env_qualify_in_place(writer->env, node, &prefix, &suffix) &&
+ is_name(serd_node_string(prefix), serd_node_length(prefix)) &&
+ is_name(suffix.buf, suffix.len)) {
+ TRY(st, write_uri_from_node(writer, prefix));
+ TRY(st, esink(":", 1, writer));
+ return ewrite_uri(writer, suffix.buf, suffix.len);
+ }
}
TRY(st, esink("<", 1, writer));