Mercurial > dwindows
comparison gtk/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 | 97b1edb41d44 |
comparison
equal
deleted
inserted
replaced
1784:86ace55df07b | 1785:c5ea64e8b436 |
---|---|
13650 if(sh.data == data) | 13650 if(sh.data == data) |
13651 _remove_signal_handler(thiswindow, z); | 13651 _remove_signal_handler(thiswindow, z); |
13652 } | 13652 } |
13653 DW_MUTEX_UNLOCK; | 13653 DW_MUTEX_UNLOCK; |
13654 } | 13654 } |
13655 | |
13656 /* | |
13657 * Converts a UTF-8 encoded string into a wide string. | |
13658 * Parameters: | |
13659 * utf8string: UTF-8 encoded source string. | |
13660 * Returns: | |
13661 * Wide string that needs to be freed with dw_free() | |
13662 * or NULL on failure. | |
13663 */ | |
13664 wchar_t * API dw_utf8_to_wchar(char *utf8string) | |
13665 { | |
13666 wchar_t *retval = NULL, *freeme; | |
13667 | |
13668 if(sizeof(wchar_t) == sizeof(gunichar)) | |
13669 freeme = retval = (wchar_t *)g_utf8_to_ucs4(utf8string, -1, NULL, NULL, NULL); | |
13670 else if(sizeof(wchar_t) == sizeof(gunichar2)) | |
13671 freeme = retval = (wchar_t *)g_utf8_to_utf16(utf8string, -1, NULL, NULL, NULL); | |
13672 if(retval) | |
13673 { | |
13674 retval = wcsdup(retval); | |
13675 g_free(freeme); | |
13676 } | |
13677 return retval; | |
13678 } | |
13679 | |
13680 /* | |
13681 * Converts a wide string into a UTF-8 encoded string. | |
13682 * Parameters: | |
13683 * wstring: Wide source string. | |
13684 * Returns: | |
13685 * UTF-8 encoded string that needs to be freed with dw_free() | |
13686 * or NULL on failure. | |
13687 */ | |
13688 char * API dw_wchar_to_utf8(wchar_t *wstring) | |
13689 { | |
13690 char *retval = NULL, *freeme; | |
13691 | |
13692 if(sizeof(wchar_t) == sizeof(gunichar)) | |
13693 freeme = retval = g_ucs4_to_utf8((gunichar *)wstring, -1, NULL, NULL, NULL); | |
13694 else if(sizeof(wchar_t) == sizeof(gunichar2)) | |
13695 freeme = retval = g_utf16_to_utf8((gunichar2 *)wstring, -1, NULL, NULL, NULL); | |
13696 if(retval) | |
13697 { | |
13698 retval = strdup(retval); | |
13699 g_free(freeme); | |
13700 } | |
13701 return retval; | |
13702 } | |
13703 |