diff options
author | David Robillard <d@drobilla.net> | 2018-04-29 18:36:11 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:58 +0100 |
commit | 5d65a0b7b687ffbbd624d75b42ac3336ce353c39 (patch) | |
tree | 2d99317b187bd28d628c6a45ee620e39c68a0d0d | |
parent | 48a9bed4cf7dc2b81acb6c645f7d053e1b9ead6d (diff) | |
download | serd-5d65a0b7b687ffbbd624d75b42ac3336ce353c39.tar.gz serd-5d65a0b7b687ffbbd624d75b42ac3336ce353c39.tar.bz2 serd-5d65a0b7b687ffbbd624d75b42ac3336ce353c39.zip |
Add blank node API
-rw-r--r-- | serd/serd.h | 10 | ||||
-rw-r--r-- | src/node.c | 14 | ||||
-rw-r--r-- | tests/env_test.c | 3 | ||||
-rw-r--r-- | tests/serd_test.c | 13 |
4 files changed, 40 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h index 8fdea919..41a1f30d 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -489,6 +489,16 @@ serd_node_new_literal(const char* str, const char* lang); /** + Create a new blank node. + + Note this function measures `str`, which is a common bottleneck. + Use sord_node_from_serd_node() instead if `str` is already measured. +*/ +SERD_API +SerdNode* +serd_node_new_blank(const char* str); + +/** Simple wrapper for serd_node_new_uri() to resolve a URI node. */ SERD_API @@ -170,6 +170,20 @@ serd_node_new_literal(const char* str, } SerdNode* +serd_node_new_blank(const char* str) +{ + if (!str) { + return NULL; + } + + const size_t n_bytes = strlen(str); + SerdNode* node = serd_node_malloc(n_bytes, 0, SERD_BLANK); + memcpy(serd_node_buffer(node), str, n_bytes); + node->n_bytes = n_bytes; + return node; +} + +SerdNode* serd_node_copy(const SerdNode* node) { if (!node) { diff --git a/tests/env_test.c b/tests/env_test.c index bcdd996e..8e0c9205 100644 --- a/tests/env_test.c +++ b/tests/env_test.c @@ -34,6 +34,8 @@ count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri) static void test_env(void) { + SerdWorld* world = serd_world_new(); + SerdNode* u = serd_node_new_string(SERD_URI, "http://example.org/foo"); SerdNode* b = serd_node_new_string(SERD_CURIE, "invalid"); SerdNode* c = serd_node_new_string(SERD_CURIE, "eg.2:b"); @@ -90,6 +92,7 @@ test_env(void) serd_node_free(u); serd_env_free(env); + serd_world_free(world); } int diff --git a/tests/serd_test.c b/tests/serd_test.c index a99ce678..15a205db 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -501,6 +501,18 @@ test_relative_uri(void) } static void +test_blank(void) +{ + assert(!serd_node_new_blank(NULL)); + + SerdNode* blank = serd_node_new_blank("b0"); + assert(serd_node_length(blank) == 2); + assert(serd_node_flags(blank) == 0); + assert(!strcmp(serd_node_string(blank), "b0")); + serd_node_free(blank); +} + +static void test_writer(const char* const path) { FILE* fd = fopen(path, "wb"); @@ -698,6 +710,7 @@ main(void) test_literal(); test_uri_from_string(); test_relative_uri(); + test_blank(); test_read_chunks(); test_read_string(); |