From cec6214d6820ff7f0ddfc6d12c4de8f6d777e6f0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 17 Jun 2009 01:34:39 +0000 Subject: 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 --- src/value.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/value.c') 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; } -- cgit v1.2.1