[gcalctool] Remove radix/tsep handling from mp-convert (bug #635517)



commit f5235bd56e37884618ad9635f8ea3d7f65b58a7a
Author: Robin Sonefors <ozamosi flukkost nu>
Date:   Mon Nov 22 17:33:25 2010 +0100

    Remove radix/tsep handling from mp-convert (bug #635517)
    
    Make math_equation_get_number use math_equation_get_equation rather than
    math_equation_get_display, as the former will perform some processing of the number.

 NEWS                |    1 +
 src/math-equation.c |    2 +-
 src/mp-convert.c    |   29 ++---------------------------
 3 files changed, 4 insertions(+), 28 deletions(-)
---
diff --git a/NEWS b/NEWS
index fa15f52..ccefe61 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 Overview of changes in gcalctool 5.91.3
 
     * Fix incorrect calculation of tanh
+    * Fix dropping of decimal points when thousand separator is '.' (Bug #635517)
 
 Overview of changes in gcalctool 5.91.2
 
diff --git a/src/math-equation.c b/src/math-equation.c
index c9ae034..7764eed 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -786,7 +786,7 @@ math_equation_get_number(MathEquation *equation, MPNumber *z)
     gchar *text;
     gboolean result;
 
-    text = math_equation_get_display(equation);
+    text = math_equation_get_equation(equation);
     result = !mp_serializer_from_string(equation->priv->serializer, text, z);
     g_free(text);
 
diff --git a/src/mp-convert.c b/src/mp-convert.c
index 4ee6c87..4e389cb 100644
--- a/src/mp-convert.c
+++ b/src/mp-convert.c
@@ -629,18 +629,6 @@ mp_set_from_string(const char *str, int default_base, MPNumber *z)
     const char *fractions[]     = {"½", "â??", "â??", "¼", "¾", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", NULL};
     int numerators[]            = { 1,   1,   2,   1,   3,   1,   2,   3,   4,   1,   5,   1,   3,   5,   7};
     int denominators[]          = { 2,   3,   3,   4,   4,   5,   5,   5,   5,   6,   6,   8,   8,   8,   8};
-    static const char *tsep = NULL;
-    static const char *radix = NULL;
-
-    if (radix == NULL) {
-        radix = nl_langinfo(RADIXCHAR);
-        radix = *radix ? g_locale_to_utf8(radix, -1, NULL, NULL, NULL) : g_strdup(".");
-    }
-
-    if (tsep == NULL) {
-        tsep = nl_langinfo(THOUSEP);
-        tsep = *tsep ? g_locale_to_utf8(tsep, -1, NULL, NULL, NULL) : tsep;
-    }
 
     if (strstr(str, "°"))
         return set_from_sexagesimal(str, strlen(str), z);
@@ -679,20 +667,11 @@ mp_set_from_string(const char *str, int default_base, MPNumber *z)
 
     /* Convert integer part */
     mp_set_from_integer(0, z);
-    while (1) {
-        i = char_val((char **)&c, base);
-        if (i < 0)
-            break;
-
+    while ((i = char_val((char **)&c, base)) >= 0) {
         if (i > base)
             return true;
         mp_multiply_integer(z, base, z);
         mp_add_integer(z, i, z);
-
-        // Must be after the first digit, as locales with tsep = ' ' becomes
-        // buggy otherwise.
-        if (*tsep && strncmp(c, tsep, strlen(tsep)) == 0)
-            c += strlen(tsep);
     }
 
     /* Look for fraction characters, e.g. â?? */
@@ -708,11 +687,7 @@ mp_set_from_string(const char *str, int default_base, MPNumber *z)
         mp_add(z, &fraction, z);
     }
 
-    /* Accept both the user's local radix point (usually '.' or ','), and the
-     * english '.', since at least europeans frequently use '.' despite ','
-     * being the correct one for their locale.
-     */
-    if (*c == '.' || strncmp(c, radix, strlen(radix)) == 0) {
+    if (*c == '.') {
         has_fraction = TRUE;
         c++;
     }



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