diff options
author | David Robillard <d@drobilla.net> | 2009-06-17 01:34:39 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-06-17 01:34:39 +0000 |
commit | cec6214d6820ff7f0ddfc6d12c4de8f6d777e6f0 (patch) | |
tree | 1e9df10c5322cd6cb617cc00613d4c5f4418807a /src | |
parent | 933263cfc85ec3464ad1e28dc7e781a3c2e9f2c4 (diff) | |
download | lilv-cec6214d6820ff7f0ddfc6d12c4de8f6d777e6f0.tar.gz lilv-cec6214d6820ff7f0ddfc6d12c4de8f6d777e6f0.tar.bz2 lilv-cec6214d6820ff7f0ddfc6d12c4de8f6d777e6f0.zip |
Remove duplicate slv2_value_new_librdf_node and slv2_value_from_librdf_node.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2122 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/query.c | 48 | ||||
-rw-r--r-- | src/value.c | 37 |
2 files changed, 22 insertions, 63 deletions
diff --git a/src/query.c b/src/query.c index 2400b86..01114e6 100644 --- a/src/query.c +++ b/src/query.c @@ -39,48 +39,6 @@ static const char* slv2_query_prefixes = "PREFIX lv2ev: <http://lv2plug.in/ns/ext/event#>\n"; -/** Create a new SLV2Value from a librdf_node, or return NULL if impossible */ -SLV2Value -slv2_value_from_librdf_node(SLV2World world, librdf_node* node) -{ - SLV2Value result = NULL; - - librdf_uri* datatype_uri = NULL; - SLV2ValueType type = SLV2_VALUE_STRING; - - switch (librdf_node_get_type(node)) { - case LIBRDF_NODE_TYPE_RESOURCE: - type = SLV2_VALUE_URI; - result = slv2_value_new_librdf_uri(world, librdf_node_get_uri(node)); - break; - case LIBRDF_NODE_TYPE_LITERAL: - datatype_uri = librdf_node_get_literal_value_datatype_uri(node); - if (datatype_uri) { - if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), - "http://www.w3.org/2001/XMLSchema#integer")) - type = SLV2_VALUE_INT; - else if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), - "http://www.w3.org/2001/XMLSchema#decimal")) - type = SLV2_VALUE_FLOAT; - else - SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); - } - result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node)); - break; - case LIBRDF_NODE_TYPE_BLANK: - type = SLV2_VALUE_STRING; - result = slv2_value_new(world, type, (const char*)librdf_node_get_blank_identifier(node)); - break; - case LIBRDF_NODE_TYPE_UNKNOWN: - default: - SLV2_ERRORF("Unknown RDF node type %d\n", librdf_node_get_type(node)); - break; - } - - return result; -} - - SLV2Values slv2_query_get_variable_bindings(SLV2World world, SLV2Results results, @@ -100,7 +58,7 @@ slv2_query_get_variable_bindings(SLV2World world, continue; } - SLV2Value val = slv2_value_from_librdf_node(world, node); + SLV2Value val = slv2_value_new_librdf_node(world, node); if (val) raptor_sequence_push(result, val); @@ -175,7 +133,7 @@ slv2_results_finished(SLV2Results results) SLV2Value slv2_results_get_binding_value(SLV2Results results, unsigned index) { - return slv2_value_from_librdf_node(results->world, + return slv2_value_new_librdf_node(results->world, librdf_query_results_get_binding_value( results->rdf_results, index)); } @@ -184,7 +142,7 @@ slv2_results_get_binding_value(SLV2Results results, unsigned index) SLV2Value slv2_results_get_binding_value_by_name(SLV2Results results, const char* name) { - return slv2_value_from_librdf_node(results->world, + return slv2_value_new_librdf_node(results->world, librdf_query_results_get_binding_value_by_name( results->rdf_results, name)); } diff --git a/src/value.c b/src/value.c index 304e666..33de756 100644 --- a/src/value.c +++ b/src/value.c @@ -72,47 +72,48 @@ slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) } -/* private */ +/** Create a new SLV2Value from a librdf_node, or return NULL if impossible */ SLV2Value slv2_value_new_librdf_node(SLV2World world, librdf_node* node) { - SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); - val->type = SLV2_VALUE_STRING; - val->str_val = NULL; + SLV2Value result = NULL; librdf_uri* datatype_uri = NULL; + SLV2ValueType type = SLV2_VALUE_STRING; switch (librdf_node_get_type(node)) { case LIBRDF_NODE_TYPE_RESOURCE: - val->type = SLV2_VALUE_URI; - val->val.uri_val = librdf_node_get_uri(node); - val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); + type = SLV2_VALUE_URI; + result = slv2_value_new_librdf_uri(world, librdf_node_get_uri(node)); break; case LIBRDF_NODE_TYPE_LITERAL: datatype_uri = librdf_node_get_literal_value_datatype_uri(node); if (datatype_uri) { - if (librdf_uri_equals(datatype_uri, librdf_node_get_uri(world->xsd_integer_node))) - val->type = SLV2_VALUE_INT; - else if (librdf_uri_equals(datatype_uri, librdf_node_get_uri(world->xsd_decimal_node))) - val->type = SLV2_VALUE_FLOAT; + if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), + "http://www.w3.org/2001/XMLSchema#integer")) + type = SLV2_VALUE_INT; + else if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), + "http://www.w3.org/2001/XMLSchema#decimal")) + type = SLV2_VALUE_FLOAT; else SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); } - val->str_val = strdup((char*)librdf_node_get_literal_value(node)); + result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node)); break; case LIBRDF_NODE_TYPE_BLANK: + type = SLV2_VALUE_STRING; + result = slv2_value_new(world, type, (const char*)librdf_node_get_blank_identifier(node)); + break; case LIBRDF_NODE_TYPE_UNKNOWN: default: - SLV2_ERROR("Unknown node type"); - free(val); - val = NULL; + SLV2_ERRORF("Unknown RDF node type %d\n", librdf_node_get_type(node)); break; } - if (val) - slv2_value_set_numerics_from_string(val); + if (result) + slv2_value_set_numerics_from_string(result); - return val; + return result; } |