aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-02-04 12:40:45 +0100
committerDavid Robillard <d@drobilla.net>2022-01-13 15:33:54 -0500
commita650d2ad2d4785c40405854740e70f487ae1016a (patch)
tree7c7b12d1dcaae256639126a5e08ed390d2b490a3
parent1483449efe47dccdfdf3f5415c2aa616f73c9cef (diff)
downloadserd-a650d2ad2d4785c40405854740e70f487ae1016a.tar.gz
serd-a650d2ad2d4785c40405854740e70f487ae1016a.tar.bz2
serd-a650d2ad2d4785c40405854740e70f487ae1016a.zip
Add node accessor API
-rw-r--r--include/serd/serd.h20
-rw-r--r--src/node.c24
2 files changed, 44 insertions, 0 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 3c058b91..b14cf24d 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -577,6 +577,26 @@ SERD_API
SerdNode
serd_node_copy(const SerdNode* SERD_NULLABLE node);
+/// Return the type of a node (SERD_URI, SERD_BLANK, or SERD_LITERAL)
+SERD_PURE_API
+SerdNodeType
+serd_node_type(const SerdNode* SERD_NONNULL node);
+
+/// Return the node's string
+SERD_PURE_API
+const char* SERD_NONNULL
+serd_node_string(const SerdNode* SERD_NONNULL node);
+
+/// Return the length of the node's string in bytes (excluding terminator)
+SERD_PURE_API
+size_t
+serd_node_length(const SerdNode* SERD_NONNULL node);
+
+/// Return the flags (string properties) of a node
+SERD_PURE_API
+SerdNodeFlags
+serd_node_flags(const SerdNode* SERD_NONNULL node);
+
/// Return true iff `a` is equal to `b`
SERD_PURE_API
bool
diff --git a/src/node.c b/src/node.c
index 93c2214a..869d9bfc 100644
--- a/src/node.c
+++ b/src/node.c
@@ -377,6 +377,30 @@ serd_new_blob(const void* const buf, const size_t size, const bool wrap_lines)
return node;
}
+SerdNodeType
+serd_node_type(const SerdNode* const node)
+{
+ return node->type;
+}
+
+const char*
+serd_node_string(const SerdNode* const node)
+{
+ return node->buf;
+}
+
+size_t
+serd_node_length(const SerdNode* const node)
+{
+ return node->n_bytes;
+}
+
+SerdNodeFlags
+serd_node_flags(const SerdNode* const node)
+{
+ return node->flags;
+}
+
void
serd_node_free(SerdNode* const node)
{