diff options
author | David Robillard <d@drobilla.net> | 2018-12-26 11:54:21 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:58 +0100 |
commit | 60bb4a81c03d6b0a08f9c858ff1a99bf3bcc602e (patch) | |
tree | 9905e430cf66ba4a8ffa4de9cc67e6d96ed878ad | |
parent | c4e1eb61f7b8262030344712537c8918f4949a20 (diff) | |
download | serd-60bb4a81c03d6b0a08f9c858ff1a99bf3bcc602e.tar.gz serd-60bb4a81c03d6b0a08f9c858ff1a99bf3bcc602e.tar.bz2 serd-60bb4a81c03d6b0a08f9c858ff1a99bf3bcc602e.zip |
Add serd_new_boolean()
-rw-r--r-- | serd/serd.h | 5 | ||||
-rw-r--r-- | src/node.c | 6 | ||||
-rw-r--r-- | src/static_nodes.h | 1 | ||||
-rw-r--r-- | tests/serd_test.c | 17 |
4 files changed, 29 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h index 433f38e8..cd2a7031 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -712,6 +712,11 @@ SERD_API SerdNode* serd_new_integer(int64_t i, const SerdNode* datatype); +/// Create a new node by serialising `b` into an xsd:boolean string +SERD_API +SerdNode* +serd_new_boolean(bool b); + /** Create a node by serialising `buf` into an xsd:base64Binary string @@ -675,6 +675,12 @@ serd_new_integer(int64_t i, const SerdNode* datatype) } SerdNode* +serd_new_boolean(bool b) +{ + return serd_new_typed_literal(b ? "true" : "false", &serd_xsd_boolean.node); +} + +SerdNode* serd_new_blob(const void* buf, size_t size, bool wrap_lines, diff --git a/src/static_nodes.h b/src/static_nodes.h index 430fa58c..1399f580 100644 --- a/src/static_nodes.h +++ b/src/static_nodes.h @@ -30,6 +30,7 @@ typedef struct StaticNode { {sizeof(NS_XSD #name) - 1, 0, SERD_URI}, NS_XSD #name}; DEFINE_XSD_NODE(base64Binary) +DEFINE_XSD_NODE(boolean) DEFINE_XSD_NODE(decimal) DEFINE_XSD_NODE(integer) diff --git a/tests/serd_test.c b/tests/serd_test.c index 7a9e67bd..34463f7e 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -305,6 +305,22 @@ test_integer_to_node(void) } static void +test_boolean(void) +{ + SerdNode* true_node = serd_new_boolean(true); + assert(!strcmp(serd_node_string(true_node), "true")); + assert(!strcmp(serd_node_string(serd_node_datatype(true_node)), + NS_XSD "boolean")); + serd_node_free(true_node); + + SerdNode* false_node = serd_new_boolean(false); + assert(!strcmp(serd_node_string(false_node), "false")); + assert(!strcmp(serd_node_string(serd_node_datatype(false_node)), + NS_XSD "boolean")); + serd_node_free(false_node); +} + +static void test_blob_to_node(void) { assert(!serd_new_blob(NULL, 0, true, NULL)); @@ -773,6 +789,7 @@ main(void) test_double_to_node(); test_integer_to_node(); test_blob_to_node(); + test_boolean(); test_strlen(); test_strerror(); test_uri_parsing(); |