comparison mac/dw.m @ 1784:86ace55df07b

Added UTF8/Wide conversion functions on OS/2 and Windows... Updated the readme file and some comment cleanups.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 24 Jul 2012 23:33:50 +0000
parents 9de6d1cc8fb8
children 9a32d4216f24
comparison
equal deleted inserted replaced
1783:9de6d1cc8fb8 1784:86ace55df07b
11033 /* 11033 /*
11034 * Converts a UTF-8 encoded string into a wide string. 11034 * Converts a UTF-8 encoded string into a wide string.
11035 * Parameters: 11035 * Parameters:
11036 * utf8string: UTF-8 encoded source string. 11036 * utf8string: UTF-8 encoded source string.
11037 * Returns: 11037 * Returns:
11038 * Wide string that needs to be freed with dw_free(). 11038 * Wide string that needs to be freed with dw_free()
11039 * or NULL on failure.
11039 */ 11040 */
11040 wchar_t * API dw_utf8_to_wchar(char *utf8string) 11041 wchar_t * API dw_utf8_to_wchar(char *utf8string)
11041 { 11042 {
11042 size_t buflen = strlen(utf8string) + 1; 11043 size_t buflen = strlen(utf8string) + 1;
11043 wchar_t *buffer = malloc(buflen * sizeof(wchar_t)); 11044 wchar_t *temp = malloc(buflen * sizeof(wchar_t));
11044 mbstowcs(buffer, utf8string, buflen); 11045 if(temp)
11045 return buffer; 11046 mbstowcs(temp, utf8string, buflen);
11047 return temp;
11046 } 11048 }
11047 11049
11048 /* 11050 /*
11049 * Converts a wide string into a UTF-8 encoded string. 11051 * Converts a wide string into a UTF-8 encoded string.
11050 * Parameters: 11052 * Parameters:
11051 * wstring: Wide source string. 11053 * wstring: Wide source string.
11052 * Returns: 11054 * Returns:
11053 * UTF-8 encoded string that needs to be freed with dw_free(). 11055 * UTF-8 encoded string that needs to be freed with dw_free()
11056 * or NULL on failure.
11054 */ 11057 */
11055 char * API dw_wchar_to_utf8(wchar_t *wstring) 11058 char * API dw_wchar_to_utf8(wchar_t *wstring)
11056 { 11059 {
11057 size_t bufflen = 8 * wcslen(wstring) + 1; 11060 size_t bufflen = 8 * wcslen(wstring) + 1;
11058 char *temp = malloc(bufflen); 11061 char *temp = malloc(bufflen);
11059 wcstombs(temp, wstring, bufflen); 11062 if(temp)
11063 wcstombs(temp, wstring, bufflen);
11060 return temp; 11064 return temp;
11061 } 11065 }