From 40588864972d1de767c669c8e5e9b50e652a459b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 20 Feb 2021 13:53:52 -0500 Subject: Add serd_node_string_view() --- include/serd/serd.h | 10 ++++++++++ src/node.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/include/serd/serd.h b/include/serd/serd.h index a55caffc..acda6ae0 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -574,6 +574,16 @@ SERD_PURE_API size_t serd_node_length(const SerdNode* SERD_NULLABLE node); +/** + Return a view of the string in a node. + + This is a convenience wrapper for serd_node_string() and serd_node_length() + that can be used to get both in a single call. +*/ +SERD_PURE_API +SerdStringView +serd_node_string_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 090dee99..fcaf0e34 100644 --- a/src/node.c +++ b/src/node.c @@ -450,6 +450,14 @@ serd_node_length(const SerdNode* const node) return node->length; } +SerdStringView +serd_node_string_view(const SerdNode* const node) +{ + const SerdStringView r = {(const char*)(node + 1), node->length}; + + return r; +} + SerdNodeFlags serd_node_flags(const SerdNode* const node) { -- cgit v1.2.1