aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-03-10 16:44:22 +0100
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit92c7329ede45876e3b7e7e84d09a2eb0c3f9440c (patch)
treef0395da5c35e98e82ba2a2fcbe71b944f9313281
parentaf5a7af4ac4aada57c2e95f47fef6dd7ff6a31b2 (diff)
downloadserd-92c7329ede45876e3b7e7e84d09a2eb0c3f9440c.tar.gz
serd-92c7329ede45876e3b7e7e84d09a2eb0c3f9440c.tar.bz2
serd-92c7329ede45876e3b7e7e84d09a2eb0c3f9440c.zip
Pass context flags to write_sep()
-rw-r--r--src/writer.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/writer.c b/src/writer.c
index b3ca783f..e342c23e 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -447,8 +447,10 @@ write_top_level_sep(SerdWriter* writer)
}
static bool
-write_sep(SerdWriter* writer, const Sep sep)
+write_sep(SerdWriter* writer, const SerdStatementFlags flags, Sep sep)
{
+ (void)flags;
+
const SepRule* rule = &rules[sep];
// Adjust indent, but tolerate if it would become negative
@@ -579,7 +581,7 @@ write_uri_node(SerdWriter* const writer,
const SerdStatementFlags flags)
{
if (is_inline_start(writer, field, flags)) {
- write_sep(writer, SEP_ANON_BEGIN);
+ write_sep(writer, flags, SEP_ANON_BEGIN);
sink(" == ", 4, writer);
}
@@ -662,7 +664,7 @@ write_curie(SerdWriter* const writer,
case SERD_TURTLE:
case SERD_TRIG:
if (is_inline_start(writer, field, flags)) {
- write_sep(writer, SEP_ANON_BEGIN);
+ write_sep(writer, flags, SEP_ANON_BEGIN);
sink(" == ", 4, writer);
}
write_lname(writer, serd_node_string(node), node->n_bytes);
@@ -682,10 +684,10 @@ write_blank(SerdWriter* const writer,
const char* node_str = serd_node_string(node);
if (supports_abbrev(writer)) {
if (is_inline_start(writer, field, flags)) {
- return write_sep(writer, SEP_ANON_BEGIN);
+ return write_sep(writer, flags, SEP_ANON_BEGIN);
} else if ((field == SERD_SUBJECT && (flags & SERD_LIST_S)) ||
(field == SERD_OBJECT && (flags & SERD_LIST_O))) {
- return write_sep(writer, SEP_LIST_BEGIN);
+ return write_sep(writer, flags, SEP_LIST_BEGIN);
} else if (field == SERD_SUBJECT && (flags & SERD_EMPTY_S)) {
writer->last_sep = SEP_NONE; // Treat "[]" like anode
return sink("[]", 2, writer) == 2;
@@ -736,7 +738,7 @@ static void
write_pred(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* pred)
{
write_node(writer, pred, SERD_PREDICATE, flags);
- write_sep(writer, SEP_P_O);
+ write_sep(writer, flags, SEP_P_O);
serd_node_set(&writer->context.predicate, pred);
}
@@ -747,14 +749,14 @@ write_list_obj(SerdWriter* writer,
const SerdNode* object)
{
if (serd_node_equals(object, writer->world->rdf_nil)) {
- write_sep(writer, SEP_LIST_END);
+ write_sep(writer, writer->context.flags, SEP_LIST_END);
return true;
}
if (serd_node_equals(predicate, writer->world->rdf_first)) {
write_node(writer, object, SERD_OBJECT, flags);
} else {
- write_sep(writer, SEP_LIST_SEP);
+ write_sep(writer, writer->context.flags, SEP_LIST_SEP);
}
return false;
@@ -803,17 +805,17 @@ serd_writer_write_statement(SerdWriter* writer,
if ((graph && !serd_node_equals(graph, writer->context.graph)) ||
(!graph && ctx(writer, SERD_GRAPH))) {
if (ctx(writer, SERD_SUBJECT)) {
- write_sep(writer, SEP_END_S);
+ write_sep(writer, writer->context.flags, SEP_END_S);
}
if (ctx(writer, SERD_GRAPH)) {
- write_sep(writer, SEP_GRAPH_END);
+ write_sep(writer, writer->context.flags, SEP_GRAPH_END);
}
write_top_level_sep(writer);
reset_context(writer, true);
if (graph) {
TRY(write_node(writer, graph, SERD_GRAPH, flags));
- write_sep(writer, SEP_GRAPH_BEGIN);
+ write_sep(writer, flags, SEP_GRAPH_BEGIN);
serd_node_set(&writer->context.graph, graph);
}
}
@@ -833,7 +835,7 @@ serd_writer_write_statement(SerdWriter* writer,
writer->context.indented_object = true;
}
- write_sep(writer, SEP_END_O);
+ write_sep(writer, writer->context.flags, SEP_END_O);
write_node(writer, object, SERD_OBJECT, flags);
} else {
// Abbreviate S
@@ -843,8 +845,8 @@ serd_writer_write_statement(SerdWriter* writer,
}
Sep sep = ctx(writer, SERD_PREDICATE) ? SEP_END_P : SEP_S_P;
- write_sep(writer, sep);
- write_pred(writer, flags, predicate);
+ write_sep(writer, writer->context.flags, sep);
+ write_pred(writer, writer->context.flags, predicate);
write_node(writer, object, SERD_OBJECT, flags);
}
} else {
@@ -855,8 +857,8 @@ serd_writer_write_statement(SerdWriter* writer,
}
if (serd_stack_is_empty(&writer->anon_stack)) {
- if (ctx(writer, SERD_SUBJECT)) {
- write_sep(writer, SEP_END_S); // Terminate last subject
+ if (ctx(writer, SERD_SUBJECT)) { // Terminate last subject
+ write_sep(writer, writer->context.flags, SEP_END_S);
}
write_top_level_sep(writer);
}
@@ -864,12 +866,12 @@ serd_writer_write_statement(SerdWriter* writer,
if (serd_stack_is_empty(&writer->anon_stack)) {
write_node(writer, subject, SERD_SUBJECT, flags);
if (!(flags & (SERD_ANON_S | SERD_LIST_S))) {
- write_sep(writer, SEP_S_P);
+ write_sep(writer, writer->context.flags, SEP_S_P);
} else if (flags & SERD_ANON_S) {
- write_sep(writer, SEP_ANON_S_P);
+ write_sep(writer, writer->context.flags, SEP_ANON_S_P);
}
} else {
- write_sep(writer, SEP_ANON_S_P);
+ write_sep(writer, writer->context.flags, SEP_ANON_S_P);
}
reset_context(writer, false);
@@ -918,7 +920,7 @@ serd_writer_end_anon(SerdWriter* writer,
"unexpected end of anonymous node\n");
}
- write_sep(writer, SEP_ANON_END);
+ write_sep(writer, writer->context.flags, SEP_ANON_END);
pop_context(writer);
if (serd_node_equals(node, writer->context.subject)) {
@@ -933,10 +935,10 @@ SerdStatus
serd_writer_finish(SerdWriter* writer)
{
if (ctx(writer, SERD_SUBJECT)) {
- write_sep(writer, SEP_END_S);
+ write_sep(writer, writer->context.flags, SEP_END_S);
}
if (ctx(writer, SERD_GRAPH)) {
- write_sep(writer, SEP_GRAPH_END);
+ write_sep(writer, writer->context.flags, SEP_GRAPH_END);
}
free_context(writer);
writer->indent = 0;