From b492b51733adc575c4dbb862d270d71671b39fee Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 16 Feb 2011 17:01:43 +0000 Subject: Turtle rdf:type, xsd:decimal, xsd:integer, and xsd:float abbreviation. Automatically finish writing in serd_writer_free if necessary. git-svn-id: http://svn.drobilla.net/serd/trunk@99 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/writer.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/writer.c b/src/writer.c index 44d88b99..699cbaf7 100644 --- a/src/writer.c +++ b/src/writer.c @@ -20,9 +20,13 @@ #include #include #include +#include #include "serd_internal.h" +#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" +#define NS_XSD "http://www.w3.org/2001/XMLSchema#" + typedef struct { SerdNode graph; SerdNode subject; @@ -204,6 +208,15 @@ write_node(SerdWriter writer, } break; case SERD_LITERAL: + if (writer->syntax == SERD_TURTLE && datatype && datatype->buf) { + // TODO: compare against NS_XSD prefix once + if (!strcmp((const char*)datatype->buf, NS_XSD "boolean") + || !strcmp((const char*)datatype->buf, NS_XSD "decimal") + || !strcmp((const char*)datatype->buf, NS_XSD "integer")) { + writer->sink(node->buf, node->n_bytes - 1, writer->stream); + break; + } + } writer->sink("\"", 1, writer->stream); write_text(writer, WRITE_STRING, node->buf, node->n_bytes - 1, '"'); writer->sink("\"", 1, writer->stream); @@ -216,7 +229,12 @@ write_node(SerdWriter writer, } break; case SERD_URI: - if (!serd_uri_string_has_scheme(node->buf)) { + if ((writer->syntax == SERD_TURTLE) + && !strcmp((const char*)node->buf, NS_RDF "type")) { + writer->sink("a", 1, writer->stream); + return true; + } else if ((writer->style & SERD_STYLE_RESOLVED) + && !serd_uri_string_has_scheme(node->buf)) { SerdURI uri; if (serd_uri_parse(node->buf, &uri)) { SerdURI abs_uri; @@ -352,6 +370,7 @@ serd_writer_finish(SerdWriter writer) { if (writer->context.subject.buf) { writer->sink(" .\n", 3, writer->stream); + writer->context.subject.buf = NULL; } } @@ -421,6 +440,7 @@ void serd_writer_free(SerdWriter writer) { SerdWriter const me = (SerdWriter)writer; + serd_writer_finish(me); serd_stack_free(&writer->anon_stack); free(me); } -- cgit v1.2.1