Mercurial > dwindows
diff win/dw.c @ 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 | d81bebc5c8cc |
children | 209c57a14b09 |
line wrap: on
line diff
--- a/win/dw.c Tue Jul 24 22:52:57 2012 +0000 +++ b/win/dw.c Tue Jul 24 23:33:50 2012 +0000 @@ -12474,3 +12474,38 @@ } } } + +/* + * 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) +{ + #ifdef UNICODE + return _myUTF8toWide(utf8string, malloc(MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0) * sizeof(WCHAR))); +#else + return NULL; +#endif +} + +/* + * 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) +{ +#ifdef UNICODE + return _myWideToUTF8(wstring, malloc(WideCharToMultiByte(CP_UTF8, 0, wstring, -1, NULL, 0, NULL, NULL))); +#else + return NULL; +#endif +} +