summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-30 03:59:36 +0000
committerDavid Robillard <d@drobilla.net>2011-01-30 03:59:36 +0000
commitaa524702008b30123be3044b45a526de84312cff (patch)
treedabc77655b4eced180ab4488c881c39c16cf48af /src/util.c
parent110e2b17943eadd4175cc9bf0cbb96e36789e5e5 (diff)
downloadlilv-aa524702008b30123be3044b45a526de84312cff.tar.gz
lilv-aa524702008b30123be3044b45a526de84312cff.tar.bz2
lilv-aa524702008b30123be3044b45a526de84312cff.zip
Non-SPARQL versions of slv2_port_get_value_by_qname, slv2_port_get_value_by_qname_i18n, and svn_port_get_value.
Gracefully handle invalid predicates in slv2_plugin_get_value_by_qname. 2 queries left... git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2866 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/util.c b/src/util.c
index 92811c8..9fee529 100644
--- a/src/util.c
+++ b/src/util.c
@@ -22,8 +22,9 @@
#include <string.h>
#include <assert.h>
#include <stdarg.h>
-#include "slv2/util.h"
+#include "slv2/util.h"
+#include "slv2_internal.h"
char*
slv2_strjoin(const char* first, ...)
@@ -87,3 +88,36 @@ slv2_get_lang()
return lang;
}
+
+char*
+slv2_qname_expand(SLV2Plugin p, const char* qname)
+{
+ char* colon = strchr(qname, ':');
+ if (!colon || colon == qname) {
+ SLV2_ERRORF("Invalid QName `%s'\n", qname);
+ return NULL;
+ }
+
+ const size_t prefix_len = colon - qname;
+ char* prefix = malloc(prefix_len + 1);
+ memcpy(prefix, qname, prefix_len);
+ prefix[prefix_len] = '\0';
+
+ char* namespace = librdf_hash_get(p->world->namespaces, prefix);
+ free(prefix);
+ if (!namespace) {
+ SLV2_ERRORF("QName `%s' has Undefined prefix\n", qname);
+ return NULL;
+ }
+
+ const size_t qname_len = strlen(qname);
+ const size_t suffix_len = qname_len - prefix_len - 1;
+ const size_t namespace_len = strlen(namespace);
+ char* uri = malloc(namespace_len + suffix_len + 1);
+ memcpy(uri, namespace, namespace_len);
+ memcpy(uri + namespace_len, colon + 1, qname_len - prefix_len - 1);
+ uri[namespace_len + suffix_len] = '\0';
+
+ free(namespace);
+ return uri;
+}