From 90885da36afd20388a6eeeb58efcd844398bc531 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 13 Dec 2008 05:47:50 +0000 Subject: Handle librdf failures (NULL values) and crazily typed values etc. more gracefully. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@1860 a436a847-0d15-0410-975c-d299462d15a1 --- src/value.c | 57 ++++++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) (limited to 'src/value.c') diff --git a/src/value.c b/src/value.c index 08c27e5..ba39754 100644 --- a/src/value.c +++ b/src/value.c @@ -28,35 +28,9 @@ /* private */ -SLV2Value -slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) -{ - SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); - val->type = type; - - if (type == SLV2_VALUE_URI) { - val->val.uri_val = librdf_new_uri(world->world, (const unsigned char*)str); - if (val->val.uri_val) - val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); - else - return NULL; - } else { - val->str_val = strdup(str); - } - - slv2_value_set_numerics_from_string(val); - - return val; -} - - -/* private */ -void +static void slv2_value_set_numerics_from_string(SLV2Value val) { - if (!val) - return; - // FIXME: locale kludges to work around librdf bug char* locale = strdup(setlocale(LC_NUMERIC, NULL)); @@ -76,6 +50,27 @@ slv2_value_set_numerics_from_string(SLV2Value val) } +/* private */ +SLV2Value +slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) +{ + SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); + val->type = type; + + if (type == SLV2_VALUE_URI) { + val->val.uri_val = librdf_new_uri(world->world, (const unsigned char*)str); + assert(val->val.uri_val); + val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); + } else { + val->str_val = strdup(str); + } + + slv2_value_set_numerics_from_string(val); + + return val; +} + + /* private */ SLV2Value slv2_value_new_librdf_node(SLV2World world, librdf_node* node) @@ -113,7 +108,9 @@ slv2_value_new_librdf_node(SLV2World world, librdf_node* node) break; } - slv2_value_set_numerics_from_string(val); + if (val) + slv2_value_set_numerics_from_string(val); + return val; } @@ -122,9 +119,7 @@ slv2_value_new_librdf_node(SLV2World world, librdf_node* node) SLV2Value slv2_value_new_librdf_uri(SLV2World world, librdf_uri* uri) { - if (!uri) - return NULL; - + assert(uri); SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); val->type = SLV2_VALUE_URI; val->val.uri_val = librdf_new_uri_from_uri(uri); -- cgit v1.2.1