From 6f03ae92415a7758fdc74f6720ec4955bc67fc0c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 14 Aug 2020 16:05:10 +0200 Subject: Merge datatype/language into node This moves closer to the sord API, and is more convenient in most cases. --- src/writer.c | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'src/writer.c') diff --git a/src/writer.c b/src/writer.c index 6df55ada..5437f659 100644 --- a/src/writer.c +++ b/src/writer.c @@ -116,8 +116,6 @@ typedef enum { WRITE_STRING, WRITE_LONG_STRING } TextContext; static bool write_node(SerdWriter* writer, const SerdNode* node, - const SerdNode* datatype, - const SerdNode* lang, Field field, SerdStatementFlags flags); @@ -509,12 +507,12 @@ is_inline_start(const SerdWriter* writer, Field field, SerdStatementFlags flags) static bool write_literal(SerdWriter* writer, const SerdNode* node, - const SerdNode* datatype, - const SerdNode* lang, SerdStatementFlags flags) { - const char* node_str = serd_node_string(node); - const char* type_uri = datatype ? serd_node_string(datatype) : NULL; + const SerdNode* datatype = serd_node_datatype(node); + const SerdNode* lang = serd_node_language(node); + const char* node_str = serd_node_string(node); + const char* type_uri = datatype ? serd_node_string(datatype) : NULL; if (supports_abbrev(writer) && type_uri) { if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) && (!strcmp(type_uri + sizeof(NS_XSD) - 1, "boolean") || @@ -550,7 +548,7 @@ write_literal(SerdWriter* writer, sink(serd_node_string(lang), lang->n_bytes, writer); } else if (type_uri) { sink("^^", 2, writer); - return write_node(writer, datatype, NULL, NULL, FIELD_NONE, flags); + return write_node(writer, datatype, FIELD_NONE, flags); } return true; } @@ -730,15 +728,13 @@ write_blank(SerdWriter* const writer, static bool write_node(SerdWriter* writer, const SerdNode* node, - const SerdNode* datatype, - const SerdNode* lang, Field field, SerdStatementFlags flags) { bool ret = false; switch (node->type) { case SERD_LITERAL: - ret = write_literal(writer, node, datatype, lang, flags); + ret = write_literal(writer, node, flags); break; case SERD_URI: ret = write_uri_node(writer, node, field, flags); @@ -763,7 +759,7 @@ is_resource(const SerdNode* node) static void write_pred(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* pred) { - write_node(writer, pred, NULL, NULL, FIELD_PREDICATE, flags); + write_node(writer, pred, FIELD_PREDICATE, flags); write_sep(writer, SEP_P_O); serd_node_set(&writer->context.predicate, pred); } @@ -772,9 +768,7 @@ static bool write_list_obj(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* predicate, - const SerdNode* object, - const SerdNode* datatype, - const SerdNode* lang) + const SerdNode* object) { if (!strcmp(serd_node_string(object), NS_RDF "nil")) { --writer->indent; @@ -784,7 +778,7 @@ write_list_obj(SerdWriter* writer, if (!strcmp(serd_node_string(predicate), NS_RDF "first")) { write_sep(writer, SEP_LIST_SEP); - write_node(writer, object, datatype, lang, FIELD_OBJECT, flags); + write_node(writer, object, FIELD_OBJECT, flags); } return false; @@ -796,9 +790,7 @@ serd_writer_write_statement(SerdWriter* writer, const SerdNode* graph, const SerdNode* subject, const SerdNode* predicate, - const SerdNode* object, - const SerdNode* datatype, - const SerdNode* lang) + const SerdNode* object) { if (!is_resource(subject) || !is_resource(predicate) || !object) { return SERD_ERR_BAD_ARG; @@ -812,14 +804,14 @@ serd_writer_write_statement(SerdWriter* writer, } while (0) if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) { - TRY(write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags)); + TRY(write_node(writer, subject, FIELD_SUBJECT, flags)); sink(" ", 1, writer); - TRY(write_node(writer, predicate, NULL, NULL, FIELD_PREDICATE, flags)); + TRY(write_node(writer, predicate, FIELD_PREDICATE, flags)); sink(" ", 1, writer); - TRY(write_node(writer, object, datatype, lang, FIELD_OBJECT, flags)); + TRY(write_node(writer, object, FIELD_OBJECT, flags)); if (writer->syntax == SERD_NQUADS && graph) { sink(" ", 1, writer); - TRY(write_node(writer, graph, datatype, lang, FIELD_GRAPH, flags)); + TRY(write_node(writer, graph, FIELD_GRAPH, flags)); } sink(" .\n", 3, writer); return SERD_SUCCESS; @@ -837,7 +829,7 @@ serd_writer_write_statement(SerdWriter* writer, reset_context(writer, true); if (graph) { - TRY(write_node(writer, graph, datatype, lang, FIELD_GRAPH, flags)); + TRY(write_node(writer, graph, FIELD_GRAPH, flags)); ++writer->indent; write_sep(writer, SEP_GRAPH_BEGIN); serd_node_set(&writer->context.graph, graph); @@ -845,7 +837,7 @@ serd_writer_write_statement(SerdWriter* writer, } if ((flags & SERD_LIST_CONT)) { - if (write_list_obj(writer, flags, predicate, object, datatype, lang)) { + if (write_list_obj(writer, flags, predicate, object)) { // Reached end of list if (--writer->list_depth == 0 && writer->list_subj) { reset_context(writer, false); @@ -862,7 +854,7 @@ serd_writer_write_statement(SerdWriter* writer, ++writer->indent; } write_sep(writer, SEP_END_O); - write_node(writer, object, datatype, lang, FIELD_OBJECT, flags); + write_node(writer, object, FIELD_OBJECT, flags); if (!(flags & SERD_ANON_O_BEGIN)) { --writer->indent; } @@ -871,7 +863,7 @@ serd_writer_write_statement(SerdWriter* writer, Sep sep = ctx(writer, FIELD_PREDICATE) ? SEP_END_P : SEP_S_P; write_sep(writer, sep); write_pred(writer, flags, predicate); - write_node(writer, object, datatype, lang, FIELD_OBJECT, flags); + write_node(writer, object, FIELD_OBJECT, flags); } } else { // No abbreviation @@ -886,7 +878,7 @@ serd_writer_write_statement(SerdWriter* writer, } if (!(flags & SERD_ANON_CONT)) { - write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags); + write_node(writer, subject, FIELD_SUBJECT, flags); ++writer->indent; write_sep(writer, SEP_S_P); } else { @@ -900,7 +892,7 @@ serd_writer_write_statement(SerdWriter* writer, write_pred(writer, flags, predicate); } - write_node(writer, object, datatype, lang, FIELD_OBJECT, flags); + write_node(writer, object, FIELD_OBJECT, flags); } if (flags & (SERD_ANON_S_BEGIN | SERD_ANON_O_BEGIN)) { -- cgit v1.2.1