aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--serd/serd.h10
-rw-r--r--src/node.c15
-rw-r--r--tests/serd_test.c14
3 files changed, 39 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index ae581886..7b24fd74 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -465,6 +465,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);
+
+/**
Return a deep copy of `node`.
*/
SERD_API
diff --git a/src/node.c b/src/node.c
index 742003fb..13af7ed6 100644
--- a/src/node.c
+++ b/src/node.c
@@ -160,6 +160,21 @@ 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;
+}
+
+SERD_API
+SerdNode*
serd_node_copy(const SerdNode* node)
{
if (!node) {
diff --git a/tests/serd_test.c b/tests/serd_test.c
index a7008e9f..5b60a03c 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -409,6 +409,20 @@ main(void)
serd_node_free(rel);
serd_node_free(base);
+ // Test serd_node_new_blank
+
+ if (serd_node_new_blank(NULL)) {
+ FAIL("Successfully created blank node from NULL string\n");
+ }
+
+ SerdNode* blank = serd_node_new_blank("b0");
+ if (serd_node_get_length(blank) != 2 ||
+ serd_node_get_flags(blank) != 0 ||
+ strcmp(serd_node_get_string(blank), "b0")) {
+ FAILF("Bad blank node %s\n", serd_node_get_string(blank));
+ }
+ serd_node_free(blank);
+
// Test SerdEnv
SerdWorld* world = serd_world_new();