aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-03-01 19:50:23 -0500
committerDavid Robillard <d@drobilla.net>2023-04-02 20:04:00 -0400
commitb7ed626f5396e70fb9fff94e7edce0b54fde1ca5 (patch)
tree9bc360de8ec906a598e7781438c8983251eaff8c /src
parent2eb037b3f1abebbac697c7d804f1e6339c907aaa (diff)
downloadserd-b7ed626f5396e70fb9fff94e7edce0b54fde1ca5.tar.gz
serd-b7ed626f5396e70fb9fff94e7edce0b54fde1ca5.tar.bz2
serd-b7ed626f5396e70fb9fff94e7edce0b54fde1ca5.zip
Improve TriG pretty-printing and remove trailing newlines
Diffstat (limited to 'src')
-rw-r--r--src/writer.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/writer.c b/src/writer.c
index d4b47e0a..3433a924 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -62,7 +62,7 @@ typedef struct {
} SepRule;
static const SepRule rules[] = {{NULL, 0, 0, 0, 0},
- {" .\n\n", 4, 0, 0, 0},
+ {" .\n", 3, 0, 0, 0},
{" ;", 2, 0, 1, 1},
{" ,", 2, 0, 1, 0},
{NULL, 0, 0, 1, 0},
@@ -73,7 +73,7 @@ static const SepRule rules[] = {{NULL, 0, 0, 0, 0},
{NULL, 0, 0, 1, 0},
{")", 1, 1, 0, 0},
{" {", 2, 0, 1, 1},
- {" }", 2, 0, 1, 1},
+ {"}\n", 2, 0, 0, 0},
{"<", 1, 0, 0, 0},
{">", 1, 0, 0, 0},
{"\n", 1, 0, 1, 0}};
@@ -459,7 +459,8 @@ write_sep(SerdWriter* writer, const Sep sep)
if ((writer->last_sep && rule->space_after_sep) ||
(!writer->last_sep && rule->space_after_node)) {
write_newline(writer);
- } else if (writer->last_sep && rule->space_after_node) {
+ } else if (writer->last_sep && writer->last_sep != SEP_GRAPH_BEGIN &&
+ rule->space_after_node) {
sink(" ", 1, writer);
}
@@ -837,6 +838,7 @@ serd_writer_write_statement(SerdWriter* writer,
reset_context(writer, true);
if (graph) {
+ write_newline(writer);
TRY(write_node(writer, graph, datatype, lang, FIELD_GRAPH, flags));
++writer->indent;
write_sep(writer, SEP_GRAPH_BEGIN);
@@ -885,6 +887,10 @@ serd_writer_write_statement(SerdWriter* writer,
}
if (!(flags & SERD_ANON_CONT)) {
+ if (writer->last_sep == SEP_END_S) {
+ write_newline(writer);
+ }
+
write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags);
++writer->indent;
write_sep(writer, SEP_S_P);