?? codingconv.cpp.svn-base
字號:
// CodingConv.cpp: implementation of the CCodingConv class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CodingConv.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
__inline void Gb2312_2_Unicode(USHORT* pusDst, const char* pszSrc)
{
::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pszSrc, 2, pusDst, 1);
}
__inline void Unicode_2_UTF8(char* pszDst, USHORT* pusSrc)
{
char* pChar = (char *)pusSrc;
pszDst[0] = (0xE0 | ((pChar[1] & 0xF0) >> 4));
pszDst[1] = (0x80 | ((pChar[1] & 0x0F) << 2)) + ((pChar[0] & 0xC0) >> 6);
pszDst[2] = (0x80 | ( pChar[0] & 0x3F));
}
__inline void UTF8_2_Unicode(USHORT* pusDst, const char* pszSrc)
{
char* pChar = (char *)pusDst;
pChar[1] = ((pszSrc[0] & 0x0F) << 4) + ((pszSrc[1] >> 2) & 0x0F);
pChar[0] = ((pszSrc[1] & 0x03) << 6) + (pszSrc[2] & 0x3F);
}
__inline void Unicode_2_GB2312(char* pDst, const USHORT usData)
{
WideCharToMultiByte(CP_ACP, NULL, &usData, 1, pDst, sizeof(unsigned short), NULL, NULL);
}
int CCodingConv::GB2312_2_UTF8(char* pszDstBuf, int nDstLen, const char* pszSrc, int nSrcLen)
{
if (pszDstBuf == NULL || pszSrc == NULL)
{
return 0;
}
if (0 == nSrcLen)
{
nSrcLen = strlen(pszSrc);
}
int j = 0;
for (int i=0; i<nSrcLen;)
{
if (j >= nDstLen - 1)
break;
if (pszSrc[i] >= 0)
{
pszDstBuf[j++] = pszSrc[i++];
}
else
{
USHORT usData = 0;
Gb2312_2_Unicode(&usData, pszSrc + i);
char sztmp[4] = "";
Unicode_2_UTF8(sztmp, &usData);
pszDstBuf[j+0] = sztmp[0];
pszDstBuf[j+1] = sztmp[1];
pszDstBuf[j+2] = sztmp[2];
i += 2;
j += 3;
}
}
pszDstBuf[j] = '\0';
return j;
}
int CCodingConv::UTF8_2_GB2312(char* pszDstBuf, int nDstLen, const char* pszSrc, int nSrcLen)
{
if (pszDstBuf == NULL || pszSrc == NULL)
{
return 0;
}
if (0 == nSrcLen)
{
nSrcLen = strlen(pszSrc);
}
int j = 0;
for (int i=0; i<nSrcLen;)
{
if (j >= nDstLen - 1)
break;
if (pszSrc[i] >= 0)
{
pszDstBuf[j++] = pszSrc[i++];
}
else
{
USHORT usData = 0;
UTF8_2_Unicode(&usData, pszSrc + i);
char szTmp[4] = "";
Unicode_2_GB2312(szTmp, usData);
pszDstBuf[j+0] = szTmp[0];
pszDstBuf[j+1] = szTmp[1];
i += 3;
j += 2;
}
}
pszDstBuf[j] = '\0';
return j;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -