Mercurial > dwindows
comparison mac/dw.m @ 1783:9de6d1cc8fb8
Put test program code into DEPRECATED #ifdef again to avoid build warnings.
Added UTF-8/Wide string conversion functions which will be used in an editor.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 24 Jul 2012 22:52:57 +0000 |
parents | d056a50196a9 |
children | 86ace55df07b |
comparison
equal
deleted
inserted
replaced
1782:d056a50196a9 | 1783:9de6d1cc8fb8 |
---|---|
11028 | 11028 |
11029 if(p) | 11029 if(p) |
11030 p->drawfunc = NULL; | 11030 p->drawfunc = NULL; |
11031 } | 11031 } |
11032 | 11032 |
11033 /* | |
11034 * Converts a UTF-8 encoded string into a wide string. | |
11035 * Parameters: | |
11036 * utf8string: UTF-8 encoded source string. | |
11037 * Returns: | |
11038 * Wide string that needs to be freed with dw_free(). | |
11039 */ | |
11040 wchar_t * API dw_utf8_to_wchar(char *utf8string) | |
11041 { | |
11042 size_t buflen = strlen(utf8string) + 1; | |
11043 wchar_t *buffer = malloc(buflen * sizeof(wchar_t)); | |
11044 mbstowcs(buffer, utf8string, buflen); | |
11045 return buffer; | |
11046 } | |
11047 | |
11048 /* | |
11049 * Converts a wide string into a UTF-8 encoded string. | |
11050 * Parameters: | |
11051 * wstring: Wide source string. | |
11052 * Returns: | |
11053 * UTF-8 encoded string that needs to be freed with dw_free(). | |
11054 */ | |
11055 char * API dw_wchar_to_utf8(wchar_t *wstring) | |
11056 { | |
11057 size_t bufflen = 8 * wcslen(wstring) + 1; | |
11058 char *temp = malloc(bufflen); | |
11059 wcstombs(temp, wstring, bufflen); | |
11060 return temp; | |
11061 } |