diff options
author | David Robillard <d@drobilla.net> | 2007-05-08 03:30:37 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-05-08 03:30:37 +0000 |
commit | f6ff6e487201bdd94e584397ce829daaa424aba9 (patch) | |
tree | aedf571fe2c1db5d3d3cd1511805e51aca64a75e /src/value.c | |
parent | 816279720d70902bf1beba5a2aaaf135707ae77f (diff) | |
download | lilv-f6ff6e487201bdd94e584397ce829daaa424aba9.tar.gz lilv-f6ff6e487201bdd94e584397ce829daaa424aba9.tar.bz2 lilv-f6ff6e487201bdd94e584397ce829daaa424aba9.zip |
Reworked simple query API to allow passing either QName or URI predicates.
Hack around a Rasqal bug for the above (URI predicates).
Clean up exposed names for greppability and to not violate user namespace.
Fixed slv2_plugin_get_value and slv2_plugin_get_value_for_resource.
git-svn-id: http://svn.drobilla.net/lad/slv2@517 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/value.c')
-rw-r--r-- | src/value.c | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/src/value.c b/src/value.c index 1d7ead0..8911619 100644 --- a/src/value.c +++ b/src/value.c @@ -30,7 +30,7 @@ SLV2Value slv2_value_new(SLV2ValueType type, const char* str) { - SLV2Value val = (SLV2Value)malloc(sizeof(struct _Value)); + SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); val->str_val = strdup(str); val->type = type; @@ -59,6 +59,27 @@ slv2_value_free(SLV2Value val) } +/* +SLV2Value +slv2_uri(const char* uri) +{ + struct _SLV2Value val; + val->str_val = (char*)uri; // const cast FTW! + val->type = SLV2_VALUE_URI; + return val; +} + + +SLV2Value +slv2_qname(const char* qname) +{ + SLV2Value val; + val->str_val = (char*)qname; // const cast FTW! + val->type = SLV2_VALUE_QNAME; + return val; +} +*/ + bool slv2_value_equals(SLV2Value value, SLV2Value other) { @@ -69,6 +90,39 @@ slv2_value_equals(SLV2Value value, SLV2Value other) } +char* +slv2_value_get_turtle_token(SLV2Value value) +{ + size_t len = 0; + char* result = NULL; + + switch (value->type) { + case SLV2_VALUE_URI: + len = strlen(value->str_val) + 3; + result = calloc(len, sizeof(char)); + snprintf(result, len, "<%s>", value->str_val); + break; + case SLV2_VALUE_QNAME: + case SLV2_VALUE_STRING: + result = strdup(value->str_val); + break; + case SLV2_VALUE_INT: + // INT64_MAX is 9223372036854775807 (19 digits) + 1 for sign + len = 20; + result = calloc(len, sizeof(char)); + snprintf(result, len, "%d", value->val.int_val); + break; + case SLV2_VALUE_FLOAT: + len = 20; // FIXME: proper maximum value? + result = calloc(len, sizeof(char)); + snprintf(result, len, ".1%f", value->val.float_val); + break; + } + + return result; +} + + bool slv2_value_is_uri(SLV2Value value) { @@ -102,7 +156,6 @@ slv2_value_is_string(SLV2Value value) const char* slv2_value_as_string(SLV2Value value) { - assert(slv2_value_is_string(value)); return value->str_val; } |