mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add a wrapper function for g_utf8_collate that handles checking for
null pointers or null strings. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13649 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
2006-03-16 David Hampton <hampton@employees.org>
|
2006-03-16 David Hampton <hampton@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-model-account.[ch]:
|
||||||
* src/gnome-utils/gnc-tree-view-account.c: Move the computation of
|
* src/gnome-utils/gnc-tree-view-account.c: Move the computation of
|
||||||
accounting period balances into the model and colorize it.
|
accounting period balances into the model and colorize it.
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ libcore_utils_la_SOURCES = \
|
|||||||
gnc-gconf-utils.c \
|
gnc-gconf-utils.c \
|
||||||
gnc-gdate-utils.c \
|
gnc-gdate-utils.c \
|
||||||
gnc-gkeyfile-utils.c \
|
gnc-gkeyfile-utils.c \
|
||||||
|
gnc-glib-utils.c \
|
||||||
gnc-gobject-utils.c
|
gnc-gobject-utils.c
|
||||||
|
|
||||||
libcore_utils_la_LIBADD = \
|
libcore_utils_la_LIBADD = \
|
||||||
@@ -28,6 +29,7 @@ noinst_HEADERS = \
|
|||||||
gnc-gconf-utils.h \
|
gnc-gconf-utils.h \
|
||||||
gnc-gdate-utils.h \
|
gnc-gdate-utils.h \
|
||||||
gnc-gkeyfile-utils.h \
|
gnc-gkeyfile-utils.h \
|
||||||
|
gnc-glib-utils.h \
|
||||||
gnc-gobject-utils.h \
|
gnc-gobject-utils.h \
|
||||||
gw-core-utils.h
|
gw-core-utils.h
|
||||||
|
|
||||||
|
|||||||
43
src/core-utils/gnc-glib-utils.c
Normal file
43
src/core-utils/gnc-glib-utils.c
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/********************************************************************\
|
||||||
|
* gnc-glib-utils.c -- utility functions based on glib functions *
|
||||||
|
* Copyright (C) 2006 David Hampton <hampton@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@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;
|
||||||
|
}
|
||||||
52
src/core-utils/gnc-glib-utils.h
Normal file
52
src/core-utils/gnc-glib-utils.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/********************************************************************\
|
||||||
|
* gnc-glib-utils.c -- utility functions based on glib functions *
|
||||||
|
* Copyright (C) 2006 David Hampton <hampton@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@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@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 */
|
||||||
|
/** @} */
|
||||||
|
/** @} */
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
#include "GroupP.h"
|
#include "GroupP.h"
|
||||||
#include "TransactionP.h"
|
#include "TransactionP.h"
|
||||||
#include "gnc-event.h"
|
#include "gnc-event.h"
|
||||||
|
#include "gnc-glib-utils.h"
|
||||||
#include "gnc-lot.h"
|
#include "gnc-lot.h"
|
||||||
#include "gnc-lot-p.h"
|
#include "gnc-lot-p.h"
|
||||||
#include "gnc-pricedb.h"
|
#include "gnc-pricedb.h"
|
||||||
@@ -976,7 +977,7 @@ xaccAccountOrder (const Account **aa, const Account **ab)
|
|||||||
{
|
{
|
||||||
char *da, *db;
|
char *da, *db;
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
int ta, tb;
|
int ta, tb, result;
|
||||||
long la, lb;
|
long la, lb;
|
||||||
|
|
||||||
if ( (*aa) && !(*ab) ) return -1;
|
if ( (*aa) && !(*ab) ) return -1;
|
||||||
@@ -1020,15 +1021,9 @@ xaccAccountOrder (const Account **aa, const Account **ab)
|
|||||||
/* otherwise, sort on accountName strings */
|
/* otherwise, sort on accountName strings */
|
||||||
da = (*aa)->accountName;
|
da = (*aa)->accountName;
|
||||||
db = (*ab)->accountName;
|
db = (*ab)->accountName;
|
||||||
if (da && db) {
|
result = safe_utf8_collate(da, db);
|
||||||
gint result = g_utf8_collate(da, db);
|
if (result)
|
||||||
if (result)
|
return result;
|
||||||
return result;
|
|
||||||
} else if (da) {
|
|
||||||
return -1;
|
|
||||||
} else if (db) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* guarantee a stable sort */
|
/* guarantee a stable sort */
|
||||||
return guid_compare (&((*aa)->inst.entity.guid), &((*ab)->inst.entity.guid));
|
return guid_compare (&((*aa)->inst.entity.guid), &((*ab)->inst.entity.guid));
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "gnc-component-manager.h"
|
#include "gnc-component-manager.h"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-gconf-utils.h"
|
#include "gnc-gconf-utils.h"
|
||||||
|
#include "gnc-glib-utils.h"
|
||||||
#include "gnc-gnome-utils.h"
|
#include "gnc-gnome-utils.h"
|
||||||
#include "gnc-icons.h"
|
#include "gnc-icons.h"
|
||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
@@ -218,19 +219,23 @@ sort_namespace (GtkTreeModel *f_model,
|
|||||||
static gint
|
static gint
|
||||||
default_sort (gnc_commodity *comm_a, gnc_commodity *comm_b)
|
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),
|
result = safe_utf8_collate (gnc_commodity_get_namespace (comm_a),
|
||||||
gnc_commodity_get_namespace (comm_b));
|
gnc_commodity_get_namespace (comm_b));
|
||||||
|
if (result != 0) return result;
|
||||||
|
|
||||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
|
result = safe_utf8_collate (gnc_commodity_get_mnemonic (comm_a),
|
||||||
gnc_commodity_get_mnemonic (comm_b));
|
gnc_commodity_get_mnemonic (comm_b));
|
||||||
|
if (result != 0) return result;
|
||||||
|
|
||||||
SAFE_STRCMP (gnc_commodity_get_fullname (comm_a),
|
result = safe_utf8_collate (gnc_commodity_get_fullname (comm_a),
|
||||||
gnc_commodity_get_fullname (comm_b));
|
gnc_commodity_get_fullname (comm_b));
|
||||||
|
if (result != 0) return result;
|
||||||
|
|
||||||
SAFE_STRCMP (gnc_commodity_get_cusip (comm_a),
|
result = safe_utf8_collate (gnc_commodity_get_cusip (comm_a),
|
||||||
gnc_commodity_get_cusip (comm_b));
|
gnc_commodity_get_cusip (comm_b));
|
||||||
|
if (result != 0) return result;
|
||||||
|
|
||||||
fraction_a = gnc_commodity_get_fraction (comm_a);
|
fraction_a = gnc_commodity_get_fraction (comm_a);
|
||||||
fraction_b = gnc_commodity_get_fraction (comm_b);
|
fraction_b = gnc_commodity_get_fraction (comm_b);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "gnc-component-manager.h"
|
#include "gnc-component-manager.h"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-gconf-utils.h"
|
#include "gnc-gconf-utils.h"
|
||||||
|
#include "gnc-glib-utils.h"
|
||||||
#include "gnc-gnome-utils.h"
|
#include "gnc-gnome-utils.h"
|
||||||
#include "gnc-icons.h"
|
#include "gnc-icons.h"
|
||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
@@ -237,11 +238,13 @@ default_sort (GNCPrice *price_a, GNCPrice *price_b)
|
|||||||
curr_a = gnc_price_get_currency (price_a);
|
curr_a = gnc_price_get_currency (price_a);
|
||||||
curr_b = gnc_price_get_currency (price_b);
|
curr_b = gnc_price_get_currency (price_b);
|
||||||
|
|
||||||
SAFE_STRCMP (gnc_commodity_get_namespace (curr_a),
|
result = safe_utf8_collate (gnc_commodity_get_namespace (curr_a),
|
||||||
gnc_commodity_get_namespace (curr_b));
|
gnc_commodity_get_namespace (curr_b));
|
||||||
|
if (result != 0) return result;
|
||||||
|
|
||||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (curr_a),
|
result = safe_utf8_collate (gnc_commodity_get_mnemonic (curr_a),
|
||||||
gnc_commodity_get_mnemonic (curr_b));
|
gnc_commodity_get_mnemonic (curr_b));
|
||||||
|
if (result != 0) return result;
|
||||||
|
|
||||||
/* tertiary sort: time */
|
/* tertiary sort: time */
|
||||||
ts_a = gnc_price_get_time (price_a);
|
ts_a = gnc_price_get_time (price_a);
|
||||||
|
|||||||
Reference in New Issue
Block a user