[Gnucash-changes] r13507 - gnucash/trunk/src - Factor out and create new function: gnc_commodity_is_currency().

Chris Shoemaker chris at cvs.gnucash.org
Mon Mar 6 21:42:12 EST 2006


Author: chris
Date: 2006-03-06 21:42:12 -0500 (Mon, 06 Mar 2006)
New Revision: 13507
Trac: http://svn.gnucash.org/trac/changeset/13507

Modified:
   gnucash/trunk/src/engine/Scrub.c
   gnucash/trunk/src/engine/gnc-commodity.c
   gnucash/trunk/src/engine/gnc-commodity.h
   gnucash/trunk/src/register/ledger-core/split-register-load.c
Log:
   Factor out and create new function: gnc_commodity_is_currency().


Modified: gnucash/trunk/src/engine/Scrub.c
===================================================================
--- gnucash/trunk/src/engine/Scrub.c	2006-03-07 00:39:29 UTC (rev 13506)
+++ gnucash/trunk/src/engine/Scrub.c	2006-03-07 02:42:12 UTC (rev 13507)
@@ -354,10 +354,7 @@
       gnc_commodity *s_commodity = xaccAccountGetCommodity (s_account);
       
       if (s_commodity) {
-        const char * namespace = gnc_commodity_get_namespace (s_commodity);
-        if (!safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) ||
-            !safe_strcmp (namespace, GNC_COMMODITY_NS_LEGACY)) {
-
+        if (gnc_commodity_is_currency(s_commodity)) {
           /* Found a split where the amount is the same as the value and
              the commodity is a currency.  If all splits in the transaction
              that fit this description are in the same currency then the

Modified: gnucash/trunk/src/engine/gnc-commodity.c
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.c	2006-03-07 00:39:29 UTC (rev 13506)
+++ gnucash/trunk/src/engine/gnc-commodity.c	2006-03-07 02:42:12 UTC (rev 13507)
@@ -1334,6 +1334,17 @@
   return (safe_strcmp(ns_name, GNC_COMMODITY_NS_ISO) == 0);
 }
 
+gboolean
+gnc_commodity_is_currency(const gnc_commodity *cm)
+{
+    const char *ns_name;
+    if (!cm) return FALSE;
+
+    ns_name = gnc_commodity_namespace_get_name(cm->namespace);
+    return (!safe_strcmp(ns_name, GNC_COMMODITY_NS_LEGACY) ||
+            !safe_strcmp(ns_name, GNC_COMMODITY_NS_ISO));
+}
+
 /********************************************************************
  * gnc_commodity_table_get_commodities
  * list commodities in a give namespace 

Modified: gnucash/trunk/src/engine/gnc-commodity.h
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.h	2006-03-07 00:39:29 UTC (rev 13506)
+++ gnucash/trunk/src/engine/gnc-commodity.h	2006-03-07 02:42:12 UTC (rev 13507)
@@ -574,6 +574,15 @@
  *
  *  @return TRUE if the commodity represents a currency, FALSE otherwise. */
 gboolean gnc_commodity_is_iso(const gnc_commodity * cm);
+
+/** Checks to see if the specified commodity is an ISO 4217 recognized
+ * currency or a legacy currency.
+ *
+ *  @param cm The commodity to check.
+ *
+ *  @return TRUE if the commodity represents a currency, FALSE otherwise. */
+gboolean gnc_commodity_is_currency(const gnc_commodity *cm);
+
 /** @} */
 
 

Modified: gnucash/trunk/src/register/ledger-core/split-register-load.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-load.c	2006-03-07 00:39:29 UTC (rev 13506)
+++ gnucash/trunk/src/register/ledger-core/split-register-load.c	2006-03-07 02:42:12 UTC (rev 13507)
@@ -194,12 +194,8 @@
      */
     if (default_account != NULL) {
       gnc_commodity * commodity = xaccAccountGetCommodity (default_account);
-      if (commodity) {
-	const char * namespace = gnc_commodity_get_namespace (commodity);
-	if (!safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) ||
-	    !safe_strcmp (namespace, GNC_COMMODITY_NS_LEGACY))
-	  currency = commodity;
-      }
+      if (gnc_commodity_is_currency(commodity))
+          currency = commodity;
     }
 
     gnc_suspend_gui_refresh ();



More information about the gnucash-changes mailing list