/* ========================================================================== * ÀÛ ¼º ÀÚ : À̼ø±Ô * ÀÛ ¼º ÀÏ : 2006.09.12 * ³» ¿ë : std::basic_stringÀ» °¨½Ñ ±âº» ½ºÆ®¸µ ÅÛÇø´ * ÁÖÀÇ»çÇ× : *===========================================================================*/ #pragma once #pragma warning( push ) //#pragma warning( disable: 4996 ) #pragma warning( disable: 4245 ) #pragma warning( disable: 4267 ) #include #include "CharTraits.h" using namespace std; template class tBasicString; /// ¹®ÀÚ¿­ ±â¹Ý template class tBasicString : protected basic_string { typedef basic_string basic_string; typedef tBasicString cSelf; static const int BUFFER_SIZE = 1024; public: typedef T* cIterator; static const unsigned int NPOS = (unsigned int)basic_string::npos; public: /* explicit tBasicString(); tBasicString( const cSelf& s ); tBasicString( const cSelf& s, unsigned int pos, unsigned int n = NPOS ); tBasicString( const T* s ); tBasicString( const T* s, unsigned int n ); tBasicString( const T* first, const T* last ); tBasicString( unsigned int n, T c ); explicit tBasicString( unsigned int n ); /// ¸ðµç ±ÛÀÚ¸¦ Á¦°Å void Clear(); /// ¿ë·®À» ¼³Á¤ void Reserve( unsigned int n ); /// ±ÛÀÚ¸¦ ¸¶Áö¸·¿¡ Ãß°¡ void PushBack( T c ); /// ¸¶Áö¸· ±ÛÀÚ¸¦ Á¦°Å void PopBack(); /// ±ÛÀÚ ¼ö¸¦ ¼³Á¤ /// ¸Þ¸ð¸® ¿ë·®ÀÌ ±ÛÀÚ ¼ö¿¡ ¸Â°Ô º¯ÇÑ´Ù. void Resize( unsigned int n ); void Resize( unsigned int n, T c ); /// ¹®ÀÚ¿­À» µÚ¿¡ Ãß°¡ void Append( cIterator first, cIterator last ); void Append( const cSelf& s ); bool Append( const cSelf& s, unsigned int pos, unsigned int n ); void Append( const T* s ); void Append( const T* s, unsigned int n ); /// ±ÛÀÚ¸¦ ¸¶Áö¸·¿¡ Ãß°¡ void Append( T c ); /// ÇØ´ç À§Ä¡¿¡ ¹®ÀÚ¿­À» »ðÀÔ bool Insert( unsigned int pos, const cSelf& s ); bool Insert( unsigned int pos, const cSelf& s, unsigned int beg, unsigned int n ); bool Insert( unsigned int pos, const T* s, unsigned int n ); bool Insert( unsigned int pos, const T* s ); /// [first, last) ¹üÀ§ÀÇ ¹®ÀÚ¿­À» »èÁ¦ void Erase( cIterator first, cIterator last ); bool Erase( unsigned int pos = 0, unsigned int n = NPOS ); /// ¿ÞÂÊ °ø¹é Á¦°Å void TrimLeft(); void TrimLeft( const T* s ); void TrimLeft( T c ); /// ¿À¸¥ÂÊ °ø¹é Á¦°Å void TrimRight(); void TrimRight( const T* s ); void TrimRight( T c ); /// ¹®ÀÚ¿­ ±³Ã¼ void Replace( cIterator first0, cIterator last0, cIterator first1, cIterator last1 ); bool Replace( unsigned int pos, unsigned int n, const cSelf& s ); bool Replace( unsigned int pos0, unsigned int n0, const cSelf& s, unsigned int pos1, unsigned int n1 ); bool Replace( unsigned int pos, unsigned int n0, const T* s, unsigned int n1 ); bool Replace( unsigned int pos, unsigned int n, const T* s ); void Replace( cIterator first, cIterator last, const cSelf& s ); void Replace( cIterator first, cIterator last, const T* s, unsigned int n ); void Replace( cIterator first, cIterator last, const T* s ); void Replace( const cSelf& oldStr, const cSelf& newStr ); void Replace( const T* oldStr, const T* newStr ); void Replace( T oldChar, T newChar ); /// °Ë»ö unsigned int Find( const cSelf& s, unsigned int pos = 0 ) const; unsigned int Find( const T* s, unsigned int pos = 0 ) const; unsigned int Find( T c, unsigned int pos = 0 ) const; unsigned int FindReverse( const cSelf& s, unsigned int pos = NPOS ) const; unsigned int FindReverse( const T* s, unsigned int pos = NPOS ) const; unsigned int FindReverse( T c, unsigned int pos = NPOS ) const; /// ¹®ÀÚ¿­ sÀÇ ºÎºÐÀΠù¹øÂ° ¹®ÀÚ¸¦ °Ë»ö unsigned int FindFirstof( const cSelf& s, unsigned int pos = 0 ) const; unsigned int FindFirstof( const T* s, unsigned int pos = 0 ) const; /// ¹®ÀÚ¿­ sÀÇ ºÎºÐÀÎ ¸¶Áö¸· ¹®ÀÚ¸¦ °Ë»ö unsigned int FindLastof( const cSelf& s, unsigned int pos = NPOS ) const; unsigned int FindLastof( const T* s, unsigned int pos = NPOS ) const; /// ¹®ÀÚ¿­ sÀÇ ºÎºÐÀÌ ¾Æ´Ñ ù¹øÂ° ¹®ÀÚÀÇ À§Ä¡¸¦ ¸®ÅÏ unsigned int FindFirstNotof( const cSelf& s, unsigned int pos = 0 ) const; unsigned int FindFirstNotof( const T* s, unsigned int pos = 0 ) const; /// ¹®ÀÚ c¿Í °°Àº ù¹øÂ° ¹®ÀÚÀÇ À§Ä¡¸¦ ¸®ÅÏ unsigned int FindFirstNotof( T c, unsigned int pos = 0 ) const; /// ¹®ÀÚ¿­ sÀÇ ºÎºÐÀÌ ¾Æ´Ñ ¸¶Áö¸· ¹®ÀÚÀÇ À§Ä¡¸¦ ¸®ÅÏ unsigned int FindLastNotof( const cSelf& s, unsigned int pos = NPOS ) const; unsigned int FindLastNotof( const T* s, unsigned int pos = NPOS ) const; /// ¹®ÀÚ c°¡ ¾Æ´Ñ ¸¶Áö¸· ¹®ÀÚÀÇ À§Ä¡¸¦ ¸®ÅÏ unsigned int FindLastNotof( T c, unsigned int pos = NPOS ) const; /// ºÎºÐ ¹®ÀÚ¿­À» ¸®ÅÏ cSelf SubStr( unsigned int pos = 0, unsigned int n = NPOS ) const; cSelf Mid( unsigned int pos ) const; cSelf Mid( unsigned int pos, unsigned int count ) const; cSelf Left( unsigned int count ) const; cSelf Right( unsigned int count ) const; /// ºñ±³ int Compare( const cSelf& s ) const; int Compare( const cSelf& s, unsigned int pos, unsigned int len ) const; int Compare( unsigned int pos, unsigned int n, const cSelf& s ) const; int Compare( unsigned int pos0, unsigned int n0, const cSelf& s, unsigned int pos1, unsigned int n1 ) const; int Compare( const T* s ) const; int Compare( const T* s, unsigned int pos, unsigned int len ) const; int Compare( unsigned int pos, unsigned int n, const T* s ) const; int Compare( unsigned int pos, unsigned int n, const T* s, unsigned int n1 ) const; int CompareNoCase( const cSelf& s ) const; int CompareNoCase( const cSelf& str, unsigned int pos, unsigned int len ) const; int CompareNoCase( const T* str ) const; int CompareNoCase( const T* str, unsigned int pos, unsigned int len ) const; /// Çü½ÄÈ­ ÀÔ·Â void Format( const T* fmt, ... ); void FormatV( const T* fmt, va_list vl ); /// º¯È¯ void ToUpper(); void ToLower(); int ToInt() const; float ToFloat() const; /// ¹Ýº¹ÀÚ¸¦ ¸®ÅÏ cIterator Begin(); const T* Begin() const; cIterator End(); const T* End() const; /// ºñ¾îÀÖ´ÂÁö ¿©ºÎ¸¦ ¸®ÅÏ bool IsEmpty() const; /// ÇØ½Ã Äڵ带 ¸®ÅÏ operator unsigned int() const; unsigned int GetHashCode() const; /// Å©±â(±æÀÌ)¸¦ ¸®ÅÏ unsigned int GetSize() const; unsigned int GetLength() const; /// ¿ë·®À» ¸®ÅÏ unsigned int GetCapacity() const; /// 0À¸·Î ³¡³ª´Â ¹®ÀÚ¿­À» ¸®ÅÏ const T* Cstr() const; /// ´ëÀÔ ¿¬»êÀÚ cSelf& operator = ( const cSelf& s ); cSelf& operator = ( const T* s ); cSelf& operator = ( T c ); cSelf& operator += ( const cSelf& s ); cSelf& operator += ( const T* s ); cSelf& operator += ( T c ); /// ÂüÁ¶ ¿¬»êÀÚ T& operator [] ( unsigned int i ); const T& operator [] ( unsigned int i ) const; */ # include "BasicString.inl" }; template inline tBasicString operator + ( const tBasicString& x, const tBasicString& y ) { typedef tBasicString Str; Str out( x.GetSize() + y.GetSize() ); out.Append( x ); out.Append( y ); return out; } template inline tBasicString operator + ( const T* s, const tBasicString& y ) { typedef tBasicString Str; unsigned int n = TRAITS::length( s ); Str out( n + y.GetSize() ); out.Append( s ); out.Append( y ); return out; } template inline tBasicString operator + ( T c, const tBasicString& y ) { typedef tBasicString Str; Str out( 1 + y.GetSize() ); out.PushBack( c ); out.Append( y ); return out; } template inline tBasicString operator + ( const tBasicString& x, const T* s ) { typedef tBasicString Str; unsigned int n = TRAITS::length( s ); Str out( x.GetSize() + n ); out.Append( x ); out.Append( s ); return out; } template inline tBasicString operator + ( const tBasicString& x, const T c ) { typedef tBasicString Str; Str out( x.GetSize() + 1 ); out.Append( x ); out.PushBack( c ); return out; } template inline bool operator == ( const tBasicString& x, const tBasicString& y ) { return x.GetSize() == y.GetSize() && TRAITS::Compare( x.Cstr(), y.Cstr(), x.GetSize() ) == 0; } template inline bool operator == ( const T* s, const tBasicString& y ) { unsigned int n = TRAITS::length( s ); return n == y.GetSize() && TRAITS::Compare( s, y.Cstr(), n ) == 0; } template inline bool operator == ( const tBasicString& x, const T* s ) { unsigned int n = TRAITS::length( s ); return x.GetSize() == n && TRAITS::Compare( x.Cstr(), s, n ) == 0; } template inline bool operator < ( const tBasicString& x, const tBasicString& y ) { return TRAITS::Compare( x.Begin(), y.Begin() ) < 0; } template inline bool operator < ( const T* s, const tBasicString& y ) { return TRAITS::Compare( s, y.Begin() ) < 0; } template inline bool operator < ( const tBasicString& x, const T* s ) { return TRAITS::Compare( x.Begin(), s ) < 0; } template inline bool operator != ( const tBasicString& x, const tBasicString& y ) { return !(x == y); } template inline bool operator > ( const tBasicString& x, const tBasicString& y ) { return y < x; } template inline bool operator <= ( const tBasicString& x, const tBasicString& y ) { return !(y < x); } template inline bool operator >= ( const tBasicString& x, const tBasicString& y ) { return !(x < y); } template inline bool operator != ( const T* s, const tBasicString& y ) { return !(s == y); } template inline bool operator != ( const tBasicString& x, const T* s ) { return !(x == s); } template inline bool operator > ( const T* s, const tBasicString& y ) { return y < s; } template inline bool operator > ( const tBasicString& x, const T* s ) { return s < x; } template inline bool operator <= ( const T* s, const tBasicString& y ) { return !(y < s); } template inline bool operator <= ( const tBasicString& x, const T* s ) { return !(s < x); } template inline bool operator >= ( const T* s, const tBasicString& y ) { return !(s < y); } template inline bool operator >= ( const tBasicString& x, const T* s ) { return !(x < s); } #pragma warning( pop ) /// ¹®ÀÚ¿­ typedef tBasicString > cString; typedef tBasicString > cStringW; #ifdef _UNICODE ; typedef wchar_t charT; ; typedef cStringW cStringT; #else ; typedef char charT; ; typedef cString cStringT; #endif //_UNICODE