aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-05-20 09:39:04 +0200
committerDavid Robillard <d@drobilla.net>2017-05-20 09:39:04 +0200
commit21211d73053d0a66a1da601472c68598cfc53595 (patch)
tree428493dc313387730f85ffda66111b8a888e8a15
parent221549c2580bb72ceb91cfff70e7295f65ce46bf (diff)
downloadserd-21211d73053d0a66a1da601472c68598cfc53595.tar.gz
serd-21211d73053d0a66a1da601472c68598cfc53595.tar.bz2
serd-21211d73053d0a66a1da601472c68598cfc53595.zip
Abstract more syntax specifics away from writer
-rw-r--r--src/writer.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/writer.c b/src/writer.c
index 8e57b681..3c3bbb48 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -49,7 +49,9 @@ typedef enum {
SEP_LIST_SEP, ///< List separator (whitespace)
SEP_LIST_END, ///< End of list (')')
SEP_GRAPH_BEGIN, ///< Start of graph ('{')
- SEP_GRAPH_END ///< End of graph ('}')
+ SEP_GRAPH_END, ///< End of graph ('}')
+ SEP_URI_BEGIN, ///< URI start quote ('<')
+ SEP_URI_END ///< URI end quote ('>')
} Sep;
typedef struct {
@@ -74,6 +76,8 @@ static const SepRule rules[] = {
{ ")", 1, 1, 0, 0 },
{ " {", 2, 0, 1, 1 },
{ " }", 2, 0, 1, 1 },
+ { "<", 1, 0, 0, 0 },
+ { ">", 1, 0, 0, 0 },
{ "\n", 1, 0, 1, 0 }
};
@@ -504,10 +508,10 @@ write_node(SerdWriter* writer,
"undefined namespace prefix `%s'\n", node->buf);
return false;
}
- sink("<", 1, writer);
+ write_sep(writer, SEP_URI_BEGIN);
write_uri(writer, uri_prefix.buf, uri_prefix.len);
write_uri(writer, suffix.buf, suffix.len);
- sink(">", 1, writer);
+ write_sep(writer, SEP_URI_END);
break;
case SERD_TURTLE:
case SERD_TRIG:
@@ -583,7 +587,7 @@ write_node(SerdWriter* writer,
write_uri(writer, suffix.buf, suffix.len);
break;
}
- sink("<", 1, writer);
+ write_sep(writer, SEP_URI_BEGIN);
if (writer->style & SERD_STYLE_RESOLVED) {
SerdURI in_base_uri, uri, abs_uri;
serd_env_get_base_uri(writer->env, &in_base_uri);
@@ -602,7 +606,7 @@ write_node(SerdWriter* writer,
} else {
write_uri(writer, node->buf, node->n_bytes);
}
- sink(">", 1, writer);
+ write_sep(writer, SEP_URI_END);
if (is_inline_start(writer, field, flags)) {
sink(" ;", 2, writer);
write_newline(writer);
@@ -815,10 +819,10 @@ SerdStatus
serd_writer_finish(SerdWriter* writer)
{
if (writer->context.subject.type) {
- sink(" .\n", 3, writer);
+ write_sep(writer, SEP_END_S);
}
if (writer->context.graph.type) {
- sink("}\n", 2, writer);
+ write_sep(writer, SEP_GRAPH_END);
}
serd_byte_sink_flush(&writer->byte_sink);
writer->indent = 0;