Index: src/libchcore/TString.h =================================================================== diff -u -N -r2755e12daeccb1935f569e7235e685e566b0b098 -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 --- src/libchcore/TString.h (.../TString.h) (revision 2755e12daeccb1935f569e7235e685e566b0b098) +++ src/libchcore/TString.h (.../TString.h) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) @@ -27,147 +27,146 @@ #include #include -BEGIN_CHCORE_NAMESPACE +namespace chcore +{ + class TStringArray; -class TStringArray; + /////////////////////////////////////////////////////////////// + // TString manipulation class + /** \brief String manipulation class + * + * Class allows user to manipulate TString objects (either standard ANSI char_t* + * based strings or UNICODE ones - wchar_t related) with simple functions and + * operators. + */ + class LIBCHCORE_API TString + { + public: + /** \name Construction/destruction */ + /*@{*/ + TString(); ///< Standard constructor + TString(const wchar_t* pszStr); ///< Constructor that takes const wchar_t* as an initial TString + TString(const wchar_t* pszStart, const wchar_t* pszEnd, size_t stMaxStringSize = DefaultMaxStringSize); + TString(const wchar_t* pszStart, size_t stCount); + TString(const TString& str); ///< Standard copy constructor -/////////////////////////////////////////////////////////////// -// TString manipulation class -/** \brief String manipulation class - * - * Class allows user to manipulate TString objects (either standard ANSI char_t* - * based strings or UNICODE ones - wchar_t related) with simple functions and - * operators. - */ -class LIBCHCORE_API TString -{ -public: -/** \name Construction/destruction */ -/*@{*/ - TString(); ///< Standard constructor - TString(const wchar_t* pszStr); ///< Constructor that takes const wchar_t* as an initial TString - TString(const wchar_t* pszStart, const wchar_t* pszEnd, size_t stMaxStringSize = DefaultMaxStringSize); - TString(const wchar_t* pszStart, size_t stCount); - TString(const TString& str); ///< Standard copy constructor - - ~TString(); ///< Standard destructor -/*@}*/ + ~TString(); ///< Standard destructor + /*@}*/ -/** \name Operators */ -/**@{*/ - // assignment - TString& operator=(const TString& src); ///< Assign operator for TString objects - TString operator+(const TString& src) const; ///< Concatenate operator for TString objects - const TString& operator+=(const TString& src); ///< Merge operator for TString objects - - const TString& operator=(const wchar_t* pszSrc); ///< Assign operator from unicode strings - TString operator+(const wchar_t* pszSrc) const; ///< Concatenate operator for unicode strings - const TString& operator+=(const wchar_t* pszSrc); ///< Merge operator for unicode strings - - /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) - bool operator<(const wchar_t* psz) const { return Compare(psz) < 0; }; - /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) - bool operator<=(const wchar_t* psz) const { return Compare(psz) <= 0; }; - /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) - bool operator==(const wchar_t* psz) const { return Compare(psz) == 0; }; - /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) - bool operator>=(const wchar_t* psz) const { return Compare(psz) >= 0; }; - /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) - bool operator>(const wchar_t* psz) const { return Compare(psz) > 0; }; - /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) - bool operator!=(const wchar_t* psz) const { return Compare(psz) != 0; }; - - /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) - bool operator<(const TString& str) const { return Compare(str) < 0; }; - /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) - bool operator<=(const TString& str) const { return Compare(str) <= 0; }; - /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) - bool operator==(const TString& str) const { return Compare(str) == 0; }; - /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) - bool operator>=(const TString& str) const { return Compare(str) >= 0; }; - /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) - bool operator>(const TString& str) const { return Compare(str) >= 0; }; - /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) - bool operator!=(const TString& str) const { return Compare(str) != 0; }; -/**@}*/ + /** \name Operators */ + /**@{*/ + // assignment + TString& operator=(const TString& src); ///< Assign operator for TString objects + TString operator+(const TString& src) const; ///< Concatenate operator for TString objects + const TString& operator+=(const TString& src); ///< Merge operator for TString objects -/** \name Standard operations */ -/**@{*/ - // appends the given TString to this - void Append(const wchar_t* pszSrc); ///< Appends an unicode TString to the TString object - void Append(const TString& src); ///< Appends a TString object to another TString object - - TString Left(size_t tLen) const; ///< Returns TString with the Left part of a source TString - TString Right(size_t tLen) const; ///< Returns TString with the Right part of a source TString - TString Mid(size_t tStart, size_t tLen = (size_t)-1) const; ///< Returns TString with the middle part of a source TString - TString MidRange(size_t tStart, size_t stAfterEndPos) const; ///< Returns TString with the middle part of a source TString - - void LeftSelf(size_t tLen); ///< Makes this TString it's Left part - void RightSelf(size_t tLen); ///< Makes this TString it's Right part - void MidSelf(size_t tStart, size_t tLen = (size_t)-1); ///< Makes this TString it's middle part - - void TrimRightSelf(const wchar_t* pszElements); + const TString& operator=(const wchar_t* pszSrc); ///< Assign operator from unicode strings + TString operator+(const wchar_t* pszSrc) const; ///< Concatenate operator for unicode strings + const TString& operator+=(const wchar_t* pszSrc); ///< Merge operator for unicode strings - bool Delete(size_t stIndex, size_t stCount); + /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) + bool operator<(const wchar_t* psz) const { return Compare(psz) < 0; }; + /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) + bool operator<=(const wchar_t* psz) const { return Compare(psz) <= 0; }; + /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) + bool operator==(const wchar_t* psz) const { return Compare(psz) == 0; }; + /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) + bool operator>=(const wchar_t* psz) const { return Compare(psz) >= 0; }; + /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) + bool operator>(const wchar_t* psz) const { return Compare(psz) > 0; }; + /// Makes case sensitive comparison to the unicode TString ( see Compare(const wchar_t* psz) ) + bool operator!=(const wchar_t* psz) const { return Compare(psz) != 0; }; - void Split(const wchar_t* pszSeparators, TStringArray& rStrings) const; + /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) + bool operator<(const TString& str) const { return Compare(str) < 0; }; + /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) + bool operator<=(const TString& str) const { return Compare(str) <= 0; }; + /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) + bool operator==(const TString& str) const { return Compare(str) == 0; }; + /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) + bool operator>=(const TString& str) const { return Compare(str) >= 0; }; + /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) + bool operator>(const TString& str) const { return Compare(str) >= 0; }; + /// Makes case sensitive comparison to the TString object ( see Compare(const TString& str) ) + bool operator!=(const TString& str) const { return Compare(str) != 0; }; + /**@}*/ - // compare operations - int_t Compare(const wchar_t* psz) const; ///< Comparison of this TString object with a given unicode TString - int_t Compare(const TString& str) const; ///< Comparison of this TString object with another TString object - - int_t CompareNoCase(const wchar_t* psz) const; ///< Comparison (case insensitive) of this TString object with a given unicode TString - int_t CompareNoCase(const TString& str) const; ///< Comparison (case insensitive) of this TString object with another TString object + /** \name Standard operations */ + /**@{*/ + // appends the given TString to this + void Append(const wchar_t* pszSrc); ///< Appends an unicode TString to the TString object + void Append(const TString& src); ///< Appends a TString object to another TString object - bool StartsWith(const wchar_t* pszText) const; - bool StartsWithNoCase(const wchar_t* pszText) const; + TString Left(size_t tLen) const; ///< Returns TString with the Left part of a source TString + TString Right(size_t tLen) const; ///< Returns TString with the Right part of a source TString + TString Mid(size_t tStart, size_t tLen = (size_t)-1) const; ///< Returns TString with the middle part of a source TString + TString MidRange(size_t tStart, size_t stAfterEndPos) const; ///< Returns TString with the middle part of a source TString - bool EndsWith(const wchar_t* pszText) const; - bool EndsWithNoCase(const wchar_t* pszText) const; + void LeftSelf(size_t tLen); ///< Makes this TString it's Left part + void RightSelf(size_t tLen); ///< Makes this TString it's Right part + void MidSelf(size_t tStart, size_t tLen = (size_t)-1); ///< Makes this TString it's middle part - size_t FindFirstOf(const wchar_t* pszChars, size_t stStartFromPos = 0) const; - size_t FindLastOf(const wchar_t* pszChars) const; + void TrimRightSelf(const wchar_t* pszElements); - size_t Find(const wchar_t* pszText, size_t stStartPos = 0); - void Replace(const wchar_t* pszWhat, const wchar_t* pszWithWhat); + bool Delete(size_t stIndex, size_t stCount); - bool GetAt(size_t tPos, wchar_t& wch) const; ///< Gets a character at a specified position - wchar_t GetAt(size_t tPos) const; + void Split(const wchar_t* pszSeparators, TStringArray& rStrings) const; - const wchar_t* c_str() const; + // compare operations + int_t Compare(const wchar_t* psz) const; ///< Comparison of this TString object with a given unicode TString + int_t Compare(const TString& str) const; ///< Comparison of this TString object with another TString object - wchar_t* GetBuffer(size_t tMinSize); ///< Gives user access to the unicode internal buffer - void ReleaseBuffer(); ///< Releases the buffer get from get_bufferx functions - void ReleaseBufferSetLength(size_t tSize); - - size_t GetLength() const; ///< Returns the GetLength of this TString in chars + int_t CompareNoCase(const wchar_t* psz) const; ///< Comparison (case insensitive) of this TString object with a given unicode TString + int_t CompareNoCase(const TString& str) const; ///< Comparison (case insensitive) of this TString object with another TString object - void Clear(); ///< Clear the contents of the TString object + bool StartsWith(const wchar_t* pszText) const; + bool StartsWithNoCase(const wchar_t* pszText) const; - bool IsEmpty() const; ///< Returns true if the TString is empty -/**@}*/ + bool EndsWith(const wchar_t* pszText) const; + bool EndsWithNoCase(const wchar_t* pszText) const; -protected: - void SetString(const wchar_t* pszStart, size_t stCount); - void SetString(const wchar_t* pszString); - void Reserve(size_t stLen); + size_t FindFirstOf(const wchar_t* pszChars, size_t stStartFromPos = 0) const; + size_t FindLastOf(const wchar_t* pszChars) const; -protected: - wchar_t* m_pszData; // contains the real string inside - size_t m_stBufferSize; // allocated string buffer size + size_t Find(const wchar_t* pszText, size_t stStartPos = 0); + void Replace(const wchar_t* pszWhat, const wchar_t* pszWithWhat); -public: - static const size_t npos = (size_t)-1; - static const size_t DefaultMaxStringSize = 65536; -}; + bool GetAt(size_t tPos, wchar_t& wch) const; ///< Gets a character at a specified position + wchar_t GetAt(size_t tPos) const; -inline std::wostream& operator<<(std::wostream& os, const TString& rString) -{ - return os << std::wstring(rString.c_str()); -} + const wchar_t* c_str() const; -END_CHCORE_NAMESPACE + wchar_t* GetBuffer(size_t tMinSize); ///< Gives user access to the unicode internal buffer + void ReleaseBuffer(); ///< Releases the buffer get from get_bufferx functions + void ReleaseBufferSetLength(size_t tSize); + size_t GetLength() const; ///< Returns the GetLength of this TString in chars + + void Clear(); ///< Clear the contents of the TString object + + bool IsEmpty() const; ///< Returns true if the TString is empty + /**@}*/ + + protected: + void SetString(const wchar_t* pszStart, size_t stCount); + void SetString(const wchar_t* pszString); + void Reserve(size_t stLen); + + protected: + wchar_t* m_pszData; // contains the real string inside + size_t m_stBufferSize; // allocated string buffer size + + public: + static const size_t npos = (size_t)-1; + static const size_t DefaultMaxStringSize = 65536; + }; + + inline std::wostream& operator<<(std::wostream& os, const TString& rString) + { + return os << std::wstring(rString.c_str()); + } +} + LIBCHCORE_API chcore::TString operator+(const wchar_t* pszString, const chcore::TString& str); #endif