diff options
author | David Robillard <d@drobilla.net> | 2023-03-27 05:39:26 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 7ffa2c0488fcd96c3c12713e5650633eb03e91f7 (patch) | |
tree | 9ca96bb40f71b6c37789ae641af75e39a2751c18 /src/writer.c | |
parent | 5e4538756d601e6a941c5290777af95ea8848e1a (diff) | |
download | serd-7ffa2c0488fcd96c3c12713e5650633eb03e91f7.tar.gz serd-7ffa2c0488fcd96c3c12713e5650633eb03e91f7.tar.bz2 serd-7ffa2c0488fcd96c3c12713e5650633eb03e91f7.zip |
[WIP] 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.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/writer.c b/src/writer.c index 329a29ad..05be0500 100644 --- a/src/writer.c +++ b/src/writer.c @@ -131,7 +131,7 @@ struct SerdWriterImpl { SerdSink iface; SerdSyntax syntax; SerdWriterFlags flags; - SerdEnv* env; + const SerdEnv* env; SerdNode* root_node; SerdURIView root_uri; WriteContext* anon_stack; @@ -1367,7 +1367,7 @@ SerdWriter* serd_writer_new(SerdWorld* world, SerdSyntax syntax, SerdWriterFlags flags, - SerdEnv* env, + const SerdEnv* env, SerdOutputStream* output, size_t block_size) { @@ -1426,20 +1426,15 @@ serd_writer_set_base_uri(SerdWriter* writer, const SerdNode* uri) { assert(writer); + SerdStatus st = SERD_SUCCESS; + if (uri && serd_node_type(uri) != SERD_URI) { return SERD_BAD_ARG; } - if (serd_node_equals(serd_env_base_uri(writer->env), uri)) { - return SERD_SUCCESS; - } - const SerdStringView uri_string = uri ? serd_node_string_view(uri) : serd_empty_string(); - SerdStatus st = SERD_SUCCESS; - TRY(st, serd_env_set_base_uri(writer->env, uri_string)); - if (uri && (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG)) { TRY(st, terminate_context(writer)); TRY(st, esink("@base <", 7, writer)); @@ -1476,16 +1471,16 @@ serd_writer_set_prefix(SerdWriter* writer, { SerdStatus st = SERD_SUCCESS; - TRY(st, - serd_env_set_prefix( - writer->env, serd_node_string_view(name), serd_node_string_view(uri))); + if (name->type != SERD_LITERAL || uri->type != SERD_URI) { + return SERD_BAD_ARG; + } if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) { TRY(st, terminate_context(writer)); TRY(st, esink("@prefix ", 8, writer)); TRY(st, esink(serd_node_string(name), name->length, writer)); TRY(st, esink(": <", 3, writer)); - TRY(st, ewrite_uri(writer, serd_node_string(uri), uri->length)); + TRY(st, write_uri_from_node(writer, uri)); TRY(st, esink(">", 1, writer)); writer->last_sep = SEP_NODE; TRY(st, write_sep(writer, writer->context.flags, SEP_END_DIRECT)); |