From 8c4e3097517e95c8c6ff67f0a972525bfeb3bb1d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 2 Oct 2022 18:19:49 -0400 Subject: Add serd_world_get_blank() --- src/world.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index c3c3660f..ececd646 100644 --- a/src/world.c +++ b/src/world.c @@ -3,9 +3,12 @@ #include "world.h" +#include "node.h" #include "serd_config.h" #include "system.h" +#include "serd/string_view.h" + #if defined(USE_POSIX_FADVISE) # include #endif @@ -14,6 +17,7 @@ #include #include #include +#include FILE* serd_world_fopen(SerdWorld* world, const char* path, const char* mode) @@ -83,13 +87,43 @@ serd_world_errorf(const SerdWorld* const world, SerdWorld* serd_world_new(void) { - return (SerdWorld*)calloc(1, sizeof(SerdWorld)); + SerdWorld* world = (SerdWorld*)calloc(1, sizeof(SerdWorld)); + SerdNode* blank_node = serd_new_blank(serd_string("b00000000000")); + + if (!world || !blank_node) { + serd_node_free(blank_node); + free(world); + return NULL; + } + + world->blank_node = blank_node; + + return world; } void serd_world_free(SerdWorld* const world) { - free(world); + if (world) { + serd_node_free(world->blank_node); + free(world); + } +} + +const SerdNode* +serd_world_get_blank(SerdWorld* const world) +{ +#define BLANK_CHARS 12 + + char* buf = serd_node_buffer(world->blank_node); + memset(buf, 0, BLANK_CHARS + 1); + + world->blank_node->length = + (size_t)snprintf(buf, BLANK_CHARS + 1, "b%u", ++world->next_blank_id); + + return world->blank_node; + +#undef BLANK_CHARS } void -- cgit v1.2.1