You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB
C++

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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_)