aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-03 20:08:50 +0000
committerDavid Robillard <d@drobilla.net>2011-02-03 20:08:50 +0000
commit4d7ad7760097f9dd01094f1a581f4d1ee4bf28a5 (patch)
tree58908ca1e345a6ac326a6d0b012fb4e717d4f391
parent051f8e0bfdd0083f152197e1da6db70af0bb9793 (diff)
downloadserd-4d7ad7760097f9dd01094f1a581f4d1ee4bf28a5.tar.gz
serd-4d7ad7760097f9dd01094f1a581f4d1ee4bf28a5.tar.bz2
serd-4d7ad7760097f9dd01094f1a581f4d1ee4bf28a5.zip
Add ability to set blank node prefix for parsing several files without conflict.
git-svn-id: http://svn.drobilla.net/serd/trunk@91 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--serd/serd.h12
-rw-r--r--src/reader.c18
2 files changed, 28 insertions, 2 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 0b90cde7..d7115054 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -281,6 +281,18 @@ serd_reader_new(SerdSyntax syntax,
SerdStatementSink statement_sink,
SerdEndSink end_sink);
+/** Set a prefix to be added to all blank node identifiers.
+ * This is useful when multiple files are to be parsed into the same output
+ * (e.g. a store, or other files). Since Serd preserves blank node IDs, this
+ * could cause conflicts where two non-equivalent blank nodes are merged,
+ * resulting in corrupt data. By setting a unique blank node prefix for
+ * each parsed file, this can be avoided, while preserving blank node names.
+ */
+SERD_API
+void
+serd_reader_set_blank_prefix(SerdReader reader,
+ const uint8_t* prefix);
+
/** Read @a file. */
SERD_API
bool
diff --git a/src/reader.c b/src/reader.c
index 226c359a..79b61385 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -85,6 +85,7 @@ struct SerdReaderImpl {
SerdStack stack;
Cursor cur;
uint8_t* buf;
+ const uint8_t* blank_prefix;
unsigned next_id;
int err;
uint8_t* read_buf;
@@ -976,8 +977,12 @@ read_nodeID(SerdReader reader)
static Ref
blank_id(SerdReader reader)
{
- char str[32];
- const int len = snprintf(str, sizeof(str), "genid%u", reader->next_id++);
+ const char* prefix = reader->blank_prefix
+ ? (const char*)reader->blank_prefix
+ : "genid";
+ char str[32]; // FIXME: ensure length of reader->blank_prefix is OK
+ const int len = snprintf(str, sizeof(str), "%s%u",
+ prefix, reader->next_id++);
return push_string(reader, str, len + 1);
}
@@ -1356,6 +1361,7 @@ serd_reader_new(SerdSyntax syntax,
me->fd = 0;
me->stack = serd_stack_new(STACK_PAGE_SIZE);
me->cur = cur;
+ me->blank_prefix = NULL;
me->next_id = 1;
me->read_buf = 0;
me->read_head = 0;
@@ -1392,6 +1398,14 @@ serd_reader_free(SerdReader reader)
}
SERD_API
+void
+serd_reader_set_blank_prefix(SerdReader reader,
+ const uint8_t* prefix)
+{
+ reader->blank_prefix = prefix;
+}
+
+SERD_API
bool
serd_reader_read_file(SerdReader me, FILE* file, const uint8_t* name)
{