📄 inststr.h
字号:
//instStr.h
#ifndef INST_STR_H
#define INST_STR_H
//本头文件是跨平台的!cpp应选用对应平台
#include <instTypes.h>
#include <instDefines.h>
namespace inst
{
typedef UInt16 KANA;
const KANA KANA_HIRA=0x0001;
const KANA KANA_KATA=0x0010;
const KANA KANA_HALFWIDTHKATA=0x0100;
const KANA KANA_ALLKATA=KANA_KATA|KANA_HALFWIDTHKATA;
typedef UInt32 CODEPAGE;
//win32获取某Locale对应的CP的方法:::GetLocaleInfo(locale, 11 ,...)
class CStr
{
private:
WChar *m_pBuf;
UInt32 m_Len; //当len==0时,m_pBuf[0]=='0',size==len+1
public:
static CODEPAGE GetSystemCodePage();
private:
static CODEPAGE CP(CODEPAGE cp){ return cp?cp:GetSystemCodePage(); }
private:
CStr(UInt32 len,Int32 unused); //不为数组每个元素初始化
public:
//ADT运算操作
CStr();
CStr(const CStr &str);
CStr(const Char *chars); //非常慢!建议不要用这个来初始化!
CStr(const Char *chars,CODEPAGE cp); //非常慢!建议不要用这个来初始化!
CStr(const WChar *wchars);
CStr(Int32 n);
CStr(UInt32 n);
CStr(Float f);
CStr(Double d);
CStr(Bool b);
~CStr();
Int32 GetLen()const{ return m_Len; }
CStr &operator =(const CStr &str);
// CStr &operator =(const Char *chars); //非常慢!建议不要用这个!
// CStr &operator =(const WChar *wchars);
Bool operator ==(const CStr &str)const;
// Bool operator ==(const Char *chars)const; //非常慢!建议不要用这个!
// Bool operator ==(const WChar *wchars)const;
Bool operator !=(const CStr &str)const;
// Bool operator !=(const Char *chars)const; //非常慢!建议不要用这个!
// Bool operator !=(const WChar *wchars)const;
CStr &operator +=(const CStr &str);
// CStr &operator +=(const Char *chars); //非常慢!建议不要用这个!
// CStr &operator +=(const WChar *wchars);
CStr operator +(const CStr &str)const;
// CStr operator +(const Char *chars)const; //非常慢!建议不要用这个!
// CStr operator +(const WChar *wchars)const;
//缓冲区操作
static CStr &CreateUninitializedStr(Int32 len){ return *(new CStr(len,0)); }
//必须要分开搞两个函数,否则会出现const错误
const WChar *ReadW()const{ return m_pBuf; } //这个很常用
WChar *ReadWriteW(){ return m_pBuf; }
//用户需要自己delete[],否则内存泄漏!
//大多情况下,ansi字符串尾的多余的\0是不要紧的
Char *ToCharArrayA(CODEPAGE cp=0)const; //很慢!建议不要用!
WChar *ToCharArrayW()const; //建议尽量不要用!为了更快,大多场合用ReadW()即可。
#ifdef TmpCharArrayA
#undef TmpCharArrayA
#endif
#define TmpCharArrayA(str) (AutoArrayPtr<Char>((str).ToCharArrayA()).GetPtr())
#ifdef TmpCharArrayAEx
#undef TmpCharArrayAEx
#endif
#define TmpCharArrayAEx(str,cp) (AutoArrayPtr<Char>((str).ToCharArrayA(cp)).GetPtr())
#ifdef TmpCharArrayW
#undef TmpCharArrayW
#endif
#define TmpCharArrayW(str) (AutoArrayPtr<WChar>((str).ToCharArrayW()).GetPtr())
//pos均从0开始!(改了~
//这里为了速度!!不可以检查边界!!
Char GetCharA(UInt32 pos);
WChar GetCharW(UInt32 pos){ return m_pBuf[pos]; }
void SetCharA(UInt32 pos,Char ch);
void SetCharW(UInt32 pos,WChar wch){ m_pBuf[pos]=wch; }
static void BltA(CStr &dest,UInt32 posdest,UInt32 lendest,const Char *src,UInt32 possrc,UInt32 lensrc);
static void BltA(Char *dest,UInt32 posdest,UInt32 lendest,const CStr &src,UInt32 possrc,UInt32 lensrc);
static void BltA(Char *dest,UInt32 posdest,UInt32 lendest,const Char *src,UInt32 possrc,UInt32 lensrc);
static void BltExA(CStr &dest,UInt32 posdest,UInt32 lendest,CODEPAGE cpdest,const Char *src,UInt32 possrc,UInt32 lensrc,CODEPAGE cpsrc);
static void BltExA(Char *dest,UInt32 posdest,UInt32 lendest,CODEPAGE cpdest,const CStr &src,UInt32 possrc,UInt32 lensrc,CODEPAGE cpsrc);
static void BltExA(Char *dest,UInt32 posdest,UInt32 lendest,CODEPAGE cpdest,const Char *src,UInt32 possrc,UInt32 lensrc,CODEPAGE cpsrc);
static void BltFastW(CStr &dest,UInt32 posdest,const CStr &src,UInt32 possrc,UInt32 len);
static void BltFastW(CStr &dest,UInt32 posdest,const WChar *src,UInt32 possrc,UInt32 len);
static void BltFastW(WChar *dest,UInt32 posdest,const CStr &src,UInt32 possrc,UInt32 len);
static void BltFastW(WChar *dest,UInt32 posdest,const WChar *src,UInt32 possrc,UInt32 len);
//高级操作
CStr ToLower()const;
CStr ToUpper()const;
CStr ToInvCase()const;
CStr ToHira(KANA flag=KANA_ALLKATA)const;
CStr ToKata(KANA flag=KANA_KATA)const;
CStr ToInvKana(KANA srcflag=KANA_ALLKATA,KANA destflag=KANA_KATA)const;
CStr Mid(UInt32 start,UInt32 len=1)const;
CStr Left(UInt32 len)const;
CStr Right(UInt32 len)const;
CStr TrimStart()const;
CStr TrimEnd()const;
CStr Trim()const;
};
}// end of namespace inst
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -