aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-04-29 18:29:03 +0200
committerDavid Robillard <d@drobilla.net>2018-12-30 17:58:17 -0500
commit4057fae5851aafbdcd42c99f86f73f985a55ab41 (patch)
tree63b164a170b5014739eeb7ded7bbf54d0e5ce4a3 /src/node.c
parent94f49fa72fdfa32ce798969af22867fde2fd73e9 (diff)
downloadserd-4057fae5851aafbdcd42c99f86f73f985a55ab41.tar.gz
serd-4057fae5851aafbdcd42c99f86f73f985a55ab41.tar.bz2
serd-4057fae5851aafbdcd42c99f86f73f985a55ab41.zip
Make serd_node_new_literal take datatype as a node
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/node.c b/src/node.c
index 14526005..880aa3f3 100644
--- a/src/node.c
+++ b/src/node.c
@@ -113,9 +113,13 @@ serd_node_new_substring(SerdType type, const char* str, const size_t len)
}
SerdNode*
-serd_node_new_literal(const char* str, const char* datatype, const char* lang)
+serd_node_new_literal(const char* str,
+ const SerdNode* datatype,
+ const char* lang)
{
- if (!str || (lang && datatype && strcmp(datatype, NS_RDF "#langString"))) {
+ if (!str || (lang && datatype &&
+ strcmp(serd_node_buffer_c(datatype), NS_RDF "#langString")) ||
+ (datatype && serd_node_get_type(datatype) != SERD_URI)) {
return NULL;
}
@@ -138,16 +142,14 @@ serd_node_new_literal(const char* str, const char* datatype, const char* lang)
memcpy(serd_node_buffer(lang_node), lang, lang_len);
} else if (datatype) {
flags |= SERD_HAS_DATATYPE;
- const size_t datatype_len = strlen(datatype);
+ const size_t datatype_len = strlen(serd_node_buffer_c(datatype));
const size_t total_len = len + sizeof(SerdNode) + datatype_len;
node = serd_node_malloc(total_len, flags, SERD_LITERAL);
memcpy(serd_node_buffer(node), str, n_bytes);
node->n_bytes = n_bytes;
SerdNode* datatype_node = node + 1 + (len / serd_node_align);
- datatype_node->type = SERD_URI;
- datatype_node->n_bytes = datatype_len;
- memcpy(serd_node_buffer(datatype_node), datatype, datatype_len);
+ memcpy(datatype_node, datatype, sizeof(SerdNode) + datatype_len);
} else {
node = serd_node_malloc(n_bytes, flags, SERD_LITERAL);
memcpy(serd_node_buffer(node), str, n_bytes);