dwstring.h.svn-base
来自「ffshow源码」· SVN-BASE 代码 · 共 905 行 · 第 1/3 页
SVN-BASE
905 行
//. See also: ReleaseBuffer(). void ReleaseBuffer(tchar** aBuf, size_t* aSize, size_t* aStart, size_t* aLen); //. This {\it advanced} member function is the symmetric opposite of //. {\tt TakeBuffer()}, to the extent that such an opposite is possible. //. It provides a way to ``export'' the buffer used internally by the //. {\tt DwString} object. //. Note, however, that because of the copy-on-modify feature of //. {\tt DwString}, the {\tt DwString} object may not have sole //. ownership of its internal buffer. When that is case, //. {\tt ReleaseBuffer()} will return a copy of the buffer. You can check //. to see if the internal buffer is shared by calling {\tt RefCount()}. //. On return from this member function, the {\tt DwString} object will //. have valid, but empty, contents. //. It is recommended that you use this function only on rare occasions //. where you need to export efficiently a large buffer. void CopyTo(DwString* aStr) const; //. This {\it advanced} member function copies this {\tt DwString} //. object to {\tt aStr}. This member //. function is different from the assignment operator, because it //. physically copies the buffer instead of just duplicating a reference //. to it.protected: DwStringRep<tchar>* mRep; size_t mStart; size_t mLength; void _copy(); void _replace(size_t aPos1, size_t aLen1, const tchar* aBuf, size_t aLen2); void _replace(size_t aPos1, size_t aLen1, size_t aLen2, tchar aChar);private: static const size_t kEmptyBufferSize; static tchar sEmptyBuffer[]; static DwStringRep<tchar>* sEmptyRep;public: static inline void mem_free(tchar* buf) { assert(buf != 0); if (buf && buf != sEmptyBuffer) delete [] buf; } //virtual void PrintDebugInfo(std::ostream& aStrm) const; //. Prints debugging information about the object to {\tt aStrm}. //. //. This member function is available only in the debug version of //. the library. static void CALLBACK GlobalInitialization( BOOL bLoading, const CLSID *rclsid);};template<class tchar> DwString<tchar> operator + (const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> DwString<tchar> operator + (const tchar* aCstr, const DwString<tchar>& aStr2);template<class tchar> DwString<tchar> operator + (tchar aChar, const DwString<tchar>& aStr2);template<class tchar> DwString<tchar> operator + (const DwString<tchar>& aStr1, const tchar* aCstr);template<class tchar> DwString<tchar> operator + (const DwString<tchar>& aStr1, tchar aChar);template<class tchar> bool operator == (const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> bool operator == (const DwString<tchar>& aStr1, const tchar* aCstr);template<class tchar> bool operator == (const tchar* aCstr, const DwString<tchar>& aStr2);template<class tchar> bool operator != (const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> bool operator != (const DwString<tchar>& aStr1, const tchar* aCstr);template<class tchar> bool operator != (const tchar* aCstr, const DwString<tchar>& aStr2);template<class tchar> bool operator < (const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> bool operator < (const DwString<tchar>& aStr1, const tchar* aCstr);template<class tchar> bool operator < (const tchar* aCstr, const DwString<tchar>& aStr2);template<class tchar> bool operator > (const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> bool operator > (const DwString<tchar>& aStr1, const tchar* aCstr);template<class tchar> bool operator > (const tchar* aCstr, const DwString<tchar>& aStr2);template<class tchar> bool operator <= (const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> bool operator <= (const DwString<tchar>& aStr1, const tchar* aCstr);template<class tchar> bool operator <= (const tchar* aCstr, const DwString<tchar>& aStr2);template<class tchar> bool operator >= (const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> bool operator >= (const DwString<tchar>& aStr1, const tchar* aCstr);template<class tchar> bool operator >= (const tchar* aCstr, const DwString<tchar>& aStr2);template<class tchar> int DwStrcasecmp(const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> int DwStrcasecmp(const DwString<tchar>& aStr1, const tchar* aCstr);template<class tchar> int DwStrcasecmp(const tchar* aCstr, const DwString<tchar>& aStr2);template<class tchar> int DwStrncasecmp(const DwString<tchar>& aStr1, const DwString<tchar>& aStr2, size_t aLen);template<class tchar> int DwStrncasecmp(const DwString<tchar>& aStr, const tchar* aCstr, size_t aLen);template<class tchar> int DwStrncasecmp(const tchar* aCstr, const DwString<tchar>& aStr, size_t aLen);template<class tchar> int DwStrcmp(const DwString<tchar>& aStr1, const DwString<tchar>& aStr2);template<class tchar> int DwStrcmp(const DwString<tchar>& aStr, const tchar* aCstr);template<class tchar> int DwStrcmp(const tchar* aCstr, const DwString<tchar>& aStr);template<class tchar> int DwStrncmp(const DwString<tchar>& aStr1, const DwString<tchar>& aStr2, size_t aLen);template<class tchar> int DwStrncmp(const DwString<tchar>& aStr, const tchar* aCstr, size_t aLen);template<class tchar> int DwStrncmp(const tchar* aCstr, const DwString<tchar>& aStr, size_t aLen);template<class tchar> void DwStrcpy(DwString<tchar>& aStrDest, const DwString<tchar>& aStrSrc);template<class tchar> void DwStrcpy(DwString<tchar>& aStrDest, const tchar* aCstrSrc);template<class tchar> void DwStrcpy(tchar* aCstrDest, const DwString<tchar>& aStrSrc);template<class tchar> void DwStrncpy(DwString<tchar>& aStrDest, const DwString<tchar>& aStrSrc, size_t aLen);template<class tchar> void DwStrncpy(DwString<tchar>& aStrDest, const tchar* aCstrSrc, size_t aLen);template<class tchar> void DwStrncpy(tchar* aCstrDest, const DwString<tchar>& aStrSrc, size_t aLen);template<class tchar> tchar* DwStrdup(const DwString<tchar>& aStr);typedef DwString<wchar_t> ffwstring;typedef std::vector<ffwstring> wstrings;#ifdef UNICODE typedef DwString<wchar_t> ffstring; typedef std::vector<ffstring> strings;#else typedef DwString<char> ffstring; typedef std::vector<ffstring> strings;#endif template<class T> struct tchar_traits {};template<> struct tchar_traits<char>{ typedef DwString<char> ffstring; typedef std::vector<ffstring> strings; typedef unsigned char uchar_t; typedef wchar_t other_char_t; typedef unsigned char toupper_t; static __forceinline int isspace(int c) {return ::isspace(c);} static __forceinline int isupper(int c) {return ::isupper(c);} static __forceinline int toupper(int c) {return ::toupper(c);} typedef int (*Tsscanf)(const char *,const char*, ...); static Tsscanf sscanf() {return ::sscanf;} typedef int (*Tsprintf)(char *,const char*, ...); static Tsprintf sprintf() {return ::sprintf;} typedef int (*Tsnprintf)(char *,size_t,const char*, ...); static Tsnprintf snprintf() {return ::_snprintf;} typedef int (*Tfprintf)(FILE *, const char *, ...); static Tfprintf fprintf() {return ::fprintf;}};template<> struct tchar_traits<wchar_t>{ typedef DwString<wchar_t> ffstring; typedef std::vector<ffstring> strings; typedef unsigned short uchar_t; typedef char other_char_t; typedef wint_t toupper_t; static __forceinline int isspace(wint_t c) {return ::iswspace(c);} static __forceinline int isupper(wint_t c) {return ::iswupper(c);} static __forceinline int toupper(wint_t c) {return ::towupper(c);} typedef int (*Tsscanf)(const wchar_t *,const wchar_t*, ...); static Tsscanf sscanf() {return ::swscanf;} typedef int (*Tsprintf)(wchar_t *,const wchar_t*, ...); static Tsprintf sprintf() {return ::swprintf;} typedef int (*Tsnprintf)(wchar_t *,size_t,const wchar_t*, ...); static Tsnprintf snprintf() {return ::_snwprintf;} typedef int (*Tfprintf)(FILE *, const wchar_t *, ...); static Tfprintf fprintf() {return ::fwprintf;}};struct ffstring_iless{ bool operator ()(const ffstring &s1,const ffstring &s2) const { return stricmp(s1.c_str(),s2.c_str())<0; }};namespace std{ template<> struct hash<DwString<char> > { size_t operator()(const DwString<char> &__s) const; }; template<> struct hash<DwString<wchar_t> > { size_t operator()(const DwString<wchar_t> &__s) const; };}#if defined(__INTEL_COMPILER) || defined(__GNUC__) || (_MSC_VER>=1300)template<class T> static inline const T* T_L(const char *t1,const wchar_t *t2);template<> inline const char* T_L(const char *t1,const wchar_t *t2) {return t1;}template<> inline const wchar_t* T_L(const char *t1,const wchar_t *t2) {return t2;}template<class T> static inline const T T_L(const char t1,const wchar_t t2);template<> inline const char T_L(const char t1,const wchar_t t2) {return t1;}template<> inline const wchar_t T_L(const char t1,const wchar_t t2) {return t2;}#undef _L#define _L(x) T_L<tchar>(x,L##x)//===================================== passtring =====================================template<class tchar> class passtring :protected DwString<tchar>{private: static tchar chr;public: static const size_t npos=0; passtring(void) {} passtring(const DwString<tchar> &Istr):DwString<tchar>(Istr) {} passtring(const tchar *Istr):DwString<tchar>(Istr) {} const tchar& operator [] (int aPos) const { return (1<=aPos && aPos<=size())?this->at(aPos-1):chr; } tchar& operator [] (int aPos) { return (1<=aPos && aPos<=size())?this->at(aPos-1):chr; } void erase(size_t aPos=0, size_t aLen=npos) { DwString<tchar>::erase(aPos-1,aLen); } int find(const DwString<tchar>& aStr, size_t aPos=1) const { return (int)DwString<tchar>::find(aStr,aPos-1)+1; } int find(tchar aStr, size_t aPos=1) const { return (int)DwString<tchar>::find(aStr,aPos-1)+1; } void replace(size_t aPos1, size_t aLen1, const DwString<tchar>& aStr) { DwString<tchar>::replace(aPos1-1,aLen1,aStr); } int size() const { return (int)DwString<tchar>::size(); } void insert(size_t aPos1, const tchar* aCstr) { DwString<tchar>::insert(aPos1-1,aCstr); } passtring copy(int pos,int len) const { if (pos>size() || len<0) return passtring(); else return this->substr(pos-1,len); } void append(const passtring& aStr) { DwString<tchar>::append(aStr); } bool empty() const { return DwString<tchar>::empty(); } const tchar* c_str() const { return DwString<tchar>::c_str(); } void clear() { DwString<tchar>::clear(); } void ConvertToLowerCase() { DwString<tchar>::ConvertToLowerCase(); }};template<class tchar> inline passtring<tchar> operator + (const passtring<tchar> &aStr1, const passtring<tchar> &aStr2){ passtring<tchar> s1(aStr1); s1.append(aStr2); return s1;}template<class tchar> inline passtring<tchar> operator + (const passtring<tchar> &aStr1, const tchar *aStr2){ passtring<tchar> s1(aStr1); s1.append(aStr2); return s1;}template<class tchar> inline passtring<tchar> operator + (const tchar *aStr1, const passtring<tchar> &aStr2){ passtring<tchar> s1(aStr1); s1.append(aStr2); return s1;}template<> inline DwString<char>& DwString<char>::operator=(const char *aCstr) {return assign(aCstr);}template<> inline DwString<char>& DwString<char>::operator=(const wchar_t *aCstr) {return assign((const char*)text<char>(aCstr));}template<> inline DwString<wchar_t>& DwString<wchar_t>::operator=(const wchar_t *aCstr) {return assign(aCstr);}template<> inline DwString<wchar_t>& DwString<wchar_t>::operator=(const char *aCstr) {return assign((const wchar_t*)text<wchar_t>(aCstr));}#endif#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?