aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-02-04 12:40:45 +0100
committerDavid Robillard <d@drobilla.net>2019-04-13 19:15:32 +0200
commit27dae08d225b0388f08a7cd8b4dcadbed1f671b9 (patch)
treed9432d666431b5283495d37957cb4d9459b1f8d2
parent07c3c06f59348c5558c909b2aa10734bf95e62e7 (diff)
downloadserd-27dae08d225b0388f08a7cd8b4dcadbed1f671b9.tar.gz
serd-27dae08d225b0388f08a7cd8b4dcadbed1f671b9.tar.bz2
serd-27dae08d225b0388f08a7cd8b4dcadbed1f671b9.zip
Add node accessor API
-rw-r--r--serd/serd.h28
-rw-r--r--src/node.c24
2 files changed, 52 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index ba285255..0909dcc7 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -606,6 +606,34 @@ SerdNode
serd_node_new_blob(const void* buf, size_t size, bool wrap_lines);
/**
+ Return the type of a node (SERD_URI, SERD_BLANK, or SERD_LITERAL).
+*/
+SERD_API
+SerdType
+serd_node_get_type(const SerdNode* node);
+
+/**
+ Return the string value of a node.
+*/
+SERD_API
+const char*
+serd_node_get_string(const SerdNode* node);
+
+/**
+ Return the length of the string value of a node in bytes.
+*/
+SERD_API
+size_t
+serd_node_get_length(const SerdNode* node);
+
+/**
+ Return the flags (string properties) of a node.
+*/
+SERD_API
+SerdNodeFlags
+serd_node_get_flags(const SerdNode* node);
+
+/**
Free any data owned by `node`.
Note that if `node` is itself dynamically allocated (which is not the case
diff --git a/src/node.c b/src/node.c
index ff22cd51..e0c1e7b3 100644
--- a/src/node.c
+++ b/src/node.c
@@ -370,6 +370,30 @@ serd_node_new_blob(const void* buf, size_t size, bool wrap_lines)
return node;
}
+SerdType
+serd_node_get_type(const SerdNode* node)
+{
+ return node ? node->type : SERD_NOTHING;
+}
+
+const char*
+serd_node_get_string(const SerdNode* node)
+{
+ return node->buf;
+}
+
+size_t
+serd_node_get_length(const SerdNode* node)
+{
+ return node->n_bytes;
+}
+
+SerdNodeFlags
+serd_node_get_flags(const SerdNode* node)
+{
+ return node->flags;
+}
+
void
serd_node_free(SerdNode* node)
{