//////////////////////////////////////////////////////////////////////////
void UTF_8ToUnicode(wchar_t* pOut,char *pText)
{
char* uchar = (char *)pOut;
uchar[1] = ((pText[0] & 0x0F) << 4) + ((pText[1] >> 2) & 0x0F);
uchar[0] = ((pText[1] & 0x03) << 6) + (pText[2] & 0x3F);
}
//////////////////////////////////////////////////////////////////////////
void UnicodeToGB2312(char* pOut,wchar_t uData)
{
WideCharToMultiByte(CP_ACP, NULL, &uData, 1, pOut, sizeof(wchar_t), NULL, NULL);
}
//////////////////////////////////////////////////////////////////////////
std::string UTF_8ToGB2312(char *pText, int nLen)
{
char * newBuf = new char[nLen+1];
char Ctemp[4];
memset(Ctemp,0,4);
int i = 0;
int j = 0;
while(i < nLen)
{
if(pText[i] > 0)
{
newBuf[j++] = pText[i++];
}
else
{
WCHAR Wtemp;
UTF_8ToUnicode(&Wtemp, pText+i);
UnicodeToGB2312(Ctemp, Wtemp);
newBuf[j] = Ctemp[0];
newBuf[j + 1] = Ctemp[1];
i += 3;
j += 2;
}
}
if (j <= nLen)
newBuf[j] = 0;
std::string strOut = newBuf;
delete []newBuf;
return strOut;
}
联系客服