summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-19 03:04:05 +0000
committerDavid Robillard <d@drobilla.net>2011-12-19 03:04:05 +0000
commitb760711088bb027d7c84eec7c19360d8f02680ec (patch)
tree97980f45935fc160171f0e9b28844d4959708bfe /src
parenta12728f443694420b2d4e7a9307d738513cef24f (diff)
downloadlilv-b760711088bb027d7c84eec7c19360d8f02680ec.tar.gz
lilv-b760711088bb027d7c84eec7c19360d8f02680ec.tar.bz2
lilv-b760711088bb027d7c84eec7c19360d8f02680ec.zip
Remove locale smashing kludges and use new serd functions for converting nodes
to/from numbers. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3891 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/node.c41
1 files changed, 8 insertions, 33 deletions
diff --git a/src/node.c b/src/node.c
index dc018c8..3dc4ace 100644
--- a/src/node.c
+++ b/src/node.c
@@ -15,7 +15,6 @@
*/
#include <assert.h>
-#include <locale.h>
#include <stdlib.h>
#include <string.h>
@@ -24,7 +23,6 @@
static void
lilv_node_set_numerics_from_string(LilvNode* val)
{
- char* locale;
char* endptr;
switch (val->type) {
@@ -33,20 +31,10 @@ lilv_node_set_numerics_from_string(LilvNode* val)
case LILV_VALUE_STRING:
break;
case LILV_VALUE_INT:
- // FIXME: locale kludge, need a locale independent strtol
- locale = lilv_strdup(setlocale(LC_NUMERIC, NULL));
- setlocale(LC_NUMERIC, "POSIX");
val->val.int_val = strtol(val->str_val, &endptr, 10);
- setlocale(LC_NUMERIC, locale);
- free(locale);
break;
case LILV_VALUE_FLOAT:
- // FIXME: locale kludge, need a locale independent strtod
- locale = lilv_strdup(setlocale(LC_NUMERIC, NULL));
- setlocale(LC_NUMERIC, "POSIX");
- val->val.float_val = strtod(val->str_val, &endptr);
- setlocale(LC_NUMERIC, locale);
- free(locale);
+ val->val.float_val = serd_strtod(val->str_val, &endptr);
break;
case LILV_VALUE_BOOL:
val->val.bool_val = (!strcmp(val->str_val, "true"));
@@ -258,9 +246,9 @@ LILV_API
char*
lilv_node_get_turtle_token(const LilvNode* value)
{
- size_t len = 0;
- char* result = NULL;
- char* locale = NULL;
+ size_t len = 0;
+ char* result = NULL;
+ SerdNode node;
switch (value->type) {
case LILV_VALUE_URI:
@@ -278,28 +266,15 @@ lilv_node_get_turtle_token(const LilvNode* value)
result = lilv_strdup(value->str_val);
break;
case LILV_VALUE_INT:
- // INT64_MAX is 9223372036854775807 (19 digits) + 1 for sign
- // FIXME: locale kludge, need a locale independent snprintf
- locale = lilv_strdup(setlocale(LC_NUMERIC, NULL));
- len = 20;
- result = calloc(len, 1);
- setlocale(LC_NUMERIC, "POSIX");
- snprintf(result, len, "%d", value->val.int_val);
- setlocale(LC_NUMERIC, locale);
+ node = serd_node_new_integer(value->val.int_val);
+ result = (char*)node.buf;
break;
case LILV_VALUE_FLOAT:
- // FIXME: locale kludge, need a locale independent snprintf
- locale = lilv_strdup(setlocale(LC_NUMERIC, NULL));
- len = 20; // FIXME: proper maximum value?
- result = calloc(len, 1);
- setlocale(LC_NUMERIC, "POSIX");
- snprintf(result, len, "%f", value->val.float_val);
- setlocale(LC_NUMERIC, locale);
+ node = serd_node_new_decimal(value->val.float_val, 8);
+ result = (char*)node.buf;
break;
}
- free(locale);
-
return result;
}