[grisbi-cvs] grisbi/src gsb_file_load.c, 1.192, 1.193 gsb_real.c, 1.59, 1.60

Gunee guneemwelloeux at users.sourceforge.net
Thu Dec 10 16:06:49 CET 2009


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

Modified Files:
	gsb_file_load.c gsb_real.c 
Log Message:
Fixed problem with separators with spanish locale (and probably other locales as well)
Bug 689

Index: gsb_real.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- gsb_real.c	26 Nov 2009 17:20:29 -0000	1.59
+++ gsb_real.c	10 Dec 2009 15:06:47 -0000	1.60
@@ -366,9 +366,6 @@
     gint8 dot_position = -1;
     const gchar *p = string;
 
-    assert ( !mon_thousands_sep || ( g_utf8_strlen ( mon_thousands_sep, -1 ) <= 1 ) );
-    assert ( !mon_decimal_point || ( g_utf8_strlen ( mon_decimal_point, -1 ) <= 1 ) );
-
     if ( !string)
         return error_real;
 
@@ -376,7 +373,10 @@
                        ? strlen ( mon_thousands_sep )
                        : 0;
     mdp_len = mon_decimal_point ? strlen ( mon_decimal_point ) : 0;
-	decimal_chars = g_strconcat(".", mon_decimal_point, NULL);
+	if ( !strchr ( mon_thousands_sep, '.' ))
+		decimal_chars = g_strconcat(".", mon_decimal_point, NULL);
+	else
+		decimal_chars = g_strdup(mon_decimal_point);
 	space_chars = g_strconcat(" ", mon_thousands_sep, NULL);
 
     for ( ; ; )
@@ -400,11 +400,6 @@
                               : 0;
             return result;
         }
-        else if ( strchr ( space_chars, *p ) )
-        {
-            // just skip spaces and thousands separators
-            p = g_utf8_find_next_char ( p, NULL );
-        }
         else if ( strchr ( decimal_chars, *p ) )
         {
             if ( dot_position >= 0 ) // already found a decimal separator
@@ -412,6 +407,11 @@
             dot_position = nb_digits;
             p = g_utf8_find_next_char ( p, NULL );
         }
+        else if ( strchr ( space_chars, *p ) )
+        {
+            // just skip spaces and thousands separators
+            p = g_utf8_find_next_char ( p, NULL );
+        }
         else if ( strchr ( negative_chars, *p ) )
         {
             if ( sign != 0 ) // sign already set
@@ -435,6 +435,73 @@
 
 
 /**
+ * get a gsb_real number from a string, during file load
+ * the string can be formatted :
+ * - spaces and the given utf8-encoded thousands separators are ignored
+ * - handle only "." as a decimal separator
+ * - another character makes a error_real return
+ *
+ * \param string
+ * \param mon_thousands_sep, can be NULL or empty, but only one utf8 sequence
+ * \param mon_decimal_point, can be NULL or empty, but only one utf8 sequence
+ *
+ * \return the number in the string transformed to gsb_real
+ */
+gsb_real gsb_real_import_from_string ( const gchar *string )
+{
+    unsigned nb_digits = 0;
+    gint64 mantissa = 0;
+    gint8 sign = 0;
+    gint8 dot_position = -1;
+    const gchar *p = string;
+
+    if ( !string)
+        return error_real;
+
+    for ( ; ; )
+    {
+        if ( g_ascii_isdigit ( *p ) )
+        {
+            mantissa *= 10;
+            mantissa += ( *p - '0' );
+            if ( mantissa > G_MAXLONG )
+                return error_real;
+            if ( sign == 0 ) sign = 1; // no sign found yet ==> positive
+            ++nb_digits;
+            ++p;
+        }
+        else if ( *p == 0 ) // terminal zero
+        {
+			gsb_real result;
+			result.mantissa = sign * mantissa;
+            result.exponent = ( dot_position >= 0 )
+                              ? nb_digits - dot_position
+                              : 0;
+            return result;
+        }
+        else if ( strchr ( ".", *p ) )
+        {
+            if ( dot_position >= 0 ) // already found a decimal separator
+                return error_real;
+            dot_position = nb_digits;
+            p = g_utf8_find_next_char ( p, NULL );
+        }
+        else if ( strchr ( "-", *p ) )
+        {
+            if ( sign != 0 ) // sign already set
+                return error_real;
+            sign = -1;
+            ++p;
+        }
+        else // unknown char ==> error
+        {
+            return error_real;
+        }
+    }
+}
+
+
+/**
  * get a real number from a string
  * the string can be formatted :
  * - handle , or . as separator

Index: gsb_file_load.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_load.c,v
retrieving revision 1.192
retrieving revision 1.193
diff -u -d -r1.192 -r1.193
--- gsb_file_load.c	18 Oct 2009 17:46:21 -0000	1.192
+++ gsb_file_load.c	10 Dec 2009 15:06:47 -0000	1.193
@@ -151,6 +151,9 @@
 static gboolean gsb_file_load_update_previous_version ( void );
 /*END_STATIC*/
 
+/*BEGIN SPECIAL FUNCTION DECLARATION*/
+gsb_real gsb_real_import_from_string ( const gchar *string );
+/*END SPECIAL FUNCTION DECLARATION*/
 
 /*START_EXTERN*/
 extern gchar *adresse_commune;
@@ -1471,7 +1474,7 @@
                         "Initial_balance" ))
     {
         gsb_data_account_set_init_balance ( account_number,
-                        gsb_real_get_from_string (attribute_values[i]));
+                        gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -1480,7 +1483,7 @@
                         "Minimum_wanted_balance" ))
     {
         gsb_data_account_set_mini_balance_wanted ( account_number, 
-                        gsb_real_get_from_string (attribute_values[i]));
+                        gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -1489,7 +1492,7 @@
                         "Minimum_authorised_balance" ))
     {
         gsb_data_account_set_mini_balance_authorized ( account_number, 
-                        gsb_real_get_from_string (attribute_values[i]));
+                        gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -1901,7 +1904,7 @@
     {
         /* get the entire real, even if the floating point of the currency is less deep */
         gsb_data_transaction_set_amount ( transaction_number,
-                          gsb_real_get_from_string (attribute_values[i]));
+                          gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -1921,7 +1924,7 @@
                "Exr" ))
     {
         gsb_data_transaction_set_exchange_rate ( transaction_number,
-                             gsb_real_get_from_string (attribute_values[i]));
+                             gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -1931,7 +1934,7 @@
                "Exf" ))
     {
         gsb_data_transaction_set_exchange_fees ( transaction_number,
-                             gsb_real_get_from_string (attribute_values[i]));
+                             gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -2182,7 +2185,7 @@
                "Am" ))
     {
         gsb_data_scheduled_set_amount ( scheduled_number,
-                        gsb_real_get_from_string (attribute_values[i]));
+                        gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -2870,7 +2873,7 @@
                                    "Ex" ))
     {
         gsb_data_currency_link_set_change_rate ( link_number,
-                                 gsb_real_get_from_string (attribute_values[i]));
+                                 gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -3311,7 +3314,7 @@
                "Ibal" ))
     {
         gsb_data_reconcile_set_init_balance ( reconcile_number,
-                              gsb_real_get_from_string (attribute_values[i]));
+                              gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -3320,7 +3323,7 @@
                "Fbal" ))
     {
         gsb_data_reconcile_set_final_balance ( reconcile_number,
-                               gsb_real_get_from_string (attribute_values[i]));
+                               gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -4530,7 +4533,7 @@
                "Amount_1" ))
     {
         gsb_data_report_amount_comparison_set_first_amount ( amount_comparison_number,
-                                     gsb_real_get_from_string (attribute_values[i]));
+                                     gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -4539,7 +4542,7 @@
                "Amount_2" ))
     {
         gsb_data_report_amount_comparison_set_second_amount ( amount_comparison_number,
-                                     gsb_real_get_from_string (attribute_values[i]));
+                                     gsb_real_import_from_string (attribute_values[i]));
         i++;
         continue;
     }
@@ -4783,7 +4786,7 @@
             tmp_string = utils_str_reduce_exponant_from_string ( attribute_values[i],
                                          2 );
             gsb_data_transaction_set_amount ( transaction_number,
-                                  gsb_real_get_from_string (tmp_string));
+                                  gsb_real_import_from_string (tmp_string));
             if (tmp_string) g_free (tmp_string);
         }
 
@@ -4800,12 +4803,12 @@
         if ( !strcmp ( attribute_names[i],
                    "Tc" ))
             gsb_data_transaction_set_exchange_rate ( transaction_number,
-                                     gsb_real_get_from_string (attribute_values[i]));
+                                     gsb_real_import_from_string (attribute_values[i]));
 
         if ( !strcmp ( attribute_names[i],
                    "Fc" ))
             gsb_data_transaction_set_exchange_fees ( transaction_number,
-                                     gsb_real_get_from_string (attribute_values[i]));
+                                     gsb_real_import_from_string (attribute_values[i]));
 
         if ( !strcmp ( attribute_names[i],
                    "T" ))
@@ -4955,7 +4958,7 @@
             tmp_string = utils_str_reduce_exponant_from_string ( attribute_values[i],
                                          2 );
             gsb_data_scheduled_set_amount ( scheduled_number,
-                                gsb_real_get_from_string (tmp_string));
+                                gsb_real_import_from_string (tmp_string));
             if (tmp_string) g_free (tmp_string);
         }
 
@@ -5311,7 +5314,7 @@
 
         if ( !strcmp ( attribute_names[i],
                    "Change" ))
-            tmp_currency_link.exchange = gsb_real_get_from_string (attribute_values[i]);
+            tmp_currency_link.exchange = gsb_real_import_from_string (attribute_values[i]);
         if ( !strcmp ( attribute_names[i], "Date_dernier_change" ) 
          &&
          strlen ( attribute_values[i] ) )
@@ -5679,7 +5682,7 @@
             tmp_string = utils_str_reduce_exponant_from_string ( attribute_values[i],
                                          2 );
             gsb_data_report_amount_comparison_set_first_amount ( amount_comparison_number,
-                                         gsb_real_get_from_string (tmp_string));
+                                         gsb_real_import_from_string (tmp_string));
             if (tmp_string) g_free (tmp_string);
         }
 
@@ -5693,7 +5696,7 @@
             tmp_string = utils_str_reduce_exponant_from_string ( attribute_values[i],
                                          2 );
             gsb_data_report_amount_comparison_set_second_amount ( amount_comparison_number,
-                                          gsb_real_get_from_string (tmp_string));
+                                          gsb_real_import_from_string (tmp_string));
             if (tmp_string) g_free (tmp_string);
         }
 
@@ -6117,7 +6120,7 @@
     tmp_string = utils_str_reduce_exponant_from_string ( text,
                                      2 );
     gsb_data_account_set_init_balance ( account_number,
-                        gsb_real_get_from_string (tmp_string));
+                        gsb_real_import_from_string (tmp_string));
     if (tmp_string) g_free (tmp_string);
     return;
     }
@@ -6132,7 +6135,7 @@
     tmp_string = utils_str_reduce_exponant_from_string ( text,
                                      2 );
     gsb_data_account_set_mini_balance_wanted ( account_number,
-                               gsb_real_get_from_string (tmp_string));
+                               gsb_real_import_from_string (tmp_string));
     if (tmp_string) g_free (tmp_string);
     return;
     }
@@ -6147,7 +6150,7 @@
     tmp_string = utils_str_reduce_exponant_from_string ( text,
                                      2 );
     gsb_data_account_set_mini_balance_authorized ( account_number,
-                                   gsb_real_get_from_string (tmp_string));
+                                   gsb_real_import_from_string (tmp_string));
     if (tmp_string) g_free (tmp_string);
     return;
     }
@@ -6182,7 +6185,7 @@
     tmp_string = utils_str_reduce_exponant_from_string ( text,
                                      2 );
     if (buffer_reconcile_conversion)
-        buffer_reconcile_conversion -> final_balance = gsb_real_get_from_string (tmp_string);
+        buffer_reconcile_conversion -> final_balance = gsb_real_import_from_string (tmp_string);
     if (tmp_string) g_free (tmp_string);
     return;
     }



More information about the cvs mailing list