aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-03 12:49:44 +0200
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:05 -0500
commit8f84a055c88c2c271abe9cf86e998a3e5d0a4ced (patch)
treec7662939be38c7ad93f0e336d080251dedeac166
parentef758859f54c37e90deb419fa4e58a9609ea1999 (diff)
downloadserd-8f84a055c88c2c271abe9cf86e998a3e5d0a4ced.tar.gz
serd-8f84a055c88c2c271abe9cf86e998a3e5d0a4ced.tar.bz2
serd-8f84a055c88c2c271abe9cf86e998a3e5d0a4ced.zip
Expand datatype of literal nodes in serd_env_expand_node
-rw-r--r--include/serd/serd.h6
-rw-r--r--src/env.c16
2 files changed, 19 insertions, 3 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 375a8c5d..41ee9993 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -834,7 +834,11 @@ serd_env_expand(const SerdEnv* SERD_NONNULL env,
SerdStringView* SERD_NONNULL uri_suffix);
/**
- Expand `node`, which must be a CURIE or URI, to a full URI.
+ Expand `node`, transforming CURIEs into URIs.
+
+ If `node` is a relative URI reference, it is expanded to a full URI if
+ possible. If `node` is a literal, its datatype is expanded if necessary.
+ If `node` is a CURIE, it is expanded to a full URI if possible.
Returns null if `node` can not be expanded.
*/
diff --git a/src/env.c b/src/env.c
index 66457df8..f0d0705c 100644
--- a/src/env.c
+++ b/src/env.c
@@ -205,8 +205,20 @@ SerdNode*
serd_env_expand_node(const SerdEnv* env, const SerdNode* node)
{
switch (node->type) {
- case SERD_LITERAL:
- break;
+ case SERD_LITERAL: {
+ const SerdNode* const short_datatype = serd_node_datatype(node);
+ if (short_datatype) {
+ SerdNode* const datatype = serd_env_expand_node(env, short_datatype);
+ if (datatype) {
+ SerdNode* ret = serd_new_literal(serd_node_string_view(node),
+ serd_node_string_view(datatype),
+ SERD_EMPTY_STRING());
+ serd_node_free(datatype);
+ return ret;
+ }
+ }
+ return NULL;
+ }
case SERD_URI:
return serd_new_resolved_uri(serd_node_string_view(node), env->base_uri);
case SERD_CURIE: {