Mercurial > dwindows
diff gtk3/dw.c @ 1785:c5ea64e8b436
Added UTF8/Wide conversion for GTK2/3.
Also added some code in the test program to use it.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 25 Jul 2012 00:46:00 +0000 |
parents | d81bebc5c8cc |
children | 2cfbfccbbafe |
line wrap: on
line diff
--- a/gtk3/dw.c Tue Jul 24 23:33:50 2012 +0000 +++ b/gtk3/dw.c Wed Jul 25 00:46:00 2012 +0000 @@ -11360,3 +11360,51 @@ DW_MUTEX_UNLOCK; } +/* + * Converts a UTF-8 encoded string into a wide string. + * Parameters: + * utf8string: UTF-8 encoded source string. + * Returns: + * Wide string that needs to be freed with dw_free() + * or NULL on failure. + */ +wchar_t * API dw_utf8_to_wchar(char *utf8string) +{ + wchar_t *retval = NULL, *freeme; + + if(sizeof(wchar_t) == sizeof(gunichar)) + freeme = retval = (wchar_t *)g_utf8_to_ucs4(utf8string, -1, NULL, NULL, NULL); + else if(sizeof(wchar_t) == sizeof(gunichar2)) + freeme = retval = (wchar_t *)g_utf8_to_utf16(utf8string, -1, NULL, NULL, NULL); + if(retval) + { + retval = wcsdup(retval); + g_free(freeme); + } + return retval; +} + +/* + * Converts a wide string into a UTF-8 encoded string. + * Parameters: + * wstring: Wide source string. + * Returns: + * UTF-8 encoded string that needs to be freed with dw_free() + * or NULL on failure. + */ +char * API dw_wchar_to_utf8(wchar_t *wstring) +{ + char *retval = NULL, *freeme; + + if(sizeof(wchar_t) == sizeof(gunichar)) + freeme = retval = g_ucs4_to_utf8((gunichar *)wstring, -1, NULL, NULL, NULL); + else if(sizeof(wchar_t) == sizeof(gunichar2)) + freeme = retval = g_utf16_to_utf8((gunichar2 *)wstring, -1, NULL, NULL, NULL); + if(retval) + { + retval = strdup(retval); + g_free(freeme); + } + return retval; +} +