aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-16 17:01:43 +0000
committerDavid Robillard <d@drobilla.net>2011-02-16 17:01:43 +0000
commitb492b51733adc575c4dbb862d270d71671b39fee (patch)
tree326396aa50ca21593d16abec55c6822575b14145
parent05a25de591ed61bb4c60c9c93d56fb6ad78a2141 (diff)
downloadserd-b492b51733adc575c4dbb862d270d71671b39fee.tar.gz
serd-b492b51733adc575c4dbb862d270d71671b39fee.tar.bz2
serd-b492b51733adc575c4dbb862d270d71671b39fee.zip
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
-rw-r--r--src/writer.c22
1 files changed, 21 insertions, 1 deletions
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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#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);
}