diff 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
line wrap: on
line diff
--- a/mac/dw.m	Mon Jul 23 16:56:08 2012 +0000
+++ b/mac/dw.m	Tue Jul 24 22:52:57 2012 +0000
@@ -11030,3 +11030,32 @@
         p->drawfunc = NULL;
 }
 
+/*
+ * 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().
+ */
+wchar_t * API dw_utf8_to_wchar(char *utf8string)
+{
+    size_t buflen = strlen(utf8string) + 1;
+    wchar_t *buffer = malloc(buflen * sizeof(wchar_t));
+    mbstowcs(buffer, utf8string, buflen);
+    return buffer;
+}
+
+/*
+ * 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().
+ */
+char * API dw_wchar_to_utf8(wchar_t *wstring)
+{
+    size_t bufflen = 8 * wcslen(wstring) + 1;
+    char *temp = malloc(bufflen);
+    wcstombs(temp, wstring, bufflen);
+    return temp;
+}