[Gnucash-changes] r13649 - gnucash/trunk - Add a wrapper function
for g_utf8_collate that handles checking for
David Hampton
hampton at cvs.gnucash.org
Thu Mar 16 15:26:54 EST 2006
Author: hampton
Date: 2006-03-16 15:26:53 -0500 (Thu, 16 Mar 2006)
New Revision: 13649
Trac: http://svn.gnucash.org/trac/changeset/13649
Added:
gnucash/trunk/src/core-utils/gnc-glib-utils.c
gnucash/trunk/src/core-utils/gnc-glib-utils.h
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/core-utils/Makefile.am
gnucash/trunk/src/engine/Account.c
gnucash/trunk/src/gnome-utils/gnc-tree-view-commodity.c
gnucash/trunk/src/gnome-utils/gnc-tree-view-price.c
Log:
Add a wrapper function for g_utf8_collate that handles checking for
null pointers or null strings.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-03-16 20:10:16 UTC (rev 13648)
+++ gnucash/trunk/ChangeLog 2006-03-16 20:26:53 UTC (rev 13649)
@@ -1,5 +1,12 @@
2006-03-16 David Hampton <hampton at employees.org>
+ * src/gnome-utils/gnc-tree-view-commodity.c:
+ * src/gnome-utils/gnc-tree-view-price.c:
+ * src/engine/Account.c:
+ * src/core-utils/gnc-glib-utils.[ch]: Add a wrapper function for
+ g_utf8_collate that handles checking for null pointers or null
+ strings.
+
* src/gnome-utils/gnc-tree-model-account.[ch]:
* src/gnome-utils/gnc-tree-view-account.c: Move the computation of
accounting period balances into the model and colorize it.
Modified: gnucash/trunk/src/core-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/core-utils/Makefile.am 2006-03-16 20:10:16 UTC (rev 13648)
+++ gnucash/trunk/src/core-utils/Makefile.am 2006-03-16 20:26:53 UTC (rev 13649)
@@ -6,6 +6,7 @@
gnc-gconf-utils.c \
gnc-gdate-utils.c \
gnc-gkeyfile-utils.c \
+ gnc-glib-utils.c \
gnc-gobject-utils.c
libcore_utils_la_LIBADD = \
@@ -28,6 +29,7 @@
gnc-gconf-utils.h \
gnc-gdate-utils.h \
gnc-gkeyfile-utils.h \
+ gnc-glib-utils.h \
gnc-gobject-utils.h \
gw-core-utils.h
Added: gnucash/trunk/src/core-utils/gnc-glib-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-glib-utils.c 2006-03-16 20:10:16 UTC (rev 13648)
+++ gnucash/trunk/src/core-utils/gnc-glib-utils.c 2006-03-16 20:26:53 UTC (rev 13649)
@@ -0,0 +1,43 @@
+/********************************************************************\
+ * gnc-glib-utils.c -- utility functions based on glib functions *
+ * Copyright (C) 2006 David Hampton <hampton at employees.org> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+ * *
+\********************************************************************/
+
+#include "config.h"
+
+#include "gnc-glib-utils.h"
+
+int
+safe_utf8_collate (const char * da, const char * db)
+{
+ if (da && !(*da))
+ da = NULL;
+ if (db && !(*db))
+ db = NULL;
+
+ if (da && db)
+ return g_utf8_collate(da, db);
+ if (da)
+ return 1;
+ if (db)
+ return -1;
+ return 0;
+}
Added: gnucash/trunk/src/core-utils/gnc-glib-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-glib-utils.h 2006-03-16 20:10:16 UTC (rev 13648)
+++ gnucash/trunk/src/core-utils/gnc-glib-utils.h 2006-03-16 20:26:53 UTC (rev 13649)
@@ -0,0 +1,52 @@
+/********************************************************************\
+ * gnc-glib-utils.c -- utility functions based on glib functions *
+ * Copyright (C) 2006 David Hampton <hampton at employees.org> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+ * *
+\********************************************************************/
+
+/** @addtogroup GLib
+ @{ */
+/** @addtogroup GConf GLib Utilities
+
+ The API in this file is designed to provide support functions that
+ wrap the base glib functions and make them easier to use.
+
+ @{ */
+/** @file gnc-glib-utils.h
+ * @brief glib helper routines.
+ * @author Copyright (C) 2006 David Hampton <hampton at employees.org>
+ */
+
+#ifndef GNC_GLIB_UTILS_H
+#define GNC_GLIB_UTILS_H
+
+#include <glib.h>
+
+/** @name glib Miscellaneous Functions
+ @{
+*/
+
+int safe_utf8_collate (const char * da, const char * db);
+
+/** @} */
+
+#endif /* GNC_GLIB_UTILS_H */
+/** @} */
+/** @} */
Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c 2006-03-16 20:10:16 UTC (rev 13648)
+++ gnucash/trunk/src/engine/Account.c 2006-03-16 20:26:53 UTC (rev 13649)
@@ -34,6 +34,7 @@
#include "GroupP.h"
#include "TransactionP.h"
#include "gnc-event.h"
+#include "gnc-glib-utils.h"
#include "gnc-lot.h"
#include "gnc-lot-p.h"
#include "gnc-pricedb.h"
@@ -976,7 +977,7 @@
{
char *da, *db;
char *endptr = NULL;
- int ta, tb;
+ int ta, tb, result;
long la, lb;
if ( (*aa) && !(*ab) ) return -1;
@@ -1020,15 +1021,9 @@
/* otherwise, sort on accountName strings */
da = (*aa)->accountName;
db = (*ab)->accountName;
- if (da && db) {
- gint result = g_utf8_collate(da, db);
- if (result)
- return result;
- } else if (da) {
- return -1;
- } else if (db) {
- return 1;
- }
+ result = safe_utf8_collate(da, db);
+ if (result)
+ return result;
/* guarantee a stable sort */
return guid_compare (&((*aa)->inst.entity.guid), &((*ab)->inst.entity.guid));
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-commodity.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-commodity.c 2006-03-16 20:10:16 UTC (rev 13648)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-commodity.c 2006-03-16 20:26:53 UTC (rev 13649)
@@ -36,6 +36,7 @@
#include "gnc-component-manager.h"
#include "gnc-engine.h"
#include "gnc-gconf-utils.h"
+#include "gnc-glib-utils.h"
#include "gnc-gnome-utils.h"
#include "gnc-icons.h"
#include "gnc-ui-util.h"
@@ -218,19 +219,23 @@
static gint
default_sort (gnc_commodity *comm_a, gnc_commodity *comm_b)
{
- gint fraction_a, fraction_b;
+ gint fraction_a, fraction_b, result;
- SAFE_STRCMP (gnc_commodity_get_namespace (comm_a),
- gnc_commodity_get_namespace (comm_b));
+ result = safe_utf8_collate (gnc_commodity_get_namespace (comm_a),
+ gnc_commodity_get_namespace (comm_b));
+ if (result != 0) return result;
- SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
- gnc_commodity_get_mnemonic (comm_b));
+ result = safe_utf8_collate (gnc_commodity_get_mnemonic (comm_a),
+ gnc_commodity_get_mnemonic (comm_b));
+ if (result != 0) return result;
- SAFE_STRCMP (gnc_commodity_get_fullname (comm_a),
- gnc_commodity_get_fullname (comm_b));
+ result = safe_utf8_collate (gnc_commodity_get_fullname (comm_a),
+ gnc_commodity_get_fullname (comm_b));
+ if (result != 0) return result;
- SAFE_STRCMP (gnc_commodity_get_cusip (comm_a),
- gnc_commodity_get_cusip (comm_b));
+ result = safe_utf8_collate (gnc_commodity_get_cusip (comm_a),
+ gnc_commodity_get_cusip (comm_b));
+ if (result != 0) return result;
fraction_a = gnc_commodity_get_fraction (comm_a);
fraction_b = gnc_commodity_get_fraction (comm_b);
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-price.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-price.c 2006-03-16 20:10:16 UTC (rev 13648)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-price.c 2006-03-16 20:26:53 UTC (rev 13649)
@@ -36,6 +36,7 @@
#include "gnc-component-manager.h"
#include "gnc-engine.h"
#include "gnc-gconf-utils.h"
+#include "gnc-glib-utils.h"
#include "gnc-gnome-utils.h"
#include "gnc-icons.h"
#include "gnc-ui-util.h"
@@ -237,11 +238,13 @@
curr_a = gnc_price_get_currency (price_a);
curr_b = gnc_price_get_currency (price_b);
- SAFE_STRCMP (gnc_commodity_get_namespace (curr_a),
- gnc_commodity_get_namespace (curr_b));
+ result = safe_utf8_collate (gnc_commodity_get_namespace (curr_a),
+ gnc_commodity_get_namespace (curr_b));
+ if (result != 0) return result;
- SAFE_STRCMP (gnc_commodity_get_mnemonic (curr_a),
- gnc_commodity_get_mnemonic (curr_b));
+ result = safe_utf8_collate (gnc_commodity_get_mnemonic (curr_a),
+ gnc_commodity_get_mnemonic (curr_b));
+ if (result != 0) return result;
/* tertiary sort: time */
ts_a = gnc_price_get_time (price_a);
More information about the gnucash-changes
mailing list