aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-25 02:13:27 +0000
committerDavid Robillard <d@drobilla.net>2011-12-25 02:13:27 +0000
commitb2effabfc5d02bab56bae00e7aa138a42bd7d3b6 (patch)
treeba2e9ab5af305b9661fc4e0e79318b8c6676cb85 /src/writer.c
parent2501f12f80c3eebed55e5b253ced5a29ac443949 (diff)
downloadserd-b2effabfc5d02bab56bae00e7aa138a42bd7d3b6.tar.gz
serd-b2effabfc5d02bab56bae00e7aa138a42bd7d3b6.tar.bz2
serd-b2effabfc5d02bab56bae00e7aa138a42bd7d3b6.zip
100% test coverage.
git-svn-id: http://svn.drobilla.net/serd/trunk@276 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/writer.c b/src/writer.c
index 96f8d1e4..c388188e 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -163,6 +163,8 @@ write_text(SerdWriter* writer, TextContext ctx,
c = in & 0x07;
} else {
fprintf(stderr, "Invalid UTF-8 at offset %zu: %X\n", i, in);
+ const uint8_t replacement_char[] = { 0xEF, 0xBF, 0xBD };
+ sink(replacement_char, sizeof(replacement_char), writer);
return false;
}
@@ -249,8 +251,6 @@ write_node(SerdWriter* writer,
SerdChunk uri_prefix;
SerdChunk uri_suffix;
switch (node->type) {
- case SERD_NOTHING:
- return false;
case SERD_BLANK:
if (writer->syntax != SERD_NTRIPLES
&& ((field == FIELD_SUBJECT && (flags & SERD_ANON_S_BEGIN))
@@ -350,11 +350,23 @@ write_node(SerdWriter* writer,
sink("<", 1, writer);
write_text(writer, WRITE_URI, node->buf, node->n_bytes, '>');
sink(">", 1, writer);
- return true;
+ default:
+ break;
}
return true;
}
+static inline bool
+is_resource(const SerdNode* node)
+{
+ switch (node->type) {
+ case SERD_URI: case SERD_CURIE: case SERD_BLANK:
+ return true;
+ default:
+ return false;
+ }
+}
+
SERD_API
SerdStatus
serd_writer_write_statement(SerdWriter* writer,
@@ -366,7 +378,12 @@ serd_writer_write_statement(SerdWriter* writer,
const SerdNode* object_datatype,
const SerdNode* object_lang)
{
- assert(subject && predicate && object);
+ if (!subject || !predicate || !object
+ || !subject->buf || !predicate->buf || !object->buf
+ || !is_resource(subject) || !is_resource(predicate)) {
+ return SERD_ERR_BAD_ARG;
+ }
+
switch (writer->syntax) {
case SERD_NTRIPLES:
write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags);
@@ -536,11 +553,9 @@ void
serd_writer_chop_blank_prefix(SerdWriter* writer,
const uint8_t* prefix)
{
- if (writer->bprefix) {
- free(writer->bprefix);
- writer->bprefix_len = 0;
- writer->bprefix = NULL;
- }
+ free(writer->bprefix);
+ writer->bprefix_len = 0;
+ writer->bprefix = NULL;
if (prefix) {
writer->bprefix_len = strlen((const char*)prefix);
writer->bprefix = malloc(writer->bprefix_len + 1);