[glade/wip/albfan/ignore-locale-numeric-values: 2/2] Ignore locale when saving numeric values
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade/wip/albfan/ignore-locale-numeric-values: 2/2] Ignore locale when saving numeric values
- Date: Wed, 20 May 2020 14:49:51 +0000 (UTC)
commit fd9059a5f7f2aa1e029f7a451c33a25f03f9ee12
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]