aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-02-24 15:49:21 -0500
committerDavid Robillard <d@drobilla.net>2021-03-07 15:32:24 -0500
commitd243368f8e2f79a125a5858223f71fb40fe84525 (patch)
tree46297455da53f8586d7f7148527a08be71f73d90
parent2607dd857a2a518ba472208bf0237c6cd0c59b32 (diff)
downloadserd-d243368f8e2f79a125a5858223f71fb40fe84525.tar.gz
serd-d243368f8e2f79a125a5858223f71fb40fe84525.tar.bz2
serd-d243368f8e2f79a125a5858223f71fb40fe84525.zip
Add serd_node_uri_view()
-rw-r--r--include/serd/serd.h15
-rw-r--r--src/node.c12
2 files changed, 27 insertions, 0 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 2087114f..489996a5 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -604,6 +604,21 @@ SERD_PURE_API
SerdStringView
serd_node_string_view(const SerdNode* SERD_NONNULL node);
+/**
+ Return a parsed view of the URI in a node.
+
+ It is best to check the node type before calling this function, though it is
+ safe to call on non-URI nodes. In that case, it will return a null view
+ with all fields zero.
+
+ Note that this parses the URI string contained in the node, so it is a good
+ idea to keep the value if you will be using it several times in the same
+ scope.
+*/
+SERD_API
+SerdURIView
+serd_node_uri_view(const SerdNode* SERD_NONNULL node);
+
/// Return the flags (string properties) of a node
SERD_PURE_API
SerdNodeFlags
diff --git a/src/node.c b/src/node.c
index 69034603..7508f45d 100644
--- a/src/node.c
+++ b/src/node.c
@@ -507,6 +507,18 @@ serd_node_string_view(const SerdNode* SERD_NONNULL node)
return result;
}
+SerdURIView
+serd_node_uri_view(const SerdNode* SERD_NONNULL node)
+{
+ SerdURIView result = SERD_URI_NULL;
+
+ if (node->type == SERD_URI) {
+ serd_uri_parse(serd_node_string(node), &result);
+ }
+
+ return result;
+}
+
const SerdNode*
serd_node_datatype(const SerdNode* node)
{