[geocode-glib] geocode-reverse: Make constructor locale safe



commit 8ac85fcb04ab941379a6859c1379605cba281f85
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Mon Aug 26 12:23:13 2013 +0200

    geocode-reverse: Make constructor locale safe
    
    When using g_strdup_printf and float values the radix
    character (decimal point) is locale dependent and for some
    locales will print a comma. This will break the nominatim
    queries for us.
    
    Switch to using g_ascii_dtostr() instead which will always
    use a dot as decimal point.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706786

 geocode-glib/geocode-reverse.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index 8f23094..9f4b5a3 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -95,15 +95,21 @@ GeocodeReverse *
 geocode_reverse_new_for_location (GeocodeLocation *location)
 {
        GeocodeReverse *object;
+       char coord[G_ASCII_DTOSTR_BUF_SIZE];
+       char *lat;
+       char *lon;
 
+       lat = g_strdup (g_ascii_dtostr (coord,
+                                       G_ASCII_DTOSTR_BUF_SIZE,
+                                       geocode_location_get_latitude (location)));
+
+       lon = g_strdup (g_ascii_dtostr (coord,
+                                       G_ASCII_DTOSTR_BUF_SIZE,
+                                       geocode_location_get_longitude (location)));
        object = g_object_new (GEOCODE_TYPE_REVERSE, NULL);
 
-       g_hash_table_insert (object->priv->ht,
-                            g_strdup ("lat"),
-                            g_strdup_printf ("%g",  geocode_location_get_latitude (location)));
-       g_hash_table_insert (object->priv->ht,
-                            g_strdup ("lon"),
-                            g_strdup_printf ("%g",  geocode_location_get_longitude (location)));
+       g_hash_table_insert (object->priv->ht, g_strdup ("lat"), lat);
+       g_hash_table_insert (object->priv->ht, g_strdup ("lon"), lon);
 
        return object;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]