aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-14 16:05:10 +0200
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit672e90382da08efa8f593fdc9081e31d0e548fa0 (patch)
tree3f70c13dda1e60e7b058c750002ec320bfaa6a73 /src/writer.c
parentfff826f406e0b9975fd8672041e50dd1a342339f (diff)
downloadserd-672e90382da08efa8f593fdc9081e31d0e548fa0.tar.gz
serd-672e90382da08efa8f593fdc9081e31d0e548fa0.tar.bz2
serd-672e90382da08efa8f593fdc9081e31d0e548fa0.zip
Merge datatype/language into node
This moves closer to the sord API, and is more convenient in most cases.
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c80
1 files changed, 35 insertions, 45 deletions
diff --git a/src/writer.c b/src/writer.c
index a0325243..5aad6d29 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -143,8 +143,6 @@ typedef enum { RESET_GRAPH = 1U << 0U, RESET_INDENT = 1U << 1U } ResetFlag;
SERD_NODISCARD static SerdStatus
write_node(SerdWriter* writer,
const SerdNode* node,
- const SerdNode* datatype,
- const SerdNode* lang,
Field field,
SerdStatementFlags flags);
@@ -667,15 +665,15 @@ reset_context(SerdWriter* writer, const unsigned flags)
}
SERD_NODISCARD static SerdStatus
-write_literal(SerdWriter* writer,
- const SerdNode* node,
- const SerdNode* datatype,
- const SerdNode* lang,
- SerdStatementFlags flags)
+write_literal(SerdWriter* const writer,
+ const SerdNode* const node,
+ const SerdStatementFlags flags)
{
- SerdStatus st = SERD_SUCCESS;
- const char* const node_str = serd_node_string(node);
- const char* const type_uri = datatype ? serd_node_string(datatype) : NULL;
+ SerdStatus st = SERD_SUCCESS;
+ const SerdNode* const datatype = serd_node_datatype(node);
+ const SerdNode* const lang = serd_node_language(node);
+ const char* const node_str = serd_node_string(node);
+ const char* const type_uri = datatype ? serd_node_string(datatype) : NULL;
if (supports_abbrev(writer) && type_uri) {
if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) &&
@@ -710,7 +708,7 @@ write_literal(SerdWriter* writer,
TRY(st, esink(serd_node_string(lang), lang->length, writer));
} else if (type_uri) {
TRY(st, esink("^^", 2, writer));
- return write_node(writer, datatype, NULL, NULL, FIELD_NONE, flags);
+ return write_node(writer, datatype, FIELD_NONE, flags);
}
return st;
@@ -862,18 +860,16 @@ write_blank(SerdWriter* const writer,
}
SERD_NODISCARD static SerdStatus
-write_node(SerdWriter* writer,
- const SerdNode* node,
- const SerdNode* datatype,
- const SerdNode* lang,
- Field field,
- SerdStatementFlags flags)
+write_node(SerdWriter* const writer,
+ const SerdNode* const node,
+ const Field field,
+ const SerdStatementFlags flags)
{
SerdStatus st = SERD_SUCCESS;
switch (node->type) {
case SERD_LITERAL:
- st = write_literal(writer, node, datatype, lang, flags);
+ st = write_literal(writer, node, flags);
break;
case SERD_URI:
st = write_uri_node(writer, node, field);
@@ -904,7 +900,7 @@ write_pred(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* pred)
{
SerdStatus st = SERD_SUCCESS;
- TRY(st, write_node(writer, pred, NULL, NULL, FIELD_PREDICATE, flags));
+ TRY(st, write_node(writer, pred, FIELD_PREDICATE, flags));
TRY(st, write_sep(writer, SEP_P_O));
serd_node_set(&writer->context.predicate, pred);
@@ -914,12 +910,10 @@ write_pred(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* pred)
}
SERD_NODISCARD static SerdStatus
-write_list_next(SerdWriter* writer,
- SerdStatementFlags flags,
- const SerdNode* predicate,
- const SerdNode* object,
- const SerdNode* datatype,
- const SerdNode* lang)
+write_list_next(SerdWriter* const writer,
+ const SerdStatementFlags flags,
+ const SerdNode* const predicate,
+ const SerdNode* const object)
{
SerdStatus st = SERD_SUCCESS;
@@ -929,7 +923,7 @@ write_list_next(SerdWriter* writer,
}
if (!strcmp(serd_node_string(predicate), NS_RDF "first")) {
- TRY(st, write_node(writer, object, datatype, lang, FIELD_OBJECT, flags));
+ TRY(st, write_node(writer, object, FIELD_OBJECT, flags));
} else {
TRY(st, write_sep(writer, SEP_LIST_SEP));
}
@@ -954,14 +948,12 @@ terminate_context(SerdWriter* writer)
}
SerdStatus
-serd_writer_write_statement(SerdWriter* writer,
- SerdStatementFlags flags,
- const SerdNode* graph,
- const SerdNode* subject,
- const SerdNode* predicate,
- const SerdNode* object,
- const SerdNode* datatype,
- const SerdNode* lang)
+serd_writer_write_statement(SerdWriter* const writer,
+ const SerdStatementFlags flags,
+ const SerdNode* const graph,
+ const SerdNode* const subject,
+ const SerdNode* const predicate,
+ const SerdNode* const object)
{
SerdStatus st = SERD_SUCCESS;
@@ -971,14 +963,14 @@ serd_writer_write_statement(SerdWriter* writer,
// Simple case: write a line of NTriples or NQuads
if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) {
- TRY(st, write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags));
+ TRY(st, write_node(writer, subject, FIELD_SUBJECT, flags));
TRY(st, esink(" ", 1, writer));
- TRY(st, write_node(writer, predicate, NULL, NULL, FIELD_PREDICATE, flags));
+ TRY(st, write_node(writer, predicate, FIELD_PREDICATE, flags));
TRY(st, esink(" ", 1, writer));
- TRY(st, write_node(writer, object, datatype, lang, FIELD_OBJECT, flags));
+ TRY(st, write_node(writer, object, FIELD_OBJECT, flags));
if (writer->syntax == SERD_NQUADS && graph) {
TRY(st, esink(" ", 1, writer));
- TRY(st, write_node(writer, graph, datatype, lang, FIELD_GRAPH, flags));
+ TRY(st, write_node(writer, graph, FIELD_GRAPH, flags));
}
TRY(st, esink(" .\n", 3, writer));
return SERD_SUCCESS;
@@ -991,7 +983,7 @@ serd_writer_write_statement(SerdWriter* writer,
reset_context(writer, RESET_GRAPH | RESET_INDENT);
if (graph) {
TRY(st, write_newline(writer));
- TRY(st, write_node(writer, graph, datatype, lang, FIELD_GRAPH, flags));
+ TRY(st, write_node(writer, graph, FIELD_GRAPH, flags));
TRY(st, write_sep(writer, SEP_GRAPH_BEGIN));
serd_node_set(&writer->context.graph, graph);
}
@@ -1004,9 +996,7 @@ serd_writer_write_statement(SerdWriter* writer,
return esink("()", 2, writer);
}
- TRY_FAILING(
- st, write_list_next(writer, flags, predicate, object, datatype, lang));
-
+ TRY_FAILING(st, write_list_next(writer, flags, predicate, object));
if (st == SERD_FAILURE) { // Reached end of list
pop_context(writer);
return SERD_SUCCESS;
@@ -1040,7 +1030,7 @@ serd_writer_write_statement(SerdWriter* writer,
TRY(st, write_pred(writer, flags, predicate));
}
- TRY(st, write_node(writer, object, datatype, lang, FIELD_OBJECT, flags));
+ TRY(st, write_node(writer, object, FIELD_OBJECT, flags));
} else {
// No abbreviation
@@ -1053,7 +1043,7 @@ serd_writer_write_statement(SerdWriter* writer,
TRY(st, write_newline(writer));
}
- TRY(st, write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags));
+ TRY(st, write_node(writer, subject, FIELD_SUBJECT, flags));
if ((flags & (SERD_ANON_S_BEGIN | SERD_LIST_S_BEGIN))) {
TRY(st, write_sep(writer, SEP_ANON_S_P));
} else {
@@ -1071,7 +1061,7 @@ serd_writer_write_statement(SerdWriter* writer,
TRY(st, write_pred(writer, flags, predicate));
}
- TRY(st, write_node(writer, object, datatype, lang, FIELD_OBJECT, flags));
+ TRY(st, write_node(writer, object, FIELD_OBJECT, flags));
}
if (flags & (SERD_ANON_S_BEGIN | SERD_LIST_S_BEGIN)) {