diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/n3.c | 6 | ||||
-rw-r--r-- | src/reader.c | 2 | ||||
-rw-r--r-- | src/reader.h | 1 | ||||
-rw-r--r-- | src/serdi.c | 6 | ||||
-rw-r--r-- | src/writer.c | 58 |
5 files changed, 41 insertions, 32 deletions
@@ -1511,6 +1511,7 @@ read_base(SerdReader* const reader, const bool sparql, const bool token) } serd_node_zero_pad(uri); + TRY(st, serd_env_set_base_uri(reader->env, serd_node_string_view(uri))); TRY(st, serd_sink_write_base(reader->sink, uri)); read_ws_star(reader); @@ -1557,6 +1558,11 @@ read_prefixID(SerdReader* const reader, const bool sparql, const bool token) serd_node_zero_pad(name); serd_node_zero_pad(uri); + + TRY(st, + serd_env_set_prefix( + reader->env, serd_node_string_view(name), serd_node_string_view(uri))); + st = serd_sink_write_prefix(reader->sink, name, uri); if (!sparql) { diff --git a/src/reader.c b/src/reader.c index c2962bdb..f2d929ac 100644 --- a/src/reader.c +++ b/src/reader.c @@ -184,6 +184,7 @@ SerdReader* serd_reader_new(SerdWorld* const world, const SerdSyntax syntax, const SerdReaderFlags flags, + SerdEnv* const env, const SerdSink* const sink, const size_t stack_size) { @@ -195,6 +196,7 @@ serd_reader_new(SerdWorld* const world, me->world = world; me->sink = sink; + me->env = env; me->stack = serd_stack_new(stack_size, serd_node_align); me->syntax = syntax; me->flags = flags; diff --git a/src/reader.h b/src/reader.h index cc8656d3..2374d7de 100644 --- a/src/reader.h +++ b/src/reader.h @@ -45,6 +45,7 @@ struct SerdReaderImpl { SerdNode* rdf_rest; SerdNode* rdf_nil; SerdByteSource* source; + SerdEnv* env; SerdStack stack; SerdSyntax syntax; SerdReaderFlags flags; diff --git a/src/serdi.c b/src/serdi.c index 28cf870d..2acae921 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -89,6 +89,7 @@ static SerdStatus read_file(SerdWorld* const world, SerdSyntax syntax, const SerdReaderFlags flags, + SerdEnv* const env, const SerdSink* const sink, const size_t stack_size, const char* const filename, @@ -118,7 +119,8 @@ read_file(SerdWorld* const world, return SERD_ERR_UNKNOWN; } - SerdReader* reader = serd_reader_new(world, syntax, flags, sink, stack_size); + SerdReader* reader = + serd_reader_new(world, syntax, flags, env, sink, stack_size); serd_reader_add_blank_prefix(reader, add_prefix); @@ -346,6 +348,7 @@ main(int argc, char** argv) serd_reader_new(world, input_syntax ? input_syntax : SERD_TRIG, reader_flags, + env, serd_writer_sink(writer), stack_size); @@ -390,6 +393,7 @@ main(int argc, char** argv) if ((st = read_file(world, input_syntax, reader_flags, + env, serd_writer_sink(writer), stack_size, inputs[i], 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; } |