[grisbi-cvs] grisbi/src gsb_real.c, 1.68, 1.69 qif.c, 1.143, 1.144 utils_str.c, 1.80, 1.81 utils_str.h, 1.45, 1.46

Pierre Biava pbiava at users.sourceforge.net
Sat Feb 13 21:27:05 CET 2010


Update of /cvsroot/grisbi/grisbi/src
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv22867/src

Modified Files:
	gsb_real.c qif.c utils_str.c utils_str.h 
Log Message:
fixed bugs 946 and 950

Index: gsb_real.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- gsb_real.c	28 Jan 2010 21:53:42 -0000	1.68
+++ gsb_real.c	13 Feb 2010 20:27:02 -0000	1.69
@@ -70,7 +70,6 @@
 static gchar *gsb_real_format_string ( gsb_real number,
                         gint currency_number,
                         gboolean show_symbol );
-static gsb_real gsb_real_get_from_string_normalized ( const gchar *string, gint default_exponent );
 static gboolean gsb_real_grow_exponent( gsb_real *num, guint target_exponent );
 static void gsb_real_minimize_exponent ( gsb_real *num );
 static void gsb_real_raw_minimize_exponent ( gint64 *mantissa, gint *exponent );
@@ -313,9 +312,23 @@
  * */
 gsb_real gsb_real_get_from_string ( const gchar *string )
 {
-    return gsb_real_get_from_string_normalized ( string, -1 );
-}
+    struct lconv *conv = localeconv ( );
+    gchar *mon_thousands_sep;
+    gchar *mon_decimal_point;
+    gsb_real result;
+
+    mon_thousands_sep = g_locale_to_utf8 (
+                             conv->mon_thousands_sep, -1, NULL, NULL, NULL );
+    mon_decimal_point = g_locale_to_utf8 (
+                             conv->mon_decimal_point, -1, NULL, NULL, NULL );
 
+    result =  gsb_real_raw_get_from_string ( string, mon_thousands_sep, mon_decimal_point );
+
+    g_free ( mon_thousands_sep );
+    g_free ( mon_decimal_point );
+
+    return result;
+}
 
 
 /**
@@ -508,34 +521,6 @@
 
 
 /**
- * get a real number from a string
- * the string can be formatted :
- * - handle , or . as separator
- * - spaces are ignored
- * - another character makes a 0 return
- *
- *   the gsb_real will have the exponent given in default_exponent, except if default_exponent = -1
- *
- * \param string
- * \param default_exponent -1 for no limit
- *
- * \return the number in the string transformed to gsb_real
- */
-gsb_real gsb_real_get_from_string_normalized ( const gchar *string, gint default_exponent )
-{
-    struct lconv *conv = localeconv ( );
-    gchar *mon_thousands_sep = g_locale_to_utf8 (
-                             conv->mon_thousands_sep, -1, NULL, NULL, NULL );
-    gchar *mon_decimal_point = g_locale_to_utf8 (
-                             conv->mon_decimal_point, -1, NULL, NULL, NULL );
-    gsb_real result =  gsb_real_raw_get_from_string ( string, mon_thousands_sep, mon_decimal_point );
-    g_free ( mon_thousands_sep );
-    g_free ( mon_decimal_point );
-    return result;
-}
-
-
-/**
  * compare 2 gsb_real and return the result (-1, 0, 1)
  *
  * \param number_1

Index: qif.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/qif.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -d -r1.143 -r1.144
--- qif.c	3 Jan 2010 11:21:26 -0000	1.143
+++ qif.c	13 Feb 2010 20:27:03 -0000	1.144
@@ -350,27 +350,12 @@
 
 		    if ( tmp_str[0] == 'T' )
             {
-                gchar *ptr_1, *ptr_2;
-                gchar *locale = gtk_set_locale ();
-                
-                if ( g_strrstr ( locale, "en" ) == NULL
-                 &&
-                 g_strrstr ( locale, "US" ) == NULL
-                 &&
-                 ( ptr_1 = g_strstr_len ( tmp_str, -1, "," ) )
-                 &&
-                 ( ptr_2 = g_strrstr ( tmp_str, "." ) )
-                 && ( ptr_2 - tmp_str ) > ( ptr_1 - tmp_str ) )
-                {
-                    gchar **tab;
+                gchar *new_str;
 
-                    tab = g_strsplit ( tmp_str + 1, ",", 0 );
-                    imported_transaction -> montant = gsb_real_get_from_string (
-                        g_strjoinv ( "", tab ) );
-                    g_strfreev ( tab );
-                }
-                else
-                    imported_transaction -> montant = gsb_real_get_from_string (tmp_str + 1);
+                new_str = utils_str_localise_decimal_point_from_string ( tmp_str + 1 );
+                imported_transaction -> montant = gsb_real_get_from_string ( new_str );
+
+                g_free ( new_str );
             }
 
 		    /* récupération du chèque */
@@ -451,7 +436,14 @@
 		    if ( tmp_str[0] == '$'
 			 &&
 			 imported_splitted )
-			imported_splitted -> montant = gsb_real_get_from_string (tmp_str + 1);
+            {
+                gchar *new_str;
+
+                new_str = utils_str_localise_decimal_point_from_string ( tmp_str + 1 );
+                imported_splitted -> montant = gsb_real_get_from_string ( new_str );
+
+                g_free ( new_str );
+            }
 		}
 	    }
 	    while ( tmp_str[0] != '^'

Index: utils_str.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/utils_str.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- utils_str.c	28 Jan 2010 20:25:12 -0000	1.80
+++ utils_str.c	13 Feb 2010 20:27:03 -0000	1.81
@@ -162,6 +162,51 @@
 
 
 /**
+ * locates the decimal dot 
+ *
+ *
+ *
+ * */
+gchar *utils_str_localise_decimal_point_from_string ( const gchar *string )
+{
+    struct lconv *conv = localeconv ( );
+    gchar *ptr_1, *ptr_2;
+    gchar *new_str;
+    gchar *mon_decimal_point;
+    gchar **tab;
+
+    mon_decimal_point = g_locale_to_utf8 ( conv->mon_decimal_point, -1, NULL, NULL, NULL );
+
+    if ( ( ptr_1 = g_strstr_len ( string, -1, "," ) )
+     &&
+     ( ptr_2 = g_strrstr ( string, "." ) ) )
+    {
+        if ( ( ptr_2 - string ) > ( ptr_1 - string ) )
+            tab = g_strsplit ( string, ",", 0 );
+        else
+            tab = g_strsplit ( string, ".", 0 );
+
+        new_str = g_strjoinv ( "", tab );
+        g_strfreev ( tab );
+    }
+    else
+        new_str = g_strdup ( string );
+
+    if ( g_strstr_len ( new_str, -1, mon_decimal_point ) == NULL )
+    {
+        tab = g_strsplit_set ( new_str, ".,", 0 );
+        g_free ( new_str );
+        new_str = g_strjoinv ( mon_decimal_point, tab );
+        g_strfreev ( tab );
+    }
+
+    g_free ( mon_decimal_point );
+
+    return new_str;
+}
+
+
+/**
  * @brief Secured version of atoi
  * 
  * Encapsulated call of atoi which may crash when it is call with a NULL pointer.

Index: utils_str.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/utils_str.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- utils_str.h	3 Nov 2009 17:32:07 -0000	1.45
+++ utils_str.h	13 Feb 2010 20:27:03 -0000	1.46
@@ -36,6 +36,7 @@
 gchar *utils_str_itoa ( gint integer );
 gchar *utils_str_reduce_exponant_from_string ( const gchar *amount_string,
                         gint exponent );
+gchar *utils_str_localise_decimal_point_from_string ( const gchar *string );
 /* END_DECLARATION */
 
 typedef enum GSB_TITLE_NAME {



More information about the cvs mailing list