[gupnp] [PATCH 2/2] Use locale-independent float <-> string conversions
- From: Sven Neumann <s neumann raumfeld com>
- To: gupnp o-hand com
- Cc: Sven Neumann <s neumann raumfeld com>
- Subject: [gupnp] [PATCH 2/2] Use locale-independent float <-> string conversions
- Date: Tue, 14 Sep 2010 10:09:34 +0200
Read and write floats and doubles using the '.' as decimal
separator, independent of the locale that is currently in use.
---
libgupnp/gvalue-util.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/libgupnp/gvalue-util.c b/libgupnp/gvalue-util.c
index d61165f..16a0292 100644
--- a/libgupnp/gvalue-util.c
+++ b/libgupnp/gvalue-util.c
@@ -32,7 +32,6 @@ gvalue_util_set_value_from_string (GValue *value,
{
GValue tmp_value = {0, };
int i;
- double d;
g_return_val_if_fail (str != NULL, FALSE);
@@ -83,14 +82,12 @@ gvalue_util_set_value_from_string (GValue *value,
break;
case G_TYPE_FLOAT:
- d = atof (str);
- g_value_set_float (value, d);
+ g_value_set_float (value, g_ascii_strtod (str, NULL));
break;
case G_TYPE_DOUBLE:
- d = atof (str);
- g_value_set_double (value, d);
+ g_value_set_double (value, g_ascii_strtod (str, NULL));
break;
@@ -166,6 +163,7 @@ gvalue_util_value_append_to_xml_string (const GValue *value,
{
GValue transformed_value = {0, };
const char *tmp;
+ char buf[G_ASCII_DTOSTR_BUF_SIZE];
switch (G_VALUE_TYPE (value)) {
case G_TYPE_STRING:
@@ -219,12 +217,16 @@ gvalue_util_value_append_to_xml_string (const GValue *value,
return TRUE;
case G_TYPE_FLOAT:
- g_string_append_printf (str, "%f", g_value_get_float (value));
+ g_string_append (str,
+ g_ascii_dtostr (buf, sizeof (buf),
+ g_value_get_float (value)));
return TRUE;
case G_TYPE_DOUBLE:
- g_string_append_printf (str, "%g", g_value_get_double (value));
+ g_string_append (str,
+ g_ascii_dtostr (buf, sizeof (buf),
+ g_value_get_double (value)));
return TRUE;
--
1.7.0.4
--
To unsubscribe send a mail to gupnp+unsubscribe\@o-hand.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]