From 0db18e483f11ac2f9518d96e137d217040ed1339 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 31 Mar 2023 20:32:26 -0400 Subject: Add "contextual" output option This is mainly for developer or power-user cases, where one wants to look at some data for investigation or debugging. In such cases, it's common for the set of prefixes to be implicitly known (because they are baked in to the application, for example), so printing them just produces a large amount of redundant noise. That said, it can also be useful programmatically, because it allows several snippets to be written independently and ultimately concatenated (with a header to define the prefixes) without redundancy. --- src/writer.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/writer.c b/src/writer.c index 30b8bb4e..7b821145 100644 --- a/src/writer.c +++ b/src/writer.c @@ -1434,6 +1434,10 @@ serd_writer_set_prefix(SerdWriter* writer, if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) { TRY(st, terminate_context(writer)); + if (writer->flags & SERD_WRITE_CONTEXTUAL) { + return st; + } + TRY(st, esink("@prefix ", 8, writer)); TRY(st, esink(serd_node_string(name), name->length, writer)); TRY(st, esink(": <", 3, writer)); -- cgit v1.2.1