diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -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; +} |