[Gnucash-changes] Treat the dash and underscore characters the same
when looking up an
David Hampton
hampton at cvs.gnucash.org
Sun Jun 5 00:33:26 EDT 2005
Log Message:
-----------
Treat the dash and underscore characters the same when
looking up an enum by name.
Tags:
----
gnucash-gnome2-dev
Modified Files:
--------------
gnucash/src/core-utils:
gnc-gconf-utils.c
Revision Data
-------------
Index: gnc-gconf-utils.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/core-utils/Attic/gnc-gconf-utils.c,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -Lsrc/core-utils/gnc-gconf-utils.c -Lsrc/core-utils/gnc-gconf-utils.c -u -r1.1.2.3 -r1.1.2.4
--- src/core-utils/gnc-gconf-utils.c
+++ src/core-utils/gnc-gconf-utils.c
@@ -25,6 +25,7 @@
#include "config.h"
#include <stdio.h>
+#include <strings.h>
#include "gnc-gconf-utils.h"
#define APP_GNUCASH "/apps/gnucash/%s"
@@ -66,6 +67,7 @@
{
GEnumClass *enum_class;
GEnumValue *enum_value;
+ gchar *alt_name, *ptr;
/* Lookup the enum class in the glib type system */
enum_class = g_type_class_ref (type);
@@ -78,6 +80,27 @@
enum_value = g_enum_get_value_by_nick(enum_class, name);
if (enum_value)
return enum_value->value;
+
+ /* Flip '-' and '_' and try again */
+ alt_name = g_strdup(name);
+ if ((ptr = index(alt_name, '-')) != NULL) {
+ do {
+ *ptr++ = '_';
+ } while ((ptr = index(ptr, '-')) != NULL);
+ } else if ((ptr = index(alt_name, '_')) != NULL) {
+ do {
+ *ptr++ = '-';
+ } while ((ptr = index(ptr, '_')) != NULL);
+ } else {
+ g_free(alt_name);
+ return default_value;
+ }
+
+ /* Lookup the specified enum in the class */
+ enum_value = g_enum_get_value_by_nick(enum_class, alt_name);
+ g_free(alt_name);
+ if (enum_value)
+ return enum_value->value;
return default_value;
}
More information about the gnucash-changes
mailing list