From 6c3ab050cfbbbd80dd795643dcf65e6c5915dec4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 24 Jan 2008 01:28:18 +0000 Subject: Kludge around string<->number issues in locales with a ',' decimal point, and locale bugs in librdf. git-svn-id: http://svn.drobilla.net/lad/slv2@1110 a436a847-0d15-0410-975c-d299462d15a1 --- src/port.c | 2 +- src/query.c | 14 +++++++++++++- src/value.c | 28 +++++++++++++++++----------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/port.c b/src/port.c index b7414be..d895b6e 100644 --- a/src/port.c +++ b/src/port.c @@ -139,7 +139,7 @@ slv2_port_get_value(SLV2Plugin p, char* query = slv2_strjoin( "SELECT DISTINCT ?value WHERE {\n" - "<", librdf_uri_as_string(p->plugin_uri), "> lv2:port ?port ." + "<", librdf_uri_as_string(p->plugin_uri), "> lv2:port ?port .\n" "?port lv2:symbol \"", port->symbol, "\";\n\t", property, " ?value .\n}", NULL); diff --git a/src/query.c b/src/query.c index 54dcda4..988e117 100644 --- a/src/query.c +++ b/src/query.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,11 @@ slv2_query_get_variable_bindings(SLV2World world, librdf_node* node = librdf_query_results_get_binding_value(results, variable); - assert(node); + if (!node) { + fprintf(stderr, "SLV2 ERROR: Variable %d bound to NULL.\n", variable); + librdf_query_results_next(results); + continue; + } librdf_uri* datatype_uri = NULL; SLV2ValueType type = SLV2_VALUE_STRING; @@ -138,7 +143,14 @@ slv2_plugin_query(SLV2Plugin plugin, return NULL; } + // FIXME: locale kludges to work around librdf bug + char* locale = strdup(setlocale(LC_NUMERIC, NULL)); + + setlocale(LC_NUMERIC, "POSIX"); librdf_query_results* results = librdf_query_execute(query, plugin->rdf); + setlocale(LC_NUMERIC, locale); + + free(locale); librdf_free_query(query); free(query_str); diff --git a/src/value.c b/src/value.c index 4724a23..498fdfd 100644 --- a/src/value.c +++ b/src/value.c @@ -44,26 +44,23 @@ slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) val->str_val = strdup(str); } - /* Kludge decimal point to '.' for people in crazy locales that use ',' */ - /* TODO: librdf should probably provide this... */ - if (type == SLV2_VALUE_INT || type == SLV2_VALUE_FLOAT) { - struct lconv* locale = localeconv(); - if (locale->decimal_point && strcmp(locale->decimal_point, ".")) { - assert(strlen(locale->decimal_point) == 1); - char* dec = strchr(str, '.'); - if (dec) - *dec = locale->decimal_point[0]; - } - } + // FIXME: locale kludges to work around librdf bug + char* locale = strdup(setlocale(LC_NUMERIC, NULL)); if (type == SLV2_VALUE_INT) { char* endptr = 0; + setlocale(LC_NUMERIC, "POSIX"); val->val.int_val = strtol(str, &endptr, 10); + setlocale(LC_NUMERIC, locale); } else if (type == SLV2_VALUE_FLOAT) { char* endptr = 0; + setlocale(LC_NUMERIC, "POSIX"); val->val.float_val = strtod(str, &endptr); + setlocale(LC_NUMERIC, locale); } + free(locale); + return val; } @@ -148,6 +145,9 @@ slv2_value_get_turtle_token(SLV2Value value) { size_t len = 0; char* result = NULL; + char* locale = strdup(setlocale(LC_NUMERIC, NULL)); + + // FIXME: locale kludges to work around librdf bug switch (value->type) { case SLV2_VALUE_URI: @@ -162,14 +162,20 @@ slv2_value_get_turtle_token(SLV2Value value) // INT64_MAX is 9223372036854775807 (19 digits) + 1 for sign len = 20; result = calloc(len, sizeof(char)); + setlocale(LC_NUMERIC, "POSIX"); snprintf(result, len, "%d", value->val.int_val); + setlocale(LC_NUMERIC, locale); break; case SLV2_VALUE_FLOAT: len = 20; // FIXME: proper maximum value? result = calloc(len, sizeof(char)); + setlocale(LC_NUMERIC, "POSIX"); snprintf(result, len, ".1%f", value->val.float_val); + setlocale(LC_NUMERIC, locale); break; } + + free(locale); return result; } -- cgit v1.2.1