aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-11 16:26:18 -0400
committerDavid Robillard <d@drobilla.net>2022-01-14 01:13:45 -0500
commitc857c0ae873ea7558e8d702ae4c588a21c220409 (patch)
tree4832c0e8c4c2590f9b72f37a925a44f16d99f76a /src/writer.c
parent0825ceb561b2f52cfa253cb8bb0613896f903363 (diff)
downloadserd-c857c0ae873ea7558e8d702ae4c588a21c220409.tar.gz
serd-c857c0ae873ea7558e8d702ae4c588a21c220409.tar.bz2
serd-c857c0ae873ea7558e8d702ae4c588a21c220409.zip
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.
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c58
1 files changed, 27 insertions, 31 deletions
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;
}