|
|
|
|
|
|
|
|
#ifndef AFX_EXT_CLASS
|
|
|
#define AFX_EXT_CLASS Q_DECL_IMPORT
|
|
|
#endif
|
|
|
#if !defined(__CCHINESECODELIB_H_)
|
|
|
#define __CCHINESECODELIB_H_
|
|
|
namespace GBase
|
|
|
{
|
|
|
class AFX_EXT_CLASS CChineseCode
|
|
|
{
|
|
|
public:
|
|
|
CChineseCode();
|
|
|
virtual ~CChineseCode();
|
|
|
|
|
|
//BOM本身也符合3字节UTF-8字符编码规律,所以本方法对带BOM的UTF-8字符串也是有效的。
|
|
|
//在程序中对最大3字节长的UTF-8字符进行了判断,在实际情况下,几乎所有能用到的UTF-8字符最长就是3个字节
|
|
|
static bool IsUTF8(const void* pBuffer, size_t size, size_t& offset);
|
|
|
|
|
|
//返回的结果需要进行delete
|
|
|
char* fromUTF8(char* str, size_t& nSize); //转换为GB2312
|
|
|
char* ToUTF8(char* str, size_t& nSize); //转换为UTF8
|
|
|
|
|
|
CString UTF_8ToGB2312(char *pText, int pLen);
|
|
|
CString GB2312ToUTF_8(char *pText, int pLen);
|
|
|
|
|
|
|
|
|
void UnicodeToUTF_8(char* pOut, WCHAR* pText); // Unicode 转换成UTF-8
|
|
|
void UTF_8ToUnicode(WCHAR* pOut, char* pText); // 把UTF-8转换成Unicode
|
|
|
|
|
|
//WCHAR与char相互转换,返回的指针需要delete
|
|
|
char* UnicodeToAnsi(const WCHAR* szStr, int wlen);
|
|
|
WCHAR* AnsiToUnicode(const char* szStr, int len);
|
|
|
|
|
|
//仅转换一个字节
|
|
|
void Gb2312ToUnicode(WCHAR* pOut, char *gbBuffer); // GB2312 转换成 Unicode
|
|
|
void UnicodeToGB2312(char* pOut, unsigned short uData); // 把Unicode 转换成 GB2312
|
|
|
CStringW UTF8toUTF16(const CStringA& utf8);
|
|
|
CStringA UTF16toUTF8(const CStringW& utf16);
|
|
|
|
|
|
};
|
|
|
}
|
|
|
#endif // !defined(__CCHINESECODELIB_H_)
|