From c857c0ae873ea7558e8d702ae4c588a21c220409 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 11 Jul 2021 16:26:18 -0400 Subject: Move SerdEnv mutation from writer to reader Writing having side-effects seems questionable in general, and this prepares things for expanding URIs in the reader. --- src/writer.c | 58 +++++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) (limited to 'src/writer.c') diff --git a/src/writer.c b/src/writer.c index 3d4cad19..a0e5f3a3 100644 --- a/src/writer.c +++ b/src/writer.c @@ -120,7 +120,7 @@ struct SerdWriterImpl { SerdSink iface; SerdSyntax syntax; SerdWriterFlags flags; - SerdEnv* env; + const SerdEnv* env; SerdNode* root_node; SerdURIView root_uri; WriteContext* anon_stack; @@ -1315,7 +1315,7 @@ SerdWriter* serd_writer_new(SerdWorld* world, SerdSyntax syntax, SerdWriterFlags flags, - SerdEnv* env, + const SerdEnv* env, SerdByteSink* byte_sink) { const WriteContext context = WRITE_CONTEXT_NULL; @@ -1362,23 +1362,22 @@ serd_writer_set_base_uri(SerdWriter* writer, const SerdNode* uri) return SERD_ERR_BAD_ARG; } - SerdStatus st = - serd_env_set_base_uri(writer->env, serd_node_string_view(uri)); + SerdStatus st = SERD_SUCCESS; - if (!st) { - if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) { - if (ctx(writer, SERD_GRAPH) || ctx(writer, SERD_SUBJECT)) { - TRY(st, esink(" .\n\n", 4, writer)); - reset_context(writer, true); - } - TRY(st, esink("@base <", 7, writer)); - TRY(st, esink(serd_node_string(uri), uri->length, writer)); - TRY(st, esink("> .\n", 4, writer)); + if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) { + if (ctx(writer, SERD_GRAPH) || ctx(writer, SERD_SUBJECT)) { + TRY(st, esink(" .\n\n", 4, writer)); + reset_context(writer, true); } - writer->indent = 0; - reset_context(writer, true); + + TRY(st, esink("@base <", 7, writer)); + TRY(st, esink(serd_node_string(uri), uri->length, writer)); + TRY(st, esink("> .\n", 4, writer)); } + writer->indent = 0; + reset_context(writer, true); + return st; } @@ -1406,27 +1405,24 @@ serd_writer_set_prefix(SerdWriter* writer, return SERD_ERR_BAD_ARG; } - SerdStatus st = serd_env_set_prefix( - writer->env, serd_node_string_view(name), serd_node_string_view(uri)); - - if (!st) { - if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) { - if (ctx(writer, SERD_GRAPH) || ctx(writer, SERD_SUBJECT)) { - TRY(st, esink(" .\n\n", 4, writer)); - reset_context(writer, true); - } + SerdStatus st = SERD_SUCCESS; - TRY(st, esink("@prefix ", 8, writer)); - TRY(st, esink(serd_node_string(name), name->length, writer)); - TRY(st, esink(": <", 3, writer)); - TRY(st, write_uri_from_node(writer, uri)); - TRY(st, esink("> .\n", 4, writer)); + if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) { + if (ctx(writer, SERD_GRAPH) || ctx(writer, SERD_SUBJECT)) { + TRY(st, esink(" .\n\n", 4, writer)); + reset_context(writer, true); } - writer->indent = 0; - reset_context(writer, true); + TRY(st, esink("@prefix ", 8, writer)); + TRY(st, esink(serd_node_string(name), name->length, writer)); + TRY(st, esink(": <", 3, writer)); + TRY(st, write_uri_from_node(writer, uri)); + TRY(st, esink("> .\n", 4, writer)); } + writer->indent = 0; + reset_context(writer, true); + return st; } -- cgit v1.2.1