diff options
author | David Robillard <d@drobilla.net> | 2018-12-26 11:54:21 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-12-20 10:26:55 -0500 |
commit | 8ab439b7bc50533da52a8be232950b615d75c532 (patch) | |
tree | ac5cdb858dcbf57865b2659b764955d24c110ad8 | |
parent | fb0597c6023bc06b4d6db3738aec69213b9d2b26 (diff) | |
download | serd-8ab439b7bc50533da52a8be232950b615d75c532.tar.gz serd-8ab439b7bc50533da52a8be232950b615d75c532.tar.bz2 serd-8ab439b7bc50533da52a8be232950b615d75c532.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 7082901e..68d3fe8f 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -733,6 +733,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 @@ -670,6 +670,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 4ab44066..42343d0d 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 4bbdb960..852c1190 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -268,6 +268,22 @@ test_integer_to_node(void) } static void +test_boolean(void) +{ + SerdNode* true_node = serd_new_boolean(true); + assert(!strcmp(serd_node_get_string(true_node), "true")); + assert(!strcmp(serd_node_get_string(serd_node_get_datatype(true_node)), + NS_XSD "boolean")); + serd_node_free(true_node); + + SerdNode* false_node = serd_new_boolean(false); + assert(!strcmp(serd_node_get_string(false_node), "false")); + assert(!strcmp(serd_node_get_string(serd_node_get_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)); @@ -789,6 +805,7 @@ main(void) test_double_to_node(); test_integer_to_node(); test_blob_to_node(); + test_boolean(); test_strlen(); test_strerror(); test_uri_parsing(); |