aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-12-26 11:54:21 -0500
committerDavid Robillard <d@drobilla.net>2019-04-13 19:48:23 +0200
commitb30f33eee72c8900228d4406eecce0b404b6e827 (patch)
tree81bfbe1f5b7b28909777d54fbeec6d5963babdd0
parent5443876d8e15c6ad011ede7d46ed36325a6cb282 (diff)
downloadserd-b30f33eee72c8900228d4406eecce0b404b6e827.tar.gz
serd-b30f33eee72c8900228d4406eecce0b404b6e827.tar.bz2
serd-b30f33eee72c8900228d4406eecce0b404b6e827.zip
Add serd_new_boolean()
-rw-r--r--serd/serd.h5
-rw-r--r--src/node.c7
-rw-r--r--tests/serd_test.c13
3 files changed, 25 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 145a424a..024ba9e8 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
diff --git a/src/node.c b/src/node.c
index 682bb42a..a7cb56b2 100644
--- a/src/node.c
+++ b/src/node.c
@@ -50,6 +50,7 @@ typedef struct StaticNode {
DEFINE_XSD_NODE(decimal)
DEFINE_XSD_NODE(integer)
+DEFINE_XSD_NODE(boolean)
DEFINE_XSD_NODE(base64Binary)
static SerdNode*
@@ -619,6 +620,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/tests/serd_test.c b/tests/serd_test.c
index e3289a17..797a489a 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -203,6 +203,19 @@ main(void)
serd_node_free(node);
}
+ // Test serd_new_boolean
+ 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);
+
// Test serd_new_blob
assert(!serd_new_blob(NULL, 0, true, NULL));
assert(!serd_new_blob("data", 0, true, NULL));