// mString.h: interface for the mString class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MSTRING_H__F225839C_CEFD_4B3E_9501_CA06A4591700__INCLUDED_)
#define AFX_MSTRING_H__F225839C_CEFD_4B3E_9501_CA06A4591700__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
////定义
//// CHAR signed char ,作为WINDOWS,ANSI,MBCS字符集使用
////UCHAR unsigned char,作为UTF-8字符集使用
////WCHAR ( wide ) unsigned char ,作为UNICODE UCS-2字符集
////ULONG unsigned long, ,作为UNICODE UCS-4字符集,Quad Char = QCHAR,Octad Char
typedef char CHAR; ////__int8, asc,oem,mbcs,dbcs
typedef unsigned char UCHAR; ////unsigned __int8, utf-8,
typedef wchar_t WCHAR; ////unsigned __int16, ucs-2,unsigned short,wide char
typedef unsigned long QCHAR; ////unsigned __int32, ucs-4,quad char
typedef unsigned __int64 OCHAR; ////unsigned __int64, ucs-8,octad char
typedef long double QFLOAT; ////float4,非标准扩展long float
#define FIND_ERROR -1
namespace UCS
{
class utf8_ucs2_t;
class utf8_ucs4_t;
#ifdef UCS_4
typedef utf8_ucs4_t utf8_t;
#else ////use for define UCS-2 or _UNICODE
typedef utf8_ucs2_t utf8_t;
#endif
class utfCount ////UTF字符数量统计表
{
long Byte[7]; ////Byte[0] = Error.其它分别代表UTF中1-6字节字符统计数
public:
utfCount( void ); ////
utfCount( const QCHAR *pString ); ////ucs-4
utfCount( const WCHAR *pString ); ////ucs-2
utfCount( const UCHAR *pString ); ////utf-8
////////////////////////////////////////////////
long Count( const QCHAR *pString ); ////统计UTF字节数量,DWORD,ucs-4
long Count( const WCHAR *pString ); ////统计UTF字节数量,WCHAR,ucs-2
long Count( const UCHAR *pString ); ////统计UTF字节数量,UCHAR,utf-8
bool Legal(const UCHAR *pString); ////错误检测
////////////////////////////////////////////////
long GetSortSize( int Index ) const; ////分类读取数量,Index = 单词字节数,0=出错数量
long GetByteSize( void ) const; ////读取字节数
long GetCharSize( void ) const; ////读取字符数
private:
void Reset( void );
};
class utf8_ucs2_t
{////UTF8字符 与 UNICODE字符之间字符转换基类
public:
bool Status;
public:
////////////////////////////////////////////////////////////
int UtfToUcs( WCHAR &Word, const UCHAR *putf ); ////UTF-8到Ucs-2转换
int UcsToUtf( UCHAR *pUtf,WCHAR Word ); ////Ucs-2到UTF-8转换
////////////////////////////////////////////////////////////
int Skip( const UCHAR * pString ) const; ////UTF移动指针
utf8_ucs2_t(void);
virtual ~utf8_ucs2_t();
private:
bool Weave( WCHAR &UniChar,UCHAR tmpByte ); ////ucs-2字符拼装
UCHAR Split( WCHAR &UniChar ); ////ucs-2字符拆分
};
class utf8_ucs4_t
{////UTF8字符 与 UNICODE字符之间字符转换基类
public:
bool Status;
public:
int UcsToUtf( UCHAR *pUtf,ULONG Ucs4 ); ////ucs-4到utf
int UtfToUcs( QCHAR &Ucs4,const UCHAR *putf ); ////utf-8到ucs-4
////////////////////////////////////////////////////////////
int Skip(const UCHAR * pUtfString ) const; ////UTF移动指针
utf8_ucs4_t(void);
virtual ~utf8_ucs4_t();
private:
int PickLead( BYTE &Head ); ////首字符吸取,返回单词总长
UCHAR MakeLead( BYTE Ucs,int nCount ); ////首字节合成
int Weave( QCHAR &Ucs4,const UCHAR *pUtf ); ////ucs-4字符拼装
void Split( UCHAR *pUtf,int Count,QCHAR Ucs4 ); ////ucs-4字符拆分
};
class utfString : protected Memory
{ ////仅用于UCS-2 与 UTF-8之间的转换(UNICODE),不再支持ASC字符,即CHAR类字符
ULONG ByteCount; ////字节数量,不是空间大小!!
public:
utfString Copy( ULONG nIndex,ULONG nCount ); ////部分复制对象
utfString Cut( ULONG nIndex,ULONG nCount ); ////部分剪切对象
long Paste( ULONG nIndex, const UCHAR *pString ); ////定位粘贴字串
long Delete( ULONG nIndex,ULONG nCount ); ////定位删除字串
////////////////////////////////////////////////////////
long Replace( const UCHAR *pOld,const UCHAR *pNew ); ////对象字串体会,返回替换数量
long Filter( const UCHAR *pString ); ////字串过滤删除,返回过滤数量
ULONG FindRight( ULONG nIndex, const UCHAR *pString ) const; ////右侧定位搜索
ULONG FindLeft( ULONG nIndex,const UCHAR *pString ) const; ////左侧定位搜索
////////////////////////////////////////////////////////
// int Trim( UCHAR *pString );
int TrimLeft( void ); ////左侧空格过滤
int TrimRight( void ); ////右侧空格过滤
////////////////////////////////////////////////////////
UCHAR & operator [](ULONG nIndex); ////不能变更数据长度
const UCHAR * operator *(void) const; ////不能变更数据长度
////////////////////////////////////////////////////////
utfString operator +(const WCHAR *pString); ////class + Unicode
utfString operator +(const UCHAR *pString); ////class + utf-8
utfString operator +(const utfString &Object); ////class + class
////////////////////////////////////////////////////////
utfString & operator +=(const WCHAR *pString);
utfString & operator +=(const UCHAR *pString);
utfString & operator +=(const utfString &Object);
////////////////////////////////////////////////////////
utfString & operator =(const WCHAR *pString);
utfString & operator =(const UCHAR *pString);
utfString & operator =(const utfString &Object);
////////////////////////////////////////////////////////
UCHAR * SetSize( ULONG tmpSize ); ////设置空间大小,单位字节
long GetSize( void ) const; ////计算空间大小,单位字节
long GetCount( void ) const; ////计算字符数量,字符总数
////////////////////////////////////////////////////////
void Empty( void ); /////清空
bool Legal( void ) const; ////UTF完整性检查
int Correct( const UCHAR *pString ) const; ////修正指针位置
long Skip( const UCHAR *pString ,long nCount ) const; ////字符移动±nCount有效字符,返回字节数量
////////////////////////////////////////////////////////
utfString( const UCHAR *pString ); ////UTF,UTF-8,unsigned char,BYTE
utfString( const WCHAR *pString ); ////UCS,UNICODE,unsigned short,WORD
utfString( const utfString &Object );
utfString( ULONG tmpSize );
utfString( void );
virtual ~utfString();
private:
UCHAR * GetAddress( void ) const; ////外部函数用 * 操作,const
utfString Extract( ULONG nIndex,ULONG nCount,bool Mode ); ////抽取,Mode = false 保留源,=true删除源
int Append(const WCHAR *pString); ////ucs,UNICODE
int Append(const UCHAR *pString); ////mbs,utf8
};
class ascString : protected Memory
{
ULONG StrSize; /////内部字节大小
public:
////////////////////////////////////////////////////////
int TrimLeft( void ); ////左侧空格过滤
int TrimRight( void ); ////右侧空格过滤
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// int Remove( WCHAR Word ); ////用Filter代替(Erase)
long Filter( CHAR Word );
long Filter( const CHAR *pString );
int Replace( const CHAR *pOld,const CHAR *pNew );
ULONG Find( ULONG nIndex, CHAR Word ) const;
ULONG FindRight( ULONG nIndex, const CHAR *pString ) const; ////nIndex 为正向序号
ULONG FindLeft( ULONG nIndex, const CHAR *pString ) const; ////nIndex 为正向序号
////////////////////////////////////////////////////////
int Delete( ULONG nIndex,ULONG nCount );
int Paste( ULONG nIndex,const CHAR *pSource );
ascString Cut( ULONG nIndex, ULONG nCount );
ascString Copy( ULONG nIndex,ULONG nCount );
////////////////////////////////////////////////
const char * operator *(void) const; ////数组操作,UNCODE i*2
char & operator [](ULONG Index); ////数组操作,Uncode i*2
////////////////////////////////////////////////
ascString operator +(const CHAR *pString); ////ASC
ascString operator +(const WCHAR *pString); ////UCS
ascString
- 1
- 2
前往页