Changeset 2122

Show
Ignore:
Timestamp:
06/16/09 18:34:39 (15 months ago)
Author:
drobilla
Message:

Remove duplicate slv2_value_new_librdf_node and slv2_value_from_librdf_node.

Location:
trunk/slv2/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/slv2/src/query.c

    r2117 r2122  
    4040 
    4141 
    42 /** Create a new SLV2Value from a librdf_node, or return NULL if impossible */ 
    43 SLV2Value 
    44 slv2_value_from_librdf_node(SLV2World world, librdf_node* node) 
    45 { 
    46         SLV2Value result = NULL; 
    47  
    48         librdf_uri* datatype_uri = NULL; 
    49         SLV2ValueType type = SLV2_VALUE_STRING; 
    50  
    51         switch (librdf_node_get_type(node)) { 
    52         case LIBRDF_NODE_TYPE_RESOURCE: 
    53                 type = SLV2_VALUE_URI; 
    54                 result = slv2_value_new_librdf_uri(world, librdf_node_get_uri(node)); 
    55                 break; 
    56         case LIBRDF_NODE_TYPE_LITERAL: 
    57                 datatype_uri = librdf_node_get_literal_value_datatype_uri(node); 
    58                 if (datatype_uri) { 
    59                         if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), 
    60                                                 "http://www.w3.org/2001/XMLSchema#integer")) 
    61                                 type = SLV2_VALUE_INT; 
    62                         else if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), 
    63                                                 "http://www.w3.org/2001/XMLSchema#decimal")) 
    64                                 type = SLV2_VALUE_FLOAT; 
    65                         else 
    66                                 SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); 
    67                 } 
    68                 result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node)); 
    69                 break; 
    70         case LIBRDF_NODE_TYPE_BLANK: 
    71                 type = SLV2_VALUE_STRING; 
    72                 result = slv2_value_new(world, type, (const char*)librdf_node_get_blank_identifier(node)); 
    73                 break; 
    74         case LIBRDF_NODE_TYPE_UNKNOWN: 
    75         default: 
    76                 SLV2_ERRORF("Unknown RDF node type %d\n", librdf_node_get_type(node)); 
    77                 break; 
    78         } 
    79  
    80         return result; 
    81 } 
    82  
    83  
    8442SLV2Values 
    8543slv2_query_get_variable_bindings(SLV2World   world, 
     
    10159                } 
    10260 
    103                 SLV2Value val = slv2_value_from_librdf_node(world, node); 
     61                SLV2Value val = slv2_value_new_librdf_node(world, node); 
    10462                if (val) 
    10563                        raptor_sequence_push(result, val); 
     
    176134slv2_results_get_binding_value(SLV2Results results, unsigned index) 
    177135{ 
    178         return slv2_value_from_librdf_node(results->world, 
     136        return slv2_value_new_librdf_node(results->world, 
    179137                        librdf_query_results_get_binding_value( 
    180138                                        results->rdf_results, index)); 
     
    185143slv2_results_get_binding_value_by_name(SLV2Results results, const char* name) 
    186144{ 
    187         return slv2_value_from_librdf_node(results->world, 
     145        return slv2_value_new_librdf_node(results->world, 
    188146                        librdf_query_results_get_binding_value_by_name( 
    189147                                        results->rdf_results, name)); 
  • trunk/slv2/src/value.c

    r2117 r2122  
    7373 
    7474 
    75 /* private */ 
     75/** Create a new SLV2Value from a librdf_node, or return NULL if impossible */ 
    7676SLV2Value 
    7777slv2_value_new_librdf_node(SLV2World world, librdf_node* node) 
    7878{ 
    79         SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); 
    80         val->type = SLV2_VALUE_STRING; 
    81         val->str_val = NULL; 
     79        SLV2Value result = NULL; 
    8280 
    8381        librdf_uri* datatype_uri = NULL; 
     82        SLV2ValueType type = SLV2_VALUE_STRING; 
    8483 
    8584        switch (librdf_node_get_type(node)) { 
    8685        case LIBRDF_NODE_TYPE_RESOURCE: 
    87                 val->type = SLV2_VALUE_URI; 
    88                 val->val.uri_val = librdf_node_get_uri(node); 
    89                 val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); 
     86                type = SLV2_VALUE_URI; 
     87                result = slv2_value_new_librdf_uri(world, librdf_node_get_uri(node)); 
    9088                break; 
    9189        case LIBRDF_NODE_TYPE_LITERAL: 
    9290                datatype_uri = librdf_node_get_literal_value_datatype_uri(node); 
    9391                if (datatype_uri) { 
    94                         if (librdf_uri_equals(datatype_uri, librdf_node_get_uri(world->xsd_integer_node))) 
    95                                 val->type = SLV2_VALUE_INT; 
    96                         else if (librdf_uri_equals(datatype_uri, librdf_node_get_uri(world->xsd_decimal_node))) 
    97                                 val->type = SLV2_VALUE_FLOAT; 
     92                        if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), 
     93                                                "http://www.w3.org/2001/XMLSchema#integer")) 
     94                                type = SLV2_VALUE_INT; 
     95                        else if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), 
     96                                                "http://www.w3.org/2001/XMLSchema#decimal")) 
     97                                type = SLV2_VALUE_FLOAT; 
    9898                        else 
    9999                                SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); 
    100100                } 
    101                 val->str_val = strdup((char*)librdf_node_get_literal_value(node)); 
     101                result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node)); 
    102102                break; 
    103103        case LIBRDF_NODE_TYPE_BLANK: 
     104                type = SLV2_VALUE_STRING; 
     105                result = slv2_value_new(world, type, (const char*)librdf_node_get_blank_identifier(node)); 
     106                break; 
    104107        case LIBRDF_NODE_TYPE_UNKNOWN: 
    105108        default: 
    106                 SLV2_ERROR("Unknown node type"); 
    107                 free(val); 
    108                 val = NULL; 
    109                 break; 
    110         } 
    111  
    112         if (val) 
    113                 slv2_value_set_numerics_from_string(val); 
    114  
    115         return val; 
     109                SLV2_ERRORF("Unknown RDF node type %d\n", librdf_node_get_type(node)); 
     110                break; 
     111        } 
     112 
     113    if (result) 
     114                slv2_value_set_numerics_from_string(result); 
     115 
     116        return result; 
    116117} 
    117118