原文档内容为:Using configuration file realmd.conf.
MaNGOS realm daemon /@VERSION@ (Win32)
<Ctrl-C> to stop.Added realm "娴嬭瘯骞绘兂".
Added realm "骞绘兂榄斿吔".
f.
转换成:Using configuration file realmd.conf.
MaNGOS realm daemon /@VERSION@ (Win32)
<Ctrl-C> to stop.
Added realm "测试幻想".
Added realm "幻想魔兽".
Using configuration file realmd.conf.
MaNGOS realm daemon /@VERSION@ (Win32)
<Ctrl-C> to stop.Added realm "娴嬭瘯骞绘兂".
Added realm "骞绘兂榄斿吔".
f.
MaNGOS realm daemon /@VERSION@ (Win32)
<Ctrl-C> to stop.Added realm "娴嬭瘯骞绘兂".
Added realm "骞绘兂榄斿吔".
f.
转换成:Using configuration file realmd.conf.
MaNGOS realm daemon /@VERSION@ (Win32)
<Ctrl-C> to stop.
Added realm "测试幻想".
Added realm "幻想魔兽".
Using configuration file realmd.conf.
MaNGOS realm daemon /@VERSION@ (Win32)
<Ctrl-C> to stop.Added realm "娴嬭瘯骞绘兂".
Added realm "骞绘兂榄斿吔".
f.
// pSrc: 源字符串指针
// pDst: 目标编码串指针
// nSrcLength: 源字符串长度
// 返回: 目标编码串长度
int EncodeUcs2(const char* pSrc, unsigned char* pDst, int nSrcLength)
{
int nDstLength; // UNICODE宽字符数目
WCHAR wchar[128]; // UNICODE串缓冲区
// 字符串-->UNICODE串
memset(wchar,0,128);// I added
nDstLength = ::MultiByteToWideChar(CP_ACP, 0, pSrc, nSrcLength, wchar, 128);
// 高低字节对调,输出
for(int i=0; i<nDstLength; i++)
{
// 先输出高位字节
*pDst++ = wchar[i] >> 8;
// 后输出低位字节
*pDst++ = wchar[i] & 0xff;
}
// 返回目标编码串长度
return nDstLength * 2;
}
// UCS2解码
// pSrc: 源编码串指针
// pDst: 目标字符串指针
// nSrcLength: 源编码串长度
// 返回: 目标字符串长度int DecodeUcs2(const unsigned char* pSrc, char* pDst, int nSrcLength)
{
int nDstLength; // UNICODE宽字符数目
WCHAR wchar[128]; // UNICODE串缓冲区
// 高低字节对调,拼成UNICODE
for(int i=0; i<nSrcLength/2; i++)
{
// 先高位字节
wchar[i] = *pSrc++ << 8;
// 后低位字节
wchar[i] |= *pSrc++;
}
// UNICODE串-->字符串
nDstLength = ::WideCharToMultiByte(CP_ACP, 0, wchar, nSrcLength/2, pDst, 160, NULL, NULL);
// 输出字符串加个结束符
pDst[nDstLength] = '\0';
// 返回目标字符串长度
return nDstLength;
}/ 字节数据转换为可打印字符串
// 如:{0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01} --> "C8329BFD0E01"
// pSrc: 源数据指针
// pDst: 目标字符串指针
// nSrcLength: 源数据长度
// 返回: 目标字符串长度
int Bytes2String(const unsigned char* pSrc, char* pDst, int nSrcLength)
{
const char tab[]="0123456789ABCDEF"; // 0x0-0xf的字符查找表
for(int i=0; i<nSrcLength; i++)
{
// 输出低4位
*pDst++ = tab[*pSrc >> 4];
// 输出高4位
*pDst++ = tab[*pSrc & 0x0f];
pSrc++;
}
// 输出字符串加个结束符
*pDst = '\0';
// 返回目标字符串长度
return nSrcLength * 2;
}