From 4584e03fce0d702160f8fde910bb3f24647d4036 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 22 Jul 2021 19:15:24 -0400 Subject: Rename serd_new_simple_node() to serd_new_token() Things get confusing without a term for this concept (which is roughly "nodes that are not annoying to construct"), so "token" it is. --- include/serd/serd.h | 15 ++++++++++----- src/node.c | 10 +++------- test/test_node.c | 7 ------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/include/serd/serd.h b/include/serd/serd.h index ded613a9..2bda9829 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -600,15 +600,20 @@ typedef enum { } SerdNodeType; /** - Create a new "simple" node that is just a string. + Create a new "token" node that is just a string. - A "simple" node has no associated language or datatype. This can be used to - efficiently create nodes from an already measured string or slice of a - buffer, which avoids a strlen compared to the friendly constructors. + "Token" is just a shorthand used in this API to refer to a node that is not + a typed or tagged literal. This can be used to create URIs, blank nodes, + variables, and simple string literals. + + Note that string literals constructed with this function will have no flags + set, and so will be written as "short" literals (not triple-quoted). To + construct long literals, use the more advanced serd_new_literal() with + #SERD_IS_LONG. */ SERD_API SerdNode* SERD_ALLOCATED -serd_new_simple_node(SerdNodeType type, SerdStringView string); +serd_new_token(SerdNodeType type, SerdStringView string); /// Create a new plain literal string node from `str` SERD_API diff --git a/src/node.c b/src/node.c index 9468325b..088ab058 100644 --- a/src/node.c +++ b/src/node.c @@ -167,12 +167,8 @@ result(const SerdStatus status, const size_t count) } SerdNode* -serd_new_simple_node(const SerdNodeType type, const SerdStringView str) +serd_new_token(const SerdNodeType type, const SerdStringView str) { - if (type != SERD_BLANK && type != SERD_URI && type != SERD_VARIABLE) { - return NULL; - } - SerdNodeFlags flags = 0u; const size_t length = str.buf ? str.len : 0u; SerdNode* node = serd_node_malloc(length, flags, type); @@ -288,7 +284,7 @@ serd_new_literal(const SerdStringView string, SerdNode* serd_new_blank(const SerdStringView str) { - return serd_new_simple_node(SERD_BLANK, str); + return serd_new_token(SERD_BLANK, str); } ExessResult @@ -463,7 +459,7 @@ serd_node_compare(const SerdNode* const a, const SerdNode* const b) SerdNode* serd_new_uri(const SerdStringView str) { - return serd_new_simple_node(SERD_URI, str); + return serd_new_token(SERD_URI, str); } SerdNode* diff --git a/test/test_node.c b/test/test_node.c index ef17afe9..efd93ddd 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -449,12 +449,6 @@ test_node_from_substring(void) serd_node_free(a_b); } -static void -test_simple_node(void) -{ - assert(!serd_new_simple_node(SERD_LITERAL, SERD_STRING("Literal"))); -} - static void check_copy_equals(const SerdNode* const node) { @@ -602,7 +596,6 @@ main(void) test_node_equals(); test_node_from_syntax(); test_node_from_substring(); - test_simple_node(); test_literal(); test_blank(); test_compare(); -- cgit v1.2.1