I have come up with a working fix for bug 450354<http://bugzilla.gnome.org/show_bug.cgi?id=450354>which involves calling the glib function g_locale_from_utf8(). However, this glib function is not available directly from Scheme unless we add a dependency for guile-slib. To avoid that, I created a C function that does the call, then swigified it so that Scheme can use it. A similar technique might be used to make a fix for bug 396665<http://bugzilla.gnome.org/show_bug.cgi?id=396665>, by attempting a conversion using g_locale_to_utf8() before resorting to the current method (character deletion).
So my question is: Is it OK to add this new C function to core-utils, as seen in the attached diff? (If so, I will add comments for C and doxygen. I've already compiled and tested it.) Cheers, Charles
Index: src/core-utils/gnc-glib-utils.c =================================================================== --- src/core-utils/gnc-glib-utils.c (revision 17061) +++ src/core-utils/gnc-glib-utils.c (working copy) @@ -229,6 +229,20 @@ return result; } +gchar * +gnc_locale_from_utf8(const gchar* str) +{ + gchar * locale_str; + gsize bytes_written = 0; + GError * err = NULL; + + locale_str = g_locale_from_utf8(str, -1, NULL, &bytes_written, &err); + if (err) + g_warning("g_locale_from_utf8 failed: %s", err->message); + + return locale_str; +} + GList* gnc_g_list_map(GList* list, GncGMapFunc fn, gpointer user_data) { Index: src/core-utils/gnc-glib-utils.h =================================================================== --- src/core-utils/gnc-glib-utils.h (revision 17061) +++ src/core-utils/gnc-glib-utils.h (working copy) @@ -80,6 +80,7 @@ * @return A newly allocated string that has to be g_free'd by the * caller. */ gchar *gnc_utf8_strip_invalid_strdup (const gchar* str); +gchar *gnc_locale_from_utf8(const gchar* str); typedef gpointer (*GncGMapFunc)(gpointer data, gpointer user_data); Index: src/core-utils/core-utils.scm =================================================================== --- src/core-utils/core-utils.scm (revision 17061) +++ src/core-utils/core-utils.scm (working copy) @@ -12,6 +12,7 @@ (re-export gnc-is-debugging) (re-export g-find-program-in-path) (re-export gnc-utf8-strip-invalid-strdup) +(re-export gnc-locale-from-utf8) (re-export gnc-scm-log-warn) (re-export gnc-scm-log-error) (re-export gnc-scm-log-msg) Index: src/core-utils/core-utils.i =================================================================== --- src/core-utils/core-utils.i (revision 17061) +++ src/core-utils/core-utils.i (working copy) @@ -21,3 +21,5 @@ %newobject gnc_utf8_strip_invalid_strdup; gchar * gnc_utf8_strip_invalid_strdup(const gchar *); +%newobject gnc_locale_from_utf8; +gchar * gnc_locale_from_utf8(const gchar *);
_______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel