📄 isnconversion.cpp
字号:
// ISNConversion.cpp: implementation of the CISNConversion class.
// Copyright by bright_road 2001.7
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "mtou.h"
#include "ISNConversion.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CISNConversion::CISNConversion()
{
}
CISNConversion::~CISNConversion()
{
}
int CISNConversion::UnicodeToUtf8(wchar_t wch, char uch[])
{
WORD t;
unsigned char ch;
t=wch;
if(t<=0x7E)
{
//00-7E 0xxxxxxx
uch[0]=LOBYTE(t);
return 1;
}
else if(t<0x800)
{
//80-7FF 110xxxxx 10xxxxxx
ch=LOBYTE(t&0x003F);
ch|=0x80;
uch[1]=ch;
ch=LOBYTE((t>>6)&0x1F);
ch|=0xC0;
uch[0]=ch;
return 2;
}
else
{
//800-FFFF 1110xxxx 10xxxxxx 10xxxxxx
ch=LOBYTE(t&0x3F);
ch|=0x80;
uch[2]=ch;
ch=LOBYTE((t>>6)&0x3F);
ch|=0x80;
uch[1]=ch;
ch=LOBYTE((t>>12)&0x0F);
ch|=0xE0;
uch[0]=ch;
return 3;
}
}
void CISNConversion::AnsiToUtf8(LPCTSTR filename, UINT CodePage)
{
UINT wLen,i;//widebyte char number/length
DWORD nLen;
CFile fp;
int nUTF8;
if( !fp.Open(filename,CFile::modeReadWrite) )
{
CString msg;
msg.Format("Open the file : \'%s\' error!",filename);
AfxMessageBox(msg);
return;
}
nLen=fp.GetLength();
char* rbuf=new char[nLen];
wchar_t* wbuf=new wchar_t[nLen];
if(rbuf==NULL || wbuf==NULL)
{ AfxMessageBox("alloc memory error!");
return;
}
// Convert ANSI or MultiByte to UNICODE
try
{
fp.Read(rbuf,nLen);
wLen=MultiByteToWideChar(CodePage,0,rbuf,nLen,wbuf,nLen);
}
catch(CFileException* pEx)
{
pEx->ReportError();
delete rbuf;
delete wbuf;
fp.Close();
return;
}
delete rbuf;
// Convert UNICODE to UTF-8
fp.SeekToBegin();
char uch[3];
i=0;
while(i<wLen)
{
nUTF8=UnicodeToUtf8(wbuf[i],uch);
fp.Write(uch,nUTF8);
i++;
}
fp.Close();
delete wbuf;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -