[Gnucash-changes] add a utility routine,
do some minor performance tuning.
Linas Vepstas
linas at cvs.gnucash.org
Mon May 31 11:22:57 EDT 2004
Log Message:
-----------
add a utility routine, do some minor performance tuning.
Modified Files:
--------------
gnucash/src/gnome-utils:
QuickFill.c
QuickFill.h
Revision Data
-------------
Index: QuickFill.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/QuickFill.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lsrc/gnome-utils/QuickFill.h -Lsrc/gnome-utils/QuickFill.h -u -r1.3 -r1.4
--- src/gnome-utils/QuickFill.h
+++ src/gnome-utils/QuickFill.h
@@ -29,8 +29,9 @@
#include <glib.h>
/** @addtogroup QuickFill
- QuickFill is meant to be used to quickly auto-complete typed
- user input. Quickfill is implemented as a heirarchical tree
+ QuickFill is meant to be used by the GUI to auto-complete
+ (e.g. tab-complete) typed user input.
+ Quickfill is implemented as a heirarchical tree
of partial matching strings. The root of the tree contains
all of the strings that user input should be matched to.
Then, given a short string segment, quickfill will return
@@ -38,6 +39,9 @@
substring. As additional letters are added to the substring,
Quickfill will thus narrow down to the unique matching string
(or to nothing if no match).
+
+ QuickFill works with national-language i18n'ed/l10n'ed multi-byte
+ and wide-char strings, as well as plain-old C-locale strings.
@{
@file QuickFill.h
@@ -91,9 +95,22 @@
QuickFill * gnc_quickfill_get_string_match (QuickFill *qf,
const GdkWChar *str);
+/** Same as gnc_quickfill_get_string_match(), except that the
+ * string length is explicilty specified.
+ */
QuickFill * gnc_quickfill_get_string_len_match (QuickFill *qf,
const GdkWChar *str, int len);
+/** Same as gnc_quickfill_get_string_match(), except that the
+ * desired match string is specified as a traditional string
+ * (may be single or multi-byte). The input string is converted
+ * to wide-chars before the actual macthing is performed.
+ * (This routine is a utility wrapper for
+ * gnc_quickfill_get_string_match ()).
+ */
+QuickFill * gnc_quickfill_get_string_match_mb (QuickFill *qf,
+ const char *str);
+
/** Walk a 'unique' part of the quickfill tree. This routine is
* typically used to assist in the tab-completion of strings.
* If the inital portion of the string is unique, but some later
Index: QuickFill.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/QuickFill.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lsrc/gnome-utils/QuickFill.c -Lsrc/gnome-utils/QuickFill.c -u -r1.2 -r1.3
--- src/gnome-utils/QuickFill.c
+++ src/gnome-utils/QuickFill.c
@@ -61,6 +61,7 @@
/********************************************************************\
\********************************************************************/
+
static guint
quickfill_hash (gconstpointer key)
{
@@ -78,6 +79,7 @@
/********************************************************************\
\********************************************************************/
+
QuickFill *
gnc_quickfill_new (void)
{
@@ -105,6 +107,7 @@
/********************************************************************\
\********************************************************************/
+
static void
destroy_helper (gpointer key, gpointer value, gpointer data)
{
@@ -131,6 +134,7 @@
/********************************************************************\
\********************************************************************/
+
const char *
gnc_quickfill_string (QuickFill *qf)
{
@@ -142,27 +146,35 @@
/********************************************************************\
\********************************************************************/
+
QuickFill *
gnc_quickfill_get_char_match (QuickFill *qf, GdkWChar wc)
{
guint key = iswlower (wc) ? towupper (wc) : wc;
- if (qf == NULL)
- return NULL;
+ if (NULL == qf) return NULL;
DEBUG ("xaccGetQuickFill(): index = %u\n", key);
+#if DEBUG_ME
+ GdkWChar s[2];
+ s[0] = wc;
+ s[1] = 0;
+ char * r= gnc_wcstombs (s);
+ PINFO ("ascii char=%s (%d)\n", r, (int) r[0]);
+#endif
return g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
}
/********************************************************************\
\********************************************************************/
+
QuickFill *
gnc_quickfill_get_string_len_match (QuickFill *qf,
const GdkWChar *str, int len)
{
- if (str == NULL)
- return NULL;
+ if (NULL == qf) return NULL;
+ if (NULL == str) return NULL;
while ((*str != 0) && (len > 0))
{
@@ -180,17 +192,40 @@
/********************************************************************\
\********************************************************************/
+
QuickFill *
gnc_quickfill_get_string_match (QuickFill *qf, const GdkWChar *str)
{
- if (str == NULL)
- return NULL;
+ if (NULL == qf) return NULL;
+ if (NULL == str) return NULL;
return gnc_quickfill_get_string_len_match (qf, str, gnc_wcslen (str));
}
/********************************************************************\
\********************************************************************/
+
+QuickFill *
+gnc_quickfill_get_string_match_mb (QuickFill *qf, const char *str)
+{
+ GdkWChar *wc_text;
+
+ if (NULL == qf) return NULL;
+ if (NULL == str) return NULL;
+
+ /* The match routines all expect wide-chars. */
+ if (gnc_mbstowcs (&wc_text, str) < 0)
+ {
+ PERR ("bad text conversion");
+ return NULL;
+ }
+
+ return gnc_quickfill_get_string_len_match (qf, wc_text, gnc_wcslen (wc_text));
+}
+
+/********************************************************************\
+\********************************************************************/
+
static void
unique_len_helper (gpointer key, gpointer value, gpointer data)
{
@@ -228,21 +263,20 @@
/********************************************************************\
\********************************************************************/
+
void
gnc_quickfill_insert (QuickFill *qf, const char *text, QuickFillSort sort)
{
GdkWChar *wc_text;
- if (text)
+ if (NULL == qf) return;
+ if (NULL == text) return;
+
+ if (gnc_mbstowcs (&wc_text, text) < 0)
{
- if (gnc_mbstowcs (&wc_text, text) < 0)
- {
- PERR ("bad text conversion");
- return;
- }
+ PERR ("bad text conversion");
+ return;
}
- else
- wc_text = NULL;
quickfill_insert_recursive (qf, wc_text, 0, text, sort);
@@ -255,17 +289,15 @@
{
char *mb_text;
- if (text)
+ if (NULL == qf) return;
+ if (NULL == text) return;
+
+ mb_text = gnc_wcstombs (text);
+ if (mb_text == NULL)
{
- mb_text = gnc_wcstombs (text);
- if (mb_text == NULL)
- {
- PERR ("bad text conversion");
- return;
- }
+ PERR ("bad text conversion");
+ return;
}
- else
- mb_text = NULL;
quickfill_insert_recursive (qf, text, 0, mb_text, sort);
@@ -274,6 +306,7 @@
/********************************************************************\
\********************************************************************/
+
static void
quickfill_insert_recursive (QuickFill *qf, const GdkWChar *text, int depth,
const char *mb_text, QuickFillSort sort)
@@ -283,11 +316,7 @@
QuickFill *match_qf;
int len;
- if (qf == NULL)
- return;
-
- if ((text == NULL) || (text[depth] == 0))
- return;
+ if (text[depth] == 0) return;
key = iswlower (text[depth]) ? towupper (text[depth]) : text[depth];
More information about the gnucash-changes
mailing list