r16357 - gnucash/branches/csv-import/src/import-export/csv - Added support for amounts with currency symbols (e.g., "$100"),

Benjamin Sperisen lasindi at cvs.gnucash.org
Wed Jul 25 06:28:59 EDT 2007


Author: lasindi
Date: 2007-07-25 06:28:57 -0400 (Wed, 25 Jul 2007)
New Revision: 16357
Trac: http://svn.gnucash.org/trac/changeset/16357

Modified:
   gnucash/branches/csv-import/src/import-export/csv/gnc-csv-gnumeric-popup.c
   gnucash/branches/csv-import/src/import-export/csv/gnc-csv-gnumeric-popup.h
   gnucash/branches/csv-import/src/import-export/csv/gnc-csv-model.c
Log:
Added support for amounts with currency symbols (e.g., "$100"),
attributed all Gnumeric developers in popup files copied from Gnumeric


Modified: gnucash/branches/csv-import/src/import-export/csv/gnc-csv-gnumeric-popup.c
===================================================================
--- gnucash/branches/csv-import/src/import-export/csv/gnc-csv-gnumeric-popup.c	2007-07-25 06:53:58 UTC (rev 16356)
+++ gnucash/branches/csv-import/src/import-export/csv/gnc-csv-gnumeric-popup.c	2007-07-25 10:28:57 UTC (rev 16357)
@@ -3,6 +3,50 @@
  * gnumeric/src/gui-util.c, and it has been modified slightly to work
  * within GnuCash. */
 
+/* Miguel de Icaza is not sure specifically who from the Gnumeric
+ * community is the copyright owner of the code below, so, on his
+ * recommendation, here is the full list of Gnumeric authors.
+ *
+ * Miguel de Icaza, creator.
+ * Jody Goldberg, maintainer.
+ * Harald Ashburner, Options pricers
+ * Sean Atkinson, functions and X-Base importing.
+ * Michel Berkelaar, Simplex algorithm for Solver (LP Solve).
+ * Jean Brefort, Core charting engine.
+ * Grandma Chema Celorio, Tester and sheet copy.
+ * Frank Chiulli, OLE support.
+ * Kenneth Christiansen, i18n, misc stuff.
+ * Zbigniew Chyla, plugin system, i18n.
+ * J.H.M. Dassen (Ray), debian packaging.
+ * Jeroen Dirks, Simplex algorithm for Solver (LP Solve).
+ * Tom Dyas, plugin support.
+ * Gergo Erdi, Gnumeric hacker.
+ * John Gotts, rpm packaging.
+ * Andreas J. Guelzow, Gnumeric hacker.
+ * Jon K. Hellan, Gnumeric hacker.
+ * Ross Ihaka, special functions.
+ * Jukka-Pekka Iivonen, numerous functions and tools.
+ * Jakub Jelinek, Gnumeric hacker.
+ * Chris Lahey, number format engine.
+ * Adrian Likins, documentation, debugging.
+ * Takashi Matsuda, original text plugin.
+ * Michael Meeks, Excel and OLE2 importing.
+ * Lutz Muller, SheetObject improvements.
+ * Emmanuel Pacaud, Many plot types for charting engine.
+ * Federico M. Quintero, canvas support.
+ * Mark Probst, Guile support.
+ * Rasca, HTML, troff, LaTeX exporters.
+ * Vincent Renardias, original CSV support, French localization.
+ * Ariel Rios, Guile support.
+ * Uwe Steinmann, Paradox Importer.
+ * Arturo Tena, OLE support.
+ * Almer S. Tigelaar, Gnumeric hacker.
+ * Bruno Unna, Excel bits.
+ * Daniel Veillard, XML support.
+ * Vladimir Vuksan, financial functions.
+ * Morten Welinder, Gnumeric hacker and leak plugging demi-god.
+ */
+
 #include "gnc-csv-gnumeric-popup.h"
 
 #include <glib/gi18n.h>

Modified: gnucash/branches/csv-import/src/import-export/csv/gnc-csv-gnumeric-popup.h
===================================================================
--- gnucash/branches/csv-import/src/import-export/csv/gnc-csv-gnumeric-popup.h	2007-07-25 06:53:58 UTC (rev 16356)
+++ gnucash/branches/csv-import/src/import-export/csv/gnc-csv-gnumeric-popup.h	2007-07-25 10:28:57 UTC (rev 16357)
@@ -3,6 +3,50 @@
  * gnumeric/src/gui-util.h, and it has been modified slightly to work
  * within GnuCash. */
 
+/* Miguel de Icaza is not sure specifically who from the Gnumeric
+ * community is the copyright owner of the code below, so, on his
+ * recommendation, here is the full list of Gnumeric authors.
+ *
+ * Miguel de Icaza, creator.
+ * Jody Goldberg, maintainer.
+ * Harald Ashburner, Options pricers
+ * Sean Atkinson, functions and X-Base importing.
+ * Michel Berkelaar, Simplex algorithm for Solver (LP Solve).
+ * Jean Brefort, Core charting engine.
+ * Grandma Chema Celorio, Tester and sheet copy.
+ * Frank Chiulli, OLE support.
+ * Kenneth Christiansen, i18n, misc stuff.
+ * Zbigniew Chyla, plugin system, i18n.
+ * J.H.M. Dassen (Ray), debian packaging.
+ * Jeroen Dirks, Simplex algorithm for Solver (LP Solve).
+ * Tom Dyas, plugin support.
+ * Gergo Erdi, Gnumeric hacker.
+ * John Gotts, rpm packaging.
+ * Andreas J. Guelzow, Gnumeric hacker.
+ * Jon K. Hellan, Gnumeric hacker.
+ * Ross Ihaka, special functions.
+ * Jukka-Pekka Iivonen, numerous functions and tools.
+ * Jakub Jelinek, Gnumeric hacker.
+ * Chris Lahey, number format engine.
+ * Adrian Likins, documentation, debugging.
+ * Takashi Matsuda, original text plugin.
+ * Michael Meeks, Excel and OLE2 importing.
+ * Lutz Muller, SheetObject improvements.
+ * Emmanuel Pacaud, Many plot types for charting engine.
+ * Federico M. Quintero, canvas support.
+ * Mark Probst, Guile support.
+ * Rasca, HTML, troff, LaTeX exporters.
+ * Vincent Renardias, original CSV support, French localization.
+ * Ariel Rios, Guile support.
+ * Uwe Steinmann, Paradox Importer.
+ * Arturo Tena, OLE support.
+ * Almer S. Tigelaar, Gnumeric hacker.
+ * Bruno Unna, Excel bits.
+ * Daniel Veillard, XML support.
+ * Vladimir Vuksan, financial functions.
+ * Morten Welinder, Gnumeric hacker and leak plugging demi-god.
+ */
+
 #ifndef GNC_CSV_GNUMERIC_POPUP
 #define GNC_CSV_GNUMERIC_POPUP
 

Modified: gnucash/branches/csv-import/src/import-export/csv/gnc-csv-model.c
===================================================================
--- gnucash/branches/csv-import/src/import-export/csv/gnc-csv-model.c	2007-07-25 06:53:58 UTC (rev 16356)
+++ gnucash/branches/csv-import/src/import-export/csv/gnc-csv-model.c	2007-07-25 10:28:57 UTC (rev 16357)
@@ -531,8 +531,6 @@
   int type; /**< A value from the GncCsvColumnType enum except
              * GNC_CSV_NONE and GNC_CSV_NUM_COL_TYPES */
   void* value; /**< Pointer to the data that will be used to configure a transaction */
-  /* TODO Try coming up with a more elegant way than storing this for
-   * every transaction safely. */
   TransPropertyList* set; /**< The set the property belongs to */
 } TransProperty;
 
@@ -583,7 +581,7 @@
  */
 static gboolean trans_property_set(TransProperty* prop, char* str)
 {
-  char* endptr;
+  char *endptr, *possible_currency_symbol, *str_dupe;
   double value;
   switch(prop->type)
   {
@@ -597,13 +595,43 @@
     return TRUE;
 
   case GNC_CSV_AMOUNT:
-    value = strtod(str, &endptr);
+    str_dupe = g_strdup(str); /* First, we make a copy so we can't mess up real data. */
+
+    /* Go through str_dupe looking for currency symbols. */
+    for(possible_currency_symbol = str_dupe; possible_currency_symbol;
+        possible_currency_symbol = g_utf8_next_char(possible_currency_symbol))
+    {
+      if(g_unichar_type(g_utf8_get_char(possible_currency_symbol)) == G_UNICODE_CURRENCY_SYMBOL)
+      {
+        /* If we find a currency symbol, save the position just ahead
+         * of the currency symbol (next_symbol), and find the null
+         * terminator of the string (last_symbol). */
+        char *next_symbol = g_utf8_next_char(possible_currency_symbol), *last_symbol = next_symbol;
+        while(*last_symbol)
+          last_symbol = g_utf8_next_char(last_symbol);
+
+        /* Move all of the string (including the null byte, which is
+         * why we have +1 in the size parameter) following the
+         * currency symbol back one character, thereby overwriting the
+         * currency symbol. */
+        memmove(possible_currency_symbol, next_symbol, last_symbol - next_symbol + 1);
+        break;
+      }
+    }
+
+    /* Translate the string (now clean of currency symbols) into a number. */
+    value = strtod(str_dupe, &endptr);
     prop->value = g_new(gnc_numeric, 1);
 
     /* If this isn't a valid numeric string, this is an error. */
-    if(endptr != str + strlen(str))
+    if(endptr != str_dupe + strlen(str_dupe))
+    {
+      g_free(str_dupe);
       return FALSE;
+    }
 
+    g_free(str_dupe);
+
     *((gnc_numeric*)(prop->value)) = double_to_gnc_numeric(value, xaccAccountGetCommoditySCU(prop->set->account),
                                                            GNC_RND_ROUND);
     return TRUE;



More information about the gnucash-changes mailing list