comparison 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
comparison
equal deleted inserted replaced
1784:86ace55df07b 1785:c5ea64e8b436
11358 _remove_signal_handler(thiswindow, z); 11358 _remove_signal_handler(thiswindow, z);
11359 } 11359 }
11360 DW_MUTEX_UNLOCK; 11360 DW_MUTEX_UNLOCK;
11361 } 11361 }
11362 11362
11363 /*
11364 * Converts a UTF-8 encoded string into a wide string.
11365 * Parameters:
11366 * utf8string: UTF-8 encoded source string.
11367 * Returns:
11368 * Wide string that needs to be freed with dw_free()
11369 * or NULL on failure.
11370 */
11371 wchar_t * API dw_utf8_to_wchar(char *utf8string)
11372 {
11373 wchar_t *retval = NULL, *freeme;
11374
11375 if(sizeof(wchar_t) == sizeof(gunichar))
11376 freeme = retval = (wchar_t *)g_utf8_to_ucs4(utf8string, -1, NULL, NULL, NULL);
11377 else if(sizeof(wchar_t) == sizeof(gunichar2))
11378 freeme = retval = (wchar_t *)g_utf8_to_utf16(utf8string, -1, NULL, NULL, NULL);
11379 if(retval)
11380 {
11381 retval = wcsdup(retval);
11382 g_free(freeme);
11383 }
11384 return retval;
11385 }
11386
11387 /*
11388 * Converts a wide string into a UTF-8 encoded string.
11389 * Parameters:
11390 * wstring: Wide source string.
11391 * Returns:
11392 * UTF-8 encoded string that needs to be freed with dw_free()
11393 * or NULL on failure.
11394 */
11395 char * API dw_wchar_to_utf8(wchar_t *wstring)
11396 {
11397 char *retval = NULL, *freeme;
11398
11399 if(sizeof(wchar_t) == sizeof(gunichar))
11400 freeme = retval = g_ucs4_to_utf8((gunichar *)wstring, -1, NULL, NULL, NULL);
11401 else if(sizeof(wchar_t) == sizeof(gunichar2))
11402 freeme = retval = g_utf16_to_utf8((gunichar2 *)wstring, -1, NULL, NULL, NULL);
11403 if(retval)
11404 {
11405 retval = strdup(retval);
11406 g_free(freeme);
11407 }
11408 return retval;
11409 }
11410