aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/world.c11
-rw-r--r--src/world.h16
-rw-r--r--src/writer.c18
3 files changed, 31 insertions, 14 deletions
diff --git a/src/world.c b/src/world.c
index 862676ee..7baeb4bc 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>
@@ -83,8 +84,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;
}
diff --git a/src/world.h b/src/world.h
index 99ef27b8..232d458f 100644
--- a/src/world.h
+++ b/src/world.h
@@ -22,10 +22,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;
+ uint32_t next_blank_id;
+ 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;
};
FILE* serd_world_fopen(SerdWorld* world, const char* path, const char* mode);
diff --git a/src/writer.c b/src/writer.c
index 3c782ae7..6a98147c 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"
@@ -438,13 +437,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
@@ -507,9 +504,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) &&
@@ -674,11 +672,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);
}