aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-03-10 17:29:39 -0400
committerDavid Robillard <d@drobilla.net>2024-03-10 17:29:39 -0400
commit357ae32835097005fa8c82708f3a8e102f981fb6 (patch)
treefc29a3b7899f43da2d789e39eebc8b1566dc45ba /src
parent4b755dbd0054c5b0b7099ab76d28ce85ca6609a5 (diff)
downloadserd-357ae32835097005fa8c82708f3a8e102f981fb6.tar.gz
serd-357ae32835097005fa8c82708f3a8e102f981fb6.tar.bz2
serd-357ae32835097005fa8c82708f3a8e102f981fb6.zip
Simplify writer logic
Diffstat (limited to 'src')
-rw-r--r--src/writer.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/writer.c b/src/writer.c
index 38f40e30..b1ffdbdd 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -663,21 +663,20 @@ write_literal(SerdWriter* writer,
if (supports_abbrev(writer) && datatype && datatype->buf) {
const char* type_uri = (const char*)datatype->buf;
- if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) &&
- (!strcmp(type_uri + sizeof(NS_XSD) - 1, "boolean") ||
- !strcmp(type_uri + sizeof(NS_XSD) - 1, "integer"))) {
- return esink(node->buf, node->n_bytes, writer);
- }
+ if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1)) {
+ const char* const xsd_name = type_uri + sizeof(NS_XSD) - 1;
+ if (!strcmp(xsd_name, "boolean") || !strcmp(xsd_name, "integer")) {
+ return esink(node->buf, node->n_bytes, writer);
+ }
- if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) &&
- !strcmp(type_uri + sizeof(NS_XSD) - 1, "decimal") &&
- strchr((const char*)node->buf, '.') &&
- node->buf[node->n_bytes - 1] != '.') {
- /* xsd:decimal literals without trailing digits, e.g. "5.", can
- not be written bare in Turtle. We could add a 0 which is
- prettier, but changes the text and breaks round tripping.
- */
- return esink(node->buf, node->n_bytes, writer);
+ if (!strcmp(xsd_name, "decimal") && strchr((const char*)node->buf, '.') &&
+ node->buf[node->n_bytes - 1] != '.') {
+ /* xsd:decimal literals without trailing digits, e.g. "5.", can't be
+ written bare in Turtle. We could add a 0 which is prettier, but
+ changes the text and breaks round tripping.
+ */
+ return esink(node->buf, node->n_bytes, writer);
+ }
}
}
@@ -685,18 +684,18 @@ write_literal(SerdWriter* writer,
(node->flags & (SERD_HAS_NEWLINE | SERD_HAS_QUOTE))) {
TRY(st, esink("\"\"\"", 3, writer));
TRY(st, write_text(writer, WRITE_LONG_STRING, node->buf, node->n_bytes));
- TRY(st, esink("\"\"\"", 3, writer));
+ st = esink("\"\"\"", 3, writer);
} else {
TRY(st, esink("\"", 1, writer));
TRY(st, write_text(writer, WRITE_STRING, node->buf, node->n_bytes));
- TRY(st, esink("\"", 1, writer));
+ st = esink("\"", 1, writer);
}
if (lang && lang->buf) {
TRY(st, esink("@", 1, writer));
- TRY(st, esink(lang->buf, lang->n_bytes, writer));
+ st = esink(lang->buf, lang->n_bytes, writer);
} else if (datatype && datatype->buf) {
TRY(st, esink("^^", 2, writer));
- return write_node(writer, datatype, NULL, NULL, FIELD_NONE, flags);
+ st = write_node(writer, datatype, NULL, NULL, FIELD_NONE, flags);
}
return st;