GlobalUnit add gbk<->utf8
This commit is contained in:
@@ -112,6 +112,54 @@ unsigned __fastcall GetCompileTime()
|
|||||||
return DateTimeToUnix(dt, false);
|
return DateTimeToUnix(dt, false);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
String GBKToUTF8(const char* str)
|
||||||
|
{
|
||||||
|
String result;
|
||||||
|
WCHAR *strSrc;
|
||||||
|
char *szRes;
|
||||||
|
|
||||||
|
//GBK to unicode
|
||||||
|
int i = MultiByteToWideChar(936, 0, str, -1, NULL, 0);
|
||||||
|
strSrc = new WCHAR[i+1];
|
||||||
|
MultiByteToWideChar(936, 0, str, -1, strSrc, i);
|
||||||
|
|
||||||
|
//unicode to UTF8
|
||||||
|
i = WideCharToMultiByte(CP_UTF8, 0, strSrc, -1, NULL, 0, NULL, NULL);
|
||||||
|
szRes = new char[i+1];
|
||||||
|
i = WideCharToMultiByte(CP_UTF8, 0, strSrc,-1, szRes, i, NULL, NULL);
|
||||||
|
|
||||||
|
result = szRes;
|
||||||
|
delete []strSrc;
|
||||||
|
delete []szRes;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
int UTF8ToGBK( const char *pcUtf8, AnsiString& strGBK )
|
||||||
|
{
|
||||||
|
int nUnicodeLen = MultiByteToWideChar(CP_UTF8, 0, pcUtf8, -1, NULL, 0);
|
||||||
|
|
||||||
|
wchar_t * pcUnicode = new wchar_t[nUnicodeLen+1];
|
||||||
|
memset(pcUnicode, 0, nUnicodeLen * 2 + 2);
|
||||||
|
|
||||||
|
//utf8 to unicode
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, pcUtf8, -1, pcUnicode, nUnicodeLen);
|
||||||
|
|
||||||
|
//unicode to GBK
|
||||||
|
int nGBKLen = WideCharToMultiByte(CP_ACP, 0, pcUnicode, -1, NULL, 0, NULL, NULL);
|
||||||
|
|
||||||
|
char *pcGBK=new char[nGBKLen + 1];
|
||||||
|
memset(pcGBK, 0, nGBKLen + 1);
|
||||||
|
|
||||||
|
WideCharToMultiByte(CP_ACP, 0, pcUnicode, -1, pcGBK, nGBKLen, NULL, NULL);
|
||||||
|
|
||||||
|
strGBK=pcGBK;
|
||||||
|
delete[] pcGBK;
|
||||||
|
delete[] pcUnicode;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
//TLog
|
//TLog
|
||||||
|
|||||||
@@ -400,6 +400,8 @@ extern char g_sWebID[]; //用户编号
|
|||||||
// 全局函数
|
// 全局函数
|
||||||
void DebugPrint(const char * fmt, ...);
|
void DebugPrint(const char * fmt, ...);
|
||||||
unsigned __fastcall GetCompileTime();
|
unsigned __fastcall GetCompileTime();
|
||||||
|
String GBKToUTF8(const char* str);
|
||||||
|
int UTF8ToGBK( const char *pcUtf8, AnsiString& strGBK );
|
||||||
|
|
||||||
class TLog
|
class TLog
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user