[glade/glade-3-36] Ignore locale when saving numeric values



commit ec7a27242357c5621ffc1c703394169745777644
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Wed May 20 16:45:05 2020 +0200

    Ignore locale when saving numeric values

 gladeui/glade-property-def.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/gladeui/glade-property-def.c b/gladeui/glade-property-def.c
index 16ff9fb3..0d49f598 100644
--- a/gladeui/glade-property-def.c
+++ b/gladeui/glade-property-def.c
@@ -452,6 +452,21 @@ glade_property_def_make_string_from_objects (GladePropertyDef *
   return string;
 }
 
+static locale_t
+get_C_locale (void)
+{
+  static gsize initialized = FALSE;
+  static locale_t C_locale = NULL;
+
+  if (g_once_init_enter (&initialized))
+    {
+      C_locale = newlocale (LC_ALL_MASK, "C", NULL);
+      g_once_init_leave (&initialized, TRUE);
+    }
+
+  return C_locale;
+}
+
 static gchar *
 glade_dtostr (double number, gdouble epsilon)
 {
@@ -461,8 +476,10 @@ glade_dtostr (double number, gdouble epsilon)
   for (i = 0; i <= 20; i++)
     {
       double rounded;
-
+      locale_t old_locale;
+      old_locale = uselocale (get_C_locale ());
       snprintf (str, G_ASCII_DTOSTR_BUF_SIZE, "%.*f", i, number);
+      uselocale (old_locale);
       rounded = g_ascii_strtod (str, NULL);
 
       if (ABS (rounded - number) <= epsilon)


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