aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-12-26 11:54:21 -0500
committerDavid Robillard <d@drobilla.net>2020-06-21 18:12:04 +0200
commitd68795cb7d79ed4b6b92386f548524ae518f41b9 (patch)
tree8f64116a021d27b90a68f23bbcf8db5ab44033f7
parent5c0c09d8ecbdc17452b3bd2c0dc2fc7bb555e5b8 (diff)
downloadserd-d68795cb7d79ed4b6b92386f548524ae518f41b9.tar.gz
serd-d68795cb7d79ed4b6b92386f548524ae518f41b9.tar.bz2
serd-d68795cb7d79ed4b6b92386f548524ae518f41b9.zip
Add serd_new_boolean()
-rw-r--r--serd/serd.h5
-rw-r--r--src/node.c6
-rw-r--r--src/static_nodes.h1
-rw-r--r--tests/serd_test.c17
4 files changed, 29 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index e1ae0aed..e82b8073 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -709,6 +709,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
diff --git a/src/node.c b/src/node.c
index 11fba1b7..bd08cdda 100644
--- a/src/node.c
+++ b/src/node.c
@@ -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 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 8594b132..f550e893 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();