mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15512 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -732,18 +732,34 @@ static void
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user