r15512 - gnucash/trunk/src/app-utils - Fix gnc_lconv_set_utf8 on Windows, #403815.
Andreas Köhler
andi5 at cvs.gnucash.org
Mon Feb 5 22:37:18 EST 2007
Author: andi5
Date: 2007-02-05 22:37:17 -0500 (Mon, 05 Feb 2007)
New Revision: 15512
Trac: http://svn.gnucash.org/trac/changeset/15512
Modified:
gnucash/trunk/src/app-utils/gnc-ui-util.c
Log:
Fix gnc_lconv_set_utf8 on Windows, #403815.
The result of g_get_charset does not necessarily match the encoding of
strings returned by CRT functions like localeconv or strftime. In
gnc_lconv_set_utf8, convert the strings first to a wide character string
with mbstowcs and then to utf8 by g_utf16_to_utf8.
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c 2007-02-06 00:45:43 UTC (rev 15511)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c 2007-02-06 03:37:17 UTC (rev 15512)
@@ -732,18 +732,34 @@
gnc_lconv_set_utf8 (char **p_value, char *default_value)
{
char *value = *p_value;
+ *p_value = NULL;
if ((value == NULL) || (value[0] == 0))
- *p_value = default_value;
+ value = default_value;
- *p_value = g_locale_to_utf8 (*p_value, -1, NULL, NULL, NULL);
+#ifdef G_OS_WIN32
+ {
+ /* get number of resulting wide characters */
+ size_t count = mbstowcs (NULL, value, 0);
+ if (count > 0) {
+ /* malloc and convert */
+ wchar_t *wvalue = g_malloc ((count+1) * sizeof(wchar_t));
+ count = mbstowcs (wvalue, value, count+1);
+ if (count > 0) {
+ *p_value = g_utf16_to_utf8 (wvalue, -1, NULL, NULL, NULL);
+ }
+ g_free (wvalue);
+ }
+ }
+#else /* !G_OS_WIN32 */
+ *p_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
+#endif
+
if (*p_value == NULL) {
// The g_locale_to_utf8 conversion failed. FIXME: Should we rather
// use an empty string instead of the default_value? Not sure.
*p_value = default_value;
}
- // FIXME: Do we really need to make a copy here ?
- //*p_value = g_strdup (*p_value);
}
static void
More information about the gnucash-changes
mailing list