diff options
author | David Robillard <d@drobilla.net> | 2011-01-29 20:53:08 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-01-29 20:53:08 +0000 |
commit | d5a4b60e8f72b76dd4d98b43f77bd9da26c0dc4a (patch) | |
tree | daa0a28cd52fa10afa174f5bdd5b6b7c5bf59fd6 /src/plugin.c | |
parent | 1e7c6fab14ca1efd91145fea55dfbf9d272f0539 (diff) | |
download | lilv-d5a4b60e8f72b76dd4d98b43f77bd9da26c0dc4a.tar.gz lilv-d5a4b60e8f72b76dd4d98b43f77bd9da26c0dc4a.tar.bz2 lilv-d5a4b60e8f72b76dd4d98b43f77bd9da26c0dc4a.zip |
Non-SPARQL version of slv2_plugin_get_value_by_qname.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2857 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/plugin.c')
-rw-r--r-- | src/plugin.c | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/src/plugin.c b/src/plugin.c index 4282be3..ffd2319 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -119,7 +119,6 @@ slv2_plugin_query_node(SLV2Plugin p, librdf_node* subject, librdf_node* predicat p, subject, predicate, NULL); if (librdf_stream_end(results)) { - librdf_free_stream(results); return NULL; } @@ -482,20 +481,50 @@ slv2_plugin_get_value(SLV2Plugin p, } -SLV2Values -slv2_plugin_get_value_by_qname(SLV2Plugin p, - const char* predicate) +static char* +slv2_qname_expand(SLV2Plugin p, const char* qname) { - char* query = slv2_strjoin( - "SELECT DISTINCT ?value WHERE { \n" - "<> ", predicate, " ?value . \n" - "}\n", NULL); + char* colon = strchr(qname, ':'); + if (!colon || colon == qname) { + SLV2_ERRORF("Invalid QName `%s'\n", qname); + return NULL; + } - SLV2Values result = slv2_plugin_query_variable(p, query, 0); + const size_t prefix_len = colon - qname; + char* prefix = malloc(prefix_len + 1); + memcpy(prefix, qname, prefix_len); + prefix[prefix_len] = '\0'; - free(query); + char* namespace = librdf_hash_get(p->world->namespaces, prefix); + free(prefix); + if (!namespace) { + SLV2_ERRORF("QName `%s' has Undefined prefix\n", qname); + return NULL; + } - return result; + 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; +} + + +SLV2Values +slv2_plugin_get_value_by_qname(SLV2Plugin p, + const char* predicate) +{ + char* predicate_uri = slv2_qname_expand(p, predicate); + SLV2Value predicate_value = slv2_value_new_uri(p->world, predicate_uri); + SLV2Values ret = slv2_plugin_get_value(p, predicate_value); + slv2_value_free(predicate_value); + free(predicate_uri); + return ret; } |