From 672e90382da08efa8f593fdc9081e31d0e548fa0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 14 Aug 2020 16:05:10 +0200 Subject: Merge datatype/language into node This moves closer to the sord API, and is more convenient in most cases. --- include/serd/node.h | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'include/serd/node.h') diff --git a/include/serd/node.h b/include/serd/node.h index b95891c9..4aa4ec0a 100644 --- a/include/serd/node.h +++ b/include/serd/node.h @@ -84,8 +84,10 @@ typedef enum { /// Node flags, which ORed together make a #SerdNodeFlags typedef enum { - SERD_HAS_NEWLINE = 1U << 0U, ///< Contains line breaks ('\\n' or '\\r') - SERD_HAS_QUOTE = 1U << 1U, ///< Contains quotes ('"') + SERD_HAS_NEWLINE = 1U << 0U, ///< Contains line breaks ('\\n' or '\\r') + SERD_HAS_QUOTE = 1U << 1U, ///< Contains quotes ('"') + SERD_HAS_DATATYPE = 1U << 2U, ///< Literal node has datatype + SERD_HAS_LANGUAGE = 1U << 3U, ///< Literal node has language } SerdNodeFlag; /// Bitwise OR of #SerdNodeFlag values @@ -111,6 +113,17 @@ serd_new_substring(SerdNodeType type, const char* SERD_NULLABLE str, size_t len); +/** + Create a new literal node from `str`. + + Either `datatype` or `lang` can be given, but not both, unless `datatype` is + rdf:langString in which case it is ignored. +*/ +SERD_API SerdNode* SERD_ALLOCATED +serd_new_literal(const char* SERD_NONNULL str, + const char* SERD_NULLABLE datatype, + const char* SERD_NULLABLE lang); + /** Create a new URI node from a parsed URI. */ @@ -227,6 +240,26 @@ serd_node_string_view(const SerdNode* SERD_NONNULL node); SERD_API SerdURIView serd_node_uri_view(const SerdNode* SERD_NONNULL node); +/** + Return the optional datatype of a literal node. + + The datatype, if present, is always a URI, typically something like + . +*/ +SERD_PURE_API const SerdNode* SERD_NULLABLE +serd_node_datatype(const SerdNode* SERD_NONNULL node); + +/** + Return the optional language tag of a literal node. + + The language tag, if present, is a well-formed BCP 47 (RFC 4647) language + tag like "en-ca". Note that these must be handled case-insensitively, for + example, the common form "en-CA" is valid, but lowercase is considered + canonical here. +*/ +SERD_PURE_API const SerdNode* SERD_NULLABLE +serd_node_language(const SerdNode* SERD_NONNULL node); + /** @} @defgroup serd_node_operators Operators -- cgit v1.2.1