aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-14 16:05:10 +0200
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit672e90382da08efa8f593fdc9081e31d0e548fa0 (patch)
tree3f70c13dda1e60e7b058c750002ec320bfaa6a73 /include/serd
parentfff826f406e0b9975fd8672041e50dd1a342339f (diff)
downloadserd-672e90382da08efa8f593fdc9081e31d0e548fa0.tar.gz
serd-672e90382da08efa8f593fdc9081e31d0e548fa0.tar.bz2
serd-672e90382da08efa8f593fdc9081e31d0e548fa0.zip
Merge datatype/language into node
This moves closer to the sord API, and is more convenient in most cases.
Diffstat (limited to 'include/serd')
-rw-r--r--include/serd/node.h37
-rw-r--r--include/serd/sink.h15
-rw-r--r--include/serd/writer.h4
3 files changed, 42 insertions, 14 deletions
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
@@ -112,6 +114,17 @@ serd_new_substring(SerdNodeType type,
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.
*/
SERD_API SerdNode* SERD_ALLOCATED
@@ -228,6 +241,26 @@ 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
+ <http://www.w3.org/2001/XMLSchema#boolean>.
+*/
+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
@{
diff --git a/include/serd/sink.h b/include/serd/sink.h
index 97b47a2f..702197d5 100644
--- a/include/serd/sink.h
+++ b/include/serd/sink.h
@@ -39,15 +39,12 @@ typedef SerdStatus (*SerdPrefixFunc)(void* SERD_NULLABLE handle,
Called for every RDF statement in the serialisation.
*/
-typedef SerdStatus (*SerdStatementFunc)(
- void* SERD_NULLABLE handle,
- SerdStatementFlags flags,
- const SerdNode* SERD_NULLABLE graph,
- const SerdNode* SERD_NONNULL subject,
- const SerdNode* SERD_NONNULL predicate,
- const SerdNode* SERD_NONNULL object,
- const SerdNode* SERD_NULLABLE object_datatype,
- const SerdNode* SERD_NULLABLE object_lang);
+typedef SerdStatus (*SerdStatementFunc)(void* SERD_NULLABLE handle,
+ SerdStatementFlags flags,
+ const SerdNode* SERD_NULLABLE graph,
+ const SerdNode* SERD_NONNULL subject,
+ const SerdNode* SERD_NONNULL predicate,
+ const SerdNode* SERD_NONNULL object);
/**
Sink function for anonymous node end markers.
diff --git a/include/serd/writer.h b/include/serd/writer.h
index 66c3d338..3327c1b9 100644
--- a/include/serd/writer.h
+++ b/include/serd/writer.h
@@ -139,9 +139,7 @@ serd_writer_write_statement(SerdWriter* SERD_NONNULL writer,
const SerdNode* SERD_NULLABLE graph,
const SerdNode* SERD_NONNULL subject,
const SerdNode* SERD_NONNULL predicate,
- const SerdNode* SERD_NONNULL object,
- const SerdNode* SERD_NULLABLE datatype,
- const SerdNode* SERD_NULLABLE lang);
+ const SerdNode* SERD_NONNULL object);
/**
Mark the end of an anonymous node's description.