From a44d17c590b7abca9b4012154ed4beb78f988588 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 24 Feb 2013 07:07:19 +0000 Subject: Generate shorter blank node IDs like the new Turtle test suite. git-svn-id: http://svn.drobilla.net/serd/trunk@414 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/reader.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/reader.c b/src/reader.c index c97228d3..a754196e 100644 --- a/src/reader.c +++ b/src/reader.c @@ -971,12 +971,12 @@ read_nodeID(SerdReader* reader) } if (reader->syntax == SERD_TURTLE) { const char* const buf = (const char*)deref(reader, ref)->buf; - if (!strncmp(buf, "genid", 5)) { - memcpy((char*)buf, "docid", 5); // Prevent clash + if (buf[0] == 'b' && is_digit(buf[1])) { + ((char*)buf)[0] = 'B'; // Prevent clash reader->seen_genid = true; - } else if (reader->seen_genid && !strncmp(buf, "docid", 5)) { + } else if (reader->seen_genid && buf[0] == 'B') { r_err(reader, SERD_ERR_ID_CLASH, - "found both `genid' and `docid' IDs, prefix required\n"); + "found both `b' and `B' blank IDs, prefix required\n"); return pop_node(reader, ref); } } @@ -984,25 +984,25 @@ read_nodeID(SerdReader* reader) } static void -set_blank_id(SerdReader* reader, Ref ref, size_t buf_size) +set_blank_id(SerdReader* reader, Ref ref, const char* b, size_t buf_size) { SerdNode* node = deref(reader, ref); const char* prefix = reader->bprefix ? (const char*)reader->bprefix : ""; node->n_bytes = node->n_chars = snprintf( - (char*)node->buf, buf_size, "%sgenid%u", prefix, reader->next_id++); + (char*)node->buf, buf_size, "%s%s%u", prefix, b, reader->next_id++); } static size_t genid_size(SerdReader* reader) { - return reader->bprefix_len + 5 + 10 + 1; // + "genid" + UINT32_MAX + \0 + return reader->bprefix_len + 2 + 10 + 1; // + "el" + UINT32_MAX + \0 } static Ref -blank_id(SerdReader* reader) +blank_id(SerdReader* reader, const char* b) { Ref ref = push_node_padded(reader, genid_size(reader), SERD_BLANK, "", 0); - set_blank_id(reader, ref, genid_size(reader)); + set_blank_id(reader, ref, b, genid_size(reader)); return ref; } @@ -1026,7 +1026,7 @@ read_blank(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest) *ctx.flags |= (subject) ? SERD_ANON_S_BEGIN : SERD_ANON_O_BEGIN; } - *dest = blank_id(reader); + *dest = blank_id(reader, "b"); if (ctx.subject) { TRY_RET(emit_statement(reader, ctx, *dest, 0, 0)); } @@ -1183,7 +1183,7 @@ read_collection(SerdReader* reader, ReadContext ctx, Ref* dest) { eat_byte_safe(reader, '('); bool end = peek_delim(reader, ')'); - *dest = end ? reader->rdf_nil : blank_id(reader); + *dest = end ? reader->rdf_nil : blank_id(reader, "el"); if (ctx.subject) { // subject predicate _:head *ctx.flags |= (end ? 0 : SERD_LIST_O_BEGIN); @@ -1216,9 +1216,9 @@ read_collection(SerdReader* reader, ReadContext ctx, Ref* dest) /* Give rest a new ID. Done as late as possible to ensure it is used and > IDs generated by read_object above. */ if (!rest) { - rest = n2 = blank_id(reader); // First pass, push a new node + rest = n2 = blank_id(reader, "el"); // First pass, push nodex } else { - set_blank_id(reader, rest, genid_size(reader)); + set_blank_id(reader, rest, "el", genid_size(reader)); } } -- cgit v1.2.1