-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeConvert.h
More file actions
43 lines (39 loc) · 909 Bytes
/
Copy pathCodeConvert.h
File metadata and controls
43 lines (39 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef __ICONV_STRING_H__
#define __ICONV_STRING_H__
#pragma comment(lib,"../Classes/lib/libiconv.lib")
#ifdef WIN32
#define UTEXT(str) GBKToUTF8(str)
#else
#define UTEXT(str) str
#endif
#ifdef WIN32
#include "CCStdC.h"
#include "iconv/iconv.h"
static char g_GBKConvUTF8Buf[5000] = { 0 };
const char* GBKToUTF8(const char *strChar)
{
iconv_t iconvH;
iconvH = iconv_open("utf-8", "gb2312");
if (iconvH == 0)
{
return NULL;
}
size_t strLength = strlen(strChar);
size_t outLength = strLength << 2;
size_t copyLength = outLength;
memset(g_GBKConvUTF8Buf, 0, 5000);
char* outbuf = (char*)malloc(outLength);
char* pBuff = outbuf;
memset(outbuf, 0, outLength);
if (-1 == iconv(iconvH, &strChar, &strLength, &outbuf, &outLength))
{
iconv_close(iconvH);
return NULL;
}
memcpy(g_GBKConvUTF8Buf, pBuff, copyLength);
free(pBuff);
iconv_close(iconvH);
return g_GBKConvUTF8Buf;
}
#endif
#endif