From 0826bb1ac3fd669e1aad4062988edc4bdee4e1d9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 24 Feb 2021 15:49:21 -0500 Subject: Add serd_node_uri_view() --- include/serd/serd.h | 15 +++++++++++++++ src/node.c | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/serd/serd.h b/include/serd/serd.h index acda6ae0..31b631b1 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -584,6 +584,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 fcaf0e34..07010684 100644 --- a/src/node.c +++ b/src/node.c @@ -458,6 +458,18 @@ serd_node_string_view(const SerdNode* const node) return r; } +SerdURIView +serd_node_uri_view(const SerdNode* const node) +{ + SerdURIView result = SERD_URI_NULL; + + if (node->type == SERD_URI) { + serd_uri_parse(serd_node_string(node), &result); + } + + return result; +} + SerdNodeFlags serd_node_flags(const SerdNode* const node) { -- cgit v1.2.1