diff options
author | David Robillard <d@drobilla.net> | 2011-05-18 02:00:03 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-05-18 02:00:03 +0000 |
commit | b92d598a22fdad8c96a1167362d4bb79015af006 (patch) | |
tree | bf4768c8b4357aafbee9218806f1fe80156dc356 /src/writer.c | |
parent | 88e6e9a333e99c304451b7755117928a213913ef (diff) | |
download | serd-b92d598a22fdad8c96a1167362d4bb79015af006.tar.gz serd-b92d598a22fdad8c96a1167362d4bb79015af006.tar.bz2 serd-b92d598a22fdad8c96a1167362d4bb79015af006.zip |
Add test to ensure blank node IDs don't clash with generated IDs.
Add handle destructor parameter to serd_reader_new.
Add serd_reader_get_handle.
Rename serd_reader_set_blank_prefix to serd_reader_add_blank_prefix.
Rename serd_reader_read_file to serd_reader_read_file_handle.
Add new serd_reader_read_file that takes a path/URI parameter.
Add serdi -i option to select input syntax.
Add serdi -p and -c options to add/chop a prefix to/from blank IDs.
Add optional base_uri parameter to serd_env_new.
Add serd_writer_chop_blank_prefix.
Bump version to 0.3.0.
git-svn-id: http://svn.drobilla.net/serd/trunk@183 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/src/writer.c b/src/writer.c index d0120cde..fafde07c 100644 --- a/src/writer.c +++ b/src/writer.c @@ -44,6 +44,8 @@ struct SerdWriterImpl { SerdSink sink; void* stream; WriteContext context; + uint8_t* bprefix; + size_t bprefix_len; unsigned indent; bool empty; }; @@ -214,7 +216,15 @@ write_node(SerdWriter* writer, } // else fall through case SERD_BLANK_ID: writer->sink("_:", 2, writer->stream); - writer->sink(node->buf, node->n_bytes, writer->stream); + if (writer->bprefix + && !strncmp((const char*)node->buf, (const char*)writer->bprefix, + writer->bprefix_len)) { + writer->sink(node->buf + writer->bprefix_len, + node->n_bytes - writer->bprefix_len, + writer->stream); + } else { + writer->sink(node->buf, node->n_bytes, writer->stream); + } break; case SERD_CURIE: switch (writer->syntax) { @@ -445,20 +455,39 @@ serd_writer_new(SerdSyntax syntax, { const WriteContext context = WRITE_CONTEXT_NULL; SerdWriter* writer = malloc(sizeof(struct SerdWriterImpl)); - writer->syntax = syntax; - writer->style = style; - writer->env = env; - writer->base_uri = base_uri ? *base_uri : SERD_URI_NULL; - writer->anon_stack = serd_stack_new(sizeof(WriteContext)); - writer->sink = sink; - writer->stream = stream; - writer->context = context; - writer->indent = 0; - writer->empty = true; + writer->syntax = syntax; + writer->style = style; + writer->env = env; + writer->base_uri = base_uri ? *base_uri : SERD_URI_NULL; + writer->anon_stack = serd_stack_new(sizeof(WriteContext)); + writer->sink = sink; + writer->stream = stream; + writer->context = context; + writer->bprefix = NULL; + writer->bprefix_len = 0; + writer->indent = 0; + writer->empty = true; return writer; } SERD_API +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; + } + if (prefix) { + writer->bprefix_len = strlen((const char*)prefix); + writer->bprefix = malloc(writer->bprefix_len + 1); + memcpy(writer->bprefix, prefix, writer->bprefix_len + 1); + } +} + +SERD_API SerdStatus serd_writer_set_base_uri(SerdWriter* writer, const SerdNode* uri) @@ -512,5 +541,6 @@ serd_writer_free(SerdWriter* writer) SerdWriter* const me = (SerdWriter*)writer; serd_writer_finish(me); serd_stack_free(&writer->anon_stack); + free(writer->bprefix); free(me); } |