diff options
author | David Robillard <d@drobilla.net> | 2011-05-12 00:32:14 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-05-12 00:32:14 +0000 |
commit | 9e9d85e3233a75b6a7ec00e306ba25f494af3013 (patch) | |
tree | 0f4783c74dd5183c6822c8f9ac89b256338ca3e1 /src/writer.c | |
parent | 126e208fa58bc787aa7e96990e83031dfcd463be (diff) | |
download | serd-9e9d85e3233a75b6a7ec00e306ba25f494af3013.tar.gz serd-9e9d85e3233a75b6a7ec00e306ba25f494af3013.tar.bz2 serd-9e9d85e3233a75b6a7ec00e306ba25f494af3013.zip |
Correctly abbreviate repeated inline blank node objects ("] , [").
git-svn-id: http://svn.drobilla.net/serd/trunk@170 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/writer.c b/src/writer.c index 13015d8c..56dedd57 100644 --- a/src/writer.c +++ b/src/writer.c @@ -28,10 +28,11 @@ typedef struct { SerdNode graph; SerdNode subject; SerdNode predicate; + SerdNode object; } WriteContext; static const WriteContext WRITE_CONTEXT_NULL = { - {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0} + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0} }; struct SerdWriterImpl { @@ -174,6 +175,8 @@ reset_context(SerdWriter* writer) serd_node_free(&writer->context.subject); if (writer->context.predicate.buf) serd_node_free(&writer->context.predicate); + if (writer->context.object.buf) + serd_node_free(&writer->context.object); writer->context = WRITE_CONTEXT_NULL; } @@ -197,6 +200,7 @@ write_node(SerdWriter* writer, ctx->graph = serd_node_copy(&writer->context.graph); ctx->subject = serd_node_copy(&writer->context.subject); ctx->predicate = serd_node_copy(&writer->context.predicate); + ctx->object = serd_node_copy(&writer->context.object); reset_context(writer); writer->context.subject = serd_node_copy(node); break; @@ -317,10 +321,15 @@ serd_writer_write_statement(SerdWriter* writer, if (serd_node_equals(subject, &writer->context.subject)) { if (serd_node_equals(predicate, &writer->context.predicate)) { // Abbreviate S P - ++writer->indent; - serd_writer_write_delim(writer, ','); - write_node(writer, object, object_datatype, object_lang); - --writer->indent; + if (writer->context.object.type == SERD_ANON_BEGIN) { + writer->sink(" , ", 3, writer->stream); + write_node(writer, object, object_datatype, object_lang); + } else { + ++writer->indent; + serd_writer_write_delim(writer, ','); + write_node(writer, object, object_datatype, object_lang); + --writer->indent; + } } else { // Abbreviate S if (writer->context.predicate.buf) { @@ -333,6 +342,9 @@ serd_writer_write_statement(SerdWriter* writer, if (writer->context.predicate.buf) serd_node_free(&writer->context.predicate); writer->context.predicate = serd_node_copy(predicate); + if (writer->context.object.buf) + serd_node_free(&writer->context.object); + writer->context.object = serd_node_copy(object); writer->sink(" ", 1, writer->stream); write_node(writer, object, object_datatype, object_lang); } @@ -374,7 +386,8 @@ serd_writer_write_statement(SerdWriter* writer, const WriteContext new_context = { serd_node_copy(graph), serd_node_copy(subject), - serd_node_copy(predicate) }; + serd_node_copy(predicate), + serd_node_copy(object) }; reset_context(writer); writer->context = new_context; return SERD_SUCCESS; |