e8cca0f23487163f45d2c578a99a3fc724832efe
[mono.git] / mono / io-layer / unicode.c
1 /*
2  * unicode.c:  unicode conversion
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9
10 #include <config.h>
11 #include <glib.h>
12 #include <pthread.h>
13 #if HAVE_ICONV_H
14 #include <iconv.h>
15 #elif HAVE_GICONV_H
16 #include <giconv.h>
17 #endif
18 #include <errno.h>
19
20 #include "mono/io-layer/wapi.h"
21 #include "unicode.h"
22
23 /* This is a nasty kludge */
24 static guint32 
25 unicode_len (const gunichar2 *str)
26 {
27         guint32 len = 0;
28         
29         do {
30                 if (str [len] == '\0')
31                         return len * 2;
32
33                 len++;
34         } while (1);
35 }
36
37 gchar *_wapi_unicode_to_utf8(const gunichar2 *uni)
38 {
39         GError *error = NULL;
40         gchar *res;
41         int len;
42
43         len = unicode_len(uni);
44         
45         res = g_utf16_to_utf8 (uni, len, NULL, NULL, &error);
46
47         g_assert (!error);
48
49         return res;
50 }