| author | J. Ali Harlow <ali@juiblex.co.uk> |
| Thu Jul 09 08:52:03 2009 +0100 (2009-07-09) | |
| changeset 0 | 8525965e930d |
| child 13 | 3073875f1b54 |
| permissions | -rw-r--r-- |
1 #include <stdlib.h>
2 #include <windows.h>
3 #include <winnls.h>
4 #include "_whelk.h"
6 char *whelk_utf16_to_utf8(const WCHAR *utf16,int len)
7 {
8 int n;
9 char *utf8;
10 n=WideCharToMultiByte(CP_UTF8,0,utf16,len,NULL,0,NULL,NULL);
11 if (n)
12 {
13 utf8=malloc(n);
14 if (utf8)
15 WideCharToMultiByte(CP_UTF8,0,utf16,len,utf8,n,NULL,NULL);
16 }
17 else
18 utf8=NULL;
19 return utf8;
20 }
22 WCHAR *whelk_utf8_to_utf16(const char *utf8,int len)
23 {
24 int n;
25 WCHAR *utf16;
26 n=MultiByteToWideChar(CP_UTF8,0,utf8,len,NULL,0);
27 if (n)
28 {
29 utf16=malloc(n*sizeof(WCHAR));
30 if (utf16)
31 MultiByteToWideChar(CP_UTF8,0,utf8,len,utf16,n);
32 }
33 else
34 utf16=NULL;
35 return utf16;
36 }