diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/world.c | 12 | ||||
-rw-r--r-- | src/world.h | 16 | ||||
-rw-r--r-- | src/writer.c | 18 |
3 files changed, 32 insertions, 14 deletions
diff --git a/src/world.c b/src/world.c index 351f246a..7b8ea5b7 100644 --- a/src/world.c +++ b/src/world.c @@ -21,6 +21,7 @@ #include "cursor.h" #include "node.h" #include "serd_config.h" +#include "serd_internal.h" #include <errno.h> #include <stdarg.h> @@ -84,8 +85,18 @@ SerdWorld* serd_world_new(void) { SerdWorld* world = (SerdWorld*)calloc(1, sizeof(SerdWorld)); + SerdNodes* nodes = serd_nodes_new(); + + world->rdf_first = serd_nodes_manage(nodes, serd_new_uri(NS_RDF "first")); + world->rdf_nil = serd_nodes_manage(nodes, serd_new_uri(NS_RDF "nil")); + world->rdf_rest = serd_nodes_manage(nodes, serd_new_uri(NS_RDF "rest")); + world->rdf_type = serd_nodes_manage(nodes, serd_new_uri(NS_RDF "type")); + world->xsd_boolean = serd_nodes_manage(nodes, serd_new_uri(NS_XSD "boolean")); + world->xsd_decimal = serd_nodes_manage(nodes, serd_new_uri(NS_XSD "decimal")); + world->xsd_integer = serd_nodes_manage(nodes, serd_new_uri(NS_XSD "integer")); world->blank_node = serd_new_blank("b0000000000"); + world->nodes = nodes; return world; } @@ -94,6 +105,7 @@ void serd_world_free(SerdWorld* world) { serd_node_free(world->blank_node); + serd_nodes_free(world->nodes); free(world); } diff --git a/src/world.h b/src/world.h index 6d32b529..11f36e21 100644 --- a/src/world.h +++ b/src/world.h @@ -23,10 +23,18 @@ #include <stdio.h> struct SerdWorldImpl { - SerdErrorSink error_sink; - void* error_handle; - uint32_t next_blank_id; - SerdNode* blank_node; + SerdNodes* nodes; + SerdErrorSink error_sink; + void* error_handle; + SerdNode* blank_node; + const SerdNode* rdf_first; + const SerdNode* rdf_nil; + const SerdNode* rdf_rest; + const SerdNode* rdf_type; + const SerdNode* xsd_boolean; + const SerdNode* xsd_decimal; + const SerdNode* xsd_integer; + uint32_t next_blank_id; }; FILE* serd_world_fopen(SerdWorld* world, const char* path, const char* mode); diff --git a/src/writer.c b/src/writer.c index 776660f6..27486fb2 100644 --- a/src/writer.c +++ b/src/writer.c @@ -16,7 +16,6 @@ #include "env.h" #include "node.h" -#include "serd_internal.h" #include "sink.h" #include "stack.h" #include "string_utils.h" @@ -440,13 +439,11 @@ write_literal(SerdWriter* writer, const char* node_str = serd_node_get_string(node); const char* type_uri = serd_node_get_string(datatype); if (supports_abbrev(writer) && type_uri) { - if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) && ( - !strcmp(type_uri + sizeof(NS_XSD) - 1, "boolean") || - !strcmp(type_uri + sizeof(NS_XSD) - 1, "integer"))) { + if (serd_node_equals(datatype, writer->world->xsd_boolean) || + serd_node_equals(datatype, writer->world->xsd_integer)) { sink(node_str, node->n_bytes, writer); return true; - } else if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) && - !strcmp(type_uri + sizeof(NS_XSD) - 1, "decimal") && + } else if (serd_node_equals(datatype, writer->world->xsd_decimal) && strchr(node_str, '.') && node_str[node->n_bytes - 1] != '.') { /* xsd:decimal literals without trailing digits, e.g. "5.", can @@ -509,9 +506,10 @@ write_uri_node(SerdWriter* const writer, const char* node_str = serd_node_get_string(node); const bool has_scheme = serd_uri_string_has_scheme(node_str); if (field == SERD_PREDICATE && supports_abbrev(writer) - && !strcmp(node_str, NS_RDF "type")) { + && serd_node_equals(node, writer->world->rdf_type)) { return sink("a", 1, writer) == 1; - } else if (supports_abbrev(writer) && !strcmp(node_str, NS_RDF "nil")) { + } else if (supports_abbrev(writer) && + serd_node_equals(node, writer->world->rdf_nil)) { return sink("()", 2, writer) == 2; } else if (has_scheme && supports_abbrev(writer) && serd_env_qualify_in_place(writer->env, node, &prefix, &suffix) && @@ -678,11 +676,11 @@ write_list_obj(SerdWriter* writer, const SerdNode* predicate, const SerdNode* object) { - if (!strcmp(serd_node_get_string(object), NS_RDF "nil")) { + if (serd_node_equals(object, writer->world->rdf_nil)) { --writer->indent; write_sep(writer, SEP_LIST_END); return true; - } else if (!strcmp(serd_node_get_string(predicate), NS_RDF "first")) { + } else if (serd_node_equals(predicate, writer->world->rdf_first)) { write_sep(writer, SEP_LIST_SEP); write_node(writer, object, SERD_OBJECT, flags); } |