diff options
author | David Robillard <d@drobilla.net> | 2025-03-16 18:05:16 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2025-03-16 20:26:27 -0400 |
commit | c97cf5fd94b390ae86e016e0562d0d2fd3207d77 (patch) | |
tree | 082cd4bab4d8268298e1d193a0ac0d30433df257 | |
parent | 269a0192b68ca653bcc1e9d1990453ba3edc564c (diff) | |
download | serd-c97cf5fd94b390ae86e016e0562d0d2fd3207d77.tar.gz serd-c97cf5fd94b390ae86e016e0562d0d2fd3207d77.tar.bz2 serd-c97cf5fd94b390ae86e016e0562d0d2fd3207d77.zip |
Drop graphs when writing Turtle output
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/writer.c | 16 | ||||
-rw-r--r-- | test/test_reader_writer.c | 2 |
3 files changed, 12 insertions, 9 deletions
@@ -1,5 +1,6 @@ serd (0.32.5) unstable; urgency=medium + * Drop graphs when writing Turtle output * Fix handling of some invalid EOF cases in lax mode * Fix invalid characters in error messages * Fix reading numbers with no space before the final dot @@ -7,7 +8,7 @@ serd (0.32.5) unstable; urgency=medium * Refuse to write incoherent statements * Remove project and version number from man page OS field - -- David Robillard <d@drobilla.net> Tue, 25 Feb 2025 22:59:32 +0000 + -- David Robillard <d@drobilla.net> Sun, 16 Mar 2025 22:02:00 +0000 serd (0.32.4) stable; urgency=medium diff --git a/src/writer.c b/src/writer.c index 1c96ca13..7e4a1060 100644 --- a/src/writer.c +++ b/src/writer.c @@ -953,15 +953,17 @@ serd_writer_write_statement(SerdWriter* const writer, } // Separate graphs if necessary - if ((graph && !serd_node_equals(graph, &writer->context.graph)) || - (!graph && writer->context.graph.type)) { + const SerdNode* const out_graph = writer->syntax == SERD_TRIG ? graph : NULL; + if ((out_graph && !serd_node_equals(out_graph, &writer->context.graph)) || + (!out_graph && writer->context.graph.type)) { TRY(st, terminate_context(writer)); reset_context(writer, RESET_GRAPH | RESET_INDENT); TRY(st, write_newline(writer)); - if (graph) { - TRY(st, write_node(writer, graph, datatype, lang, FIELD_GRAPH, flags)); + if (out_graph) { + TRY(st, + write_node(writer, out_graph, datatype, lang, FIELD_GRAPH, flags)); TRY(st, write_sep(writer, SEP_GRAPH_BEGIN)); - copy_node(&writer->context.graph, graph); + copy_node(&writer->context.graph, out_graph); } } @@ -1042,7 +1044,7 @@ serd_writer_write_statement(SerdWriter* const writer, const bool is_list = (flags & SERD_LIST_S_BEGIN); push_context(writer, is_list ? CTX_LIST : CTX_BLANK, - serd_node_copy(graph), + serd_node_copy(out_graph), serd_node_copy(subject), is_list ? SERD_NODE_NULL : serd_node_copy(predicate)); } @@ -1051,7 +1053,7 @@ serd_writer_write_statement(SerdWriter* const writer, // Push context for anonymous or list object if necessary push_context(writer, (flags & SERD_LIST_O_BEGIN) ? CTX_LIST : CTX_BLANK, - serd_node_copy(graph), + serd_node_copy(out_graph), serd_node_copy(object), SERD_NODE_NULL); } diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 49821242..ceaae30f 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -144,7 +144,7 @@ static void test_write_errors(void) { // Syntax-keyed array of output document sizes - static const size_t max_offsets[] = {0, 465, 1911, 2003, 465}; + static const size_t max_offsets[] = {0, 451, 1911, 2003, 465}; for (unsigned s = 1; s <= (unsigned)SERD_TRIG; ++s) { const SerdSyntax syntax = (SerdSyntax)s; |