X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/95691abd435bd311c72d5fd80f0da5b7f6ea53d2..cbeda384e51acb82e13994cb67ac1714669cae10:/include/wx/ustring.h diff --git a/include/wx/ustring.h b/include/wx/ustring.h index ebf8e43536..68494d5767 100644 --- a/include/wx/ustring.h +++ b/include/wx/ustring.h @@ -3,12 +3,12 @@ // Purpose: 32-bit string (UCS-4) // Author: Robert Roebling // Copyright: (c) Robert Roebling -// RCS-ID: $Id: tab.h 37400 2006-02-09 00:28:34Z VZ $ +// RCS-ID: $Id$ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_USTRING_H_BASE_ -#define _WX_USTRING_H_BASE_ +#ifndef _WX_USTRING_H_ +#define _WX_USTRING_H_ #include "wx/defs.h" #include "wx/string.h" @@ -17,37 +17,41 @@ #if SIZEOF_WCHAR_T == 2 typedef wxWCharBuffer wxU16CharBuffer; +typedef wxScopedWCharBuffer wxScopedU16CharBuffer; #else typedef wxCharTypeBuffer wxU16CharBuffer; +typedef wxScopedCharTypeBuffer wxScopedU16CharBuffer; #endif #if SIZEOF_WCHAR_T == 4 typedef wxWCharBuffer wxU32CharBuffer; +typedef wxScopedWCharBuffer wxScopedU32CharBuffer; #else typedef wxCharTypeBuffer wxU32CharBuffer; +typedef wxScopedCharTypeBuffer wxScopedU32CharBuffer; #endif class WXDLLIMPEXP_BASE wxUString: public std::basic_string { -public: +public: wxUString() { } - + wxUString( const wxChar32 *str ) { assign(str); } wxUString( const wxUString &str ) { assign(str); } - wxUString( const wxU32CharBuffer &buf ) { assign(buf); } - + wxUString( const wxScopedU32CharBuffer &buf ) { assign(buf); } + wxUString( const char *str ) { assign(str); } - wxUString( const wxCharBuffer &buf ) { assign(buf); } + wxUString( const wxScopedCharBuffer &buf ) { assign(buf); } wxUString( const char *str, const wxMBConv &conv ) { assign(str,conv); } - wxUString( const wxCharBuffer &buf, const wxMBConv &conv ) { assign(buf,conv); } + wxUString( const wxScopedCharBuffer &buf, const wxMBConv &conv ) { assign(buf,conv); } wxUString( const wxChar16 *str ) { assign(str); } - wxUString( const wxU16CharBuffer &buf ) { assign(buf); } - + wxUString( const wxScopedU16CharBuffer &buf ) { assign(buf); } + wxUString( const wxCStrData *cstr ) { assign(cstr); } wxUString( const wxString &str ) { assign(str); } - + wxUString( char ch ) { assign(ch); } wxUString( wxChar16 ch ) { assign(ch); } wxUString( wxChar32 ch ) { assign(ch); } @@ -58,53 +62,53 @@ public: wxUString( size_type n, wxChar32 ch ) { assign(n,ch); } wxUString( size_type n, wxUniChar ch ) { assign(n,ch); } wxUString( size_type n, wxUniCharRef ch ) { assign(n,ch); } - + // static construction - + static wxUString FromAscii( const char *str, size_type n ) { wxUString ret; ret.assignFromAscii( str, n ); return ret; } - + static wxUString FromAscii( const char *str ) { wxUString ret; ret.assignFromAscii( str ); return ret; } - + static wxUString FromUTF8( const char *str, size_type n ) { wxUString ret; ret.assignFromUTF8( str, n ); return ret; } - + static wxUString FromUTF8( const char *str ) { wxUString ret; ret.assignFromUTF8( str ); return ret; } - + static wxUString FromUTF16( const wxChar16 *str, size_type n ) { wxUString ret; ret.assignFromUTF16( str, n ); return ret; } - + static wxUString FromUTF16( const wxChar16 *str ) { wxUString ret; ret.assignFromUTF16( str ); return ret; } - + // assign from encoding - + wxUString &assignFromAscii( const char *str ); wxUString &assignFromAscii( const char *str, size_type n ); wxUString &assignFromUTF8( const char *str ); @@ -113,14 +117,14 @@ public: wxUString &assignFromUTF16( const wxChar16* str, size_type n ); wxUString &assignFromCString( const char* str ); wxUString &assignFromCString( const char* str, const wxMBConv &conv ); - + // conversions - - wxCharBuffer utf8_str() const; - wxU16CharBuffer utf16_str() const; - + + wxScopedCharBuffer utf8_str() const; + wxScopedU16CharBuffer utf16_str() const; + #if SIZEOF_WCHAR_T == 2 - wxWCharBuffer wc_str() const + wxScopedWCharBuffer wc_str() const { return utf16_str(); } @@ -145,13 +149,13 @@ public: } #if wxUSE_UNICODE_UTF8 - wxCharBuffer wx_str() + wxScopedCharBuffer wx_str() { return utf8_str(); } #else #if SIZEOF_WCHAR_T == 2 - wxWCharBuffer wx_str() + wxScopedWCharBuffer wx_str() { return utf16_str(); } @@ -164,78 +168,78 @@ public: #endif // assign - - inline wxUString &assign( const wxChar32* str ) + + wxUString &assign( const wxChar32* str ) { std::basic_string *base = this; return (wxUString &) base->assign( str ); } - - inline wxUString &assign( const wxChar32* str, size_type n ) + + wxUString &assign( const wxChar32* str, size_type n ) { std::basic_string *base = this; return (wxUString &) base->assign( str, n ); } - - inline wxUString &assign( const wxUString &str ) + + wxUString &assign( const wxUString &str ) { std::basic_string *base = this; return (wxUString &) base->assign( str ); } - - inline wxUString &assign( const wxUString &str, size_type pos, size_type n ) + + wxUString &assign( const wxUString &str, size_type pos, size_type n ) { std::basic_string *base = this; return (wxUString &) base->assign( str, pos, n ); } - - inline wxUString &assign( wxChar32 ch ) + + wxUString &assign( wxChar32 ch ) { std::basic_string *base = this; return (wxUString &) base->assign( (size_type) 1, ch ); } - - inline wxUString &assign( size_type n, wxChar32 ch ) + + wxUString &assign( size_type n, wxChar32 ch ) { std::basic_string *base = this; return (wxUString &) base->assign( n, ch ); } - - wxUString &assign( const wxU32CharBuffer &buf ) + + wxUString &assign( const wxScopedU32CharBuffer &buf ) { return assign( buf.data() ); } - + wxUString &assign( const char *str ) { return assignFromCString( str ); } - - wxUString &assign( const wxCharBuffer &buf ) - { + + wxUString &assign( const wxScopedCharBuffer &buf ) + { return assignFromCString( buf.data() ); } - + wxUString &assign( const char *str, const wxMBConv &conv ) - { + { return assignFromCString( str, conv ); } - - wxUString &assign( const wxCharBuffer &buf, const wxMBConv &conv ) - { + + wxUString &assign( const wxScopedCharBuffer &buf, const wxMBConv &conv ) + { return assignFromCString( buf.data(), conv ); } - + wxUString &assign( const wxChar16 *str ) { return assignFromUTF16( str ); } - - wxUString &assign( const wxU16CharBuffer &buf ) + + wxUString &assign( const wxScopedU16CharBuffer &buf ) { return assignFromUTF16( buf.data() ); } - + wxUString &assign( const wxCStrData *cstr ) { #if SIZEOF_WCHAR_T == 2 @@ -244,7 +248,7 @@ public: return assign( cstr->AsWChar() ); #endif } - + wxUString &assign( const wxString &str ) { #if wxUSE_UNICODE_UTF8 @@ -253,11 +257,11 @@ public: #if SIZEOF_WCHAR_T == 2 return assignFromUTF16( str.wc_str() ); #else - return assign( wc_str() ); + return assign( str.wc_str() ); #endif #endif } - + wxUString &assign( char ch ) { char buf[2]; @@ -265,9 +269,9 @@ public: buf[1] = 0; return assignFromCString( buf ); } - + wxUString &assign( size_type n, char ch ) - { + { wxCharBuffer buffer(n); char *p = buffer.data(); size_type i; @@ -278,7 +282,7 @@ public: } return assignFromCString( buffer.data() ); } - + wxUString &assign( wxChar16 ch ) { wxChar16 buf[2]; @@ -286,7 +290,7 @@ public: buf[1] = 0; return assignFromUTF16( buf ); } - + wxUString &assign( size_type n, wxChar16 ch ) { wxU16CharBuffer buffer(n); @@ -299,60 +303,60 @@ public: } return assignFromUTF16( buffer.data() ); } - + wxUString &assign( wxUniChar ch ) { - return assign( (const wxChar32) ch.GetValue() ); + return assign( (wxChar32) ch.GetValue() ); } - + wxUString &assign( size_type n, wxUniChar ch ) { - return assign( n, (const wxChar32) ch.GetValue() ); + return assign( n, (wxChar32) ch.GetValue() ); } - + wxUString &assign( wxUniCharRef ch ) { - return assign( (const wxChar32) ch.GetValue() ); + return assign( (wxChar32) ch.GetValue() ); } - + wxUString &assign( size_type n, wxUniCharRef ch ) { - return assign( n, (const wxChar32) ch.GetValue() ); + return assign( n, (wxChar32) ch.GetValue() ); } - + // append [STL overload] - - inline wxUString &append( const wxUString &s ) + + wxUString &append( const wxUString &s ) { std::basic_string *base = this; return (wxUString &) base->append( s ); } - - inline wxUString &append( const wxUString &s, size_type pos, size_type n ) + + wxUString &append( const wxUString &s, size_type pos, size_type n ) { std::basic_string *base = this; return (wxUString &) base->append( s, pos, n ); } - - inline wxUString &append( const wxChar32* s ) + + wxUString &append( const wxChar32* s ) { std::basic_string *base = this; return (wxUString &) base->append( s ); } - inline wxUString &append( const wxChar32* s, size_type n ) + wxUString &append( const wxChar32* s, size_type n ) { std::basic_string *base = this; return (wxUString &) base->append( s, n ); } - inline wxUString &append( size_type n, wxChar32 c ) + wxUString &append( size_type n, wxChar32 c ) { std::basic_string *base = this; return (wxUString &) base->append( n, c ); } - inline wxUString &append( wxChar32 c ) + wxUString &append( wxChar32 c ) { std::basic_string *base = this; return (wxUString &) base->append( 1, c ); @@ -360,12 +364,12 @@ public: // append [wx overload] - wxUString &append( const wxU16CharBuffer &buf ) + wxUString &append( const wxScopedU16CharBuffer &buf ) { return append( buf.data() ); } - wxUString &append( const wxU32CharBuffer &buf ) + wxUString &append( const wxScopedU32CharBuffer &buf ) { return append( buf.data() ); } @@ -375,7 +379,7 @@ public: return append( wxUString( str ) ); } - wxUString &append( const wxCharBuffer &buf ) + wxUString &append( const wxScopedCharBuffer &buf ) { return append( wxUString( buf ) ); } @@ -384,17 +388,17 @@ public: { return append( wxUString( str ) ); } - + wxUString &append( const wxString &str ) { return append( wxUString( str ) ); } - + wxUString &append( const wxCStrData *cstr ) { return append( wxUString( cstr ) ); } - + wxUString &append( char ch ) { char buf[2]; @@ -402,7 +406,7 @@ public: buf[1] = 0; return append( buf ); } - + wxUString &append( wxChar16 ch ) { wxChar16 buf[2]; @@ -410,7 +414,7 @@ public: buf[1] = 0; return append( buf ); } - + wxUString &append( wxUniChar ch ) { return append( (size_type) 1, (wxChar32) ch.GetValue() ); @@ -421,34 +425,34 @@ public: return append( (size_type) 1, (wxChar32) ch.GetValue() ); } - + // insert [STL overloads] - - inline wxUString &insert( size_type pos, const wxUString &s ) + + wxUString &insert( size_type pos, const wxUString &s ) { std::basic_string *base = this; return (wxUString &) base->insert( pos, s ); } - inline wxUString &insert( size_type pos, const wxUString &s, size_type pos1, size_type n ) + wxUString &insert( size_type pos, const wxUString &s, size_type pos1, size_type n ) { std::basic_string *base = this; return (wxUString &) base->insert( pos, s, pos1, n ); } - inline wxUString &insert( size_type pos, const wxChar32 *s ) + wxUString &insert( size_type pos, const wxChar32 *s ) { std::basic_string *base = this; return (wxUString &) base->insert( pos, s ); } - inline wxUString &insert( size_type pos, const wxChar32 *s, size_type n ) + wxUString &insert( size_type pos, const wxChar32 *s, size_type n ) { std::basic_string *base = this; return (wxUString &) base->insert( pos, s, n ); } - inline wxUString &insert( size_type pos, size_type n, wxChar32 c ) + wxUString &insert( size_type pos, size_type n, wxChar32 c ) { std::basic_string *base = this; return (wxUString &) base->insert( pos, n, c ); @@ -467,17 +471,17 @@ public: return insert( n, wxUString( s ) ); } - wxUString &insert( size_type n, const wxCharBuffer &buf ) + wxUString &insert( size_type n, const wxScopedCharBuffer &buf ) { return insert( n, wxUString( buf ) ); } - wxUString &insert( size_type n, const wxU16CharBuffer &buf ) + wxUString &insert( size_type n, const wxScopedU16CharBuffer &buf ) { return insert( n, wxUString( buf ) ); } - wxUString &insert( size_type n, const wxU32CharBuffer &buf ) + wxUString &insert( size_type n, const wxScopedU32CharBuffer &buf ) { return insert( n, buf.data() ); } @@ -486,12 +490,12 @@ public: { return insert( n, wxUString( s ) ); } - + wxUString &insert( size_type n, const wxCStrData *cstr ) { return insert( n, wxUString( cstr ) ); } - + wxUString &insert( size_type n, char ch ) { char buf[2]; @@ -499,7 +503,7 @@ public: buf[1] = 0; return insert( n, buf ); } - + wxUString &insert( size_type n, wchar_t ch ) { wchar_t buf[2]; @@ -507,15 +511,15 @@ public: buf[1] = 0; return insert( n, buf ); } - + // insert iterator - + iterator insert( iterator it, wxChar32 ch ) { std::basic_string *base = this; return base->insert( it, ch ); } - + void insert(iterator it, const_iterator first, const_iterator last) { std::basic_string *base = this; @@ -524,65 +528,65 @@ public: // operator = - inline wxUString& operator=(const wxUString& s) + wxUString& operator=(const wxUString& s) { return assign( s ); } - inline wxUString& operator=(const wxString& s) + wxUString& operator=(const wxString& s) { return assign( s ); } - inline wxUString& operator=(const wxCStrData* s) + wxUString& operator=(const wxCStrData* s) { return assign( s ); } - inline wxUString& operator=(const char *s) + wxUString& operator=(const char *s) { return assign( s ); } - inline wxUString& operator=(const wxChar16 *s) + wxUString& operator=(const wxChar16 *s) { return assign( s ); } - inline wxUString& operator=(const wxChar32 *s) + wxUString& operator=(const wxChar32 *s) { return assign( s ); } - inline wxUString& operator=(const wxCharBuffer &s) + wxUString& operator=(const wxScopedCharBuffer &s) { return assign( s ); } - inline wxUString& operator=(const wxU16CharBuffer &s) + wxUString& operator=(const wxScopedU16CharBuffer &s) { return assign( s ); } - inline wxUString& operator=(const wxU32CharBuffer &s) + wxUString& operator=(const wxScopedU32CharBuffer &s) { return assign( s ); } - inline wxUString& operator=(const char ch) + wxUString& operator=(const char ch) { return assign( ch ); } - inline wxUString& operator=(const wxChar16 ch) + wxUString& operator=(const wxChar16 ch) { return assign( ch ); } - inline wxUString& operator=(const wxChar32 ch) + wxUString& operator=(const wxChar32 ch) { return assign( ch ); } - inline wxUString& operator=(const wxUniChar ch) + wxUString& operator=(const wxUniChar ch) { return assign( ch ); } - inline wxUString& operator=(const wxUniCharRef ch) + wxUString& operator=(const wxUniCharRef ch) { return assign( ch ); } - + // operator += - inline wxUString& operator+=(const wxUString& s) + wxUString& operator+=(const wxUString& s) { return append( s ); } - inline wxUString& operator+=(const wxString& s) + wxUString& operator+=(const wxString& s) { return append( s ); } - inline wxUString& operator+=(const wxCStrData* s) + wxUString& operator+=(const wxCStrData* s) { return append( s ); } - inline wxUString& operator+=(const char *s) + wxUString& operator+=(const char *s) { return append( s ); } - inline wxUString& operator+=(const wxChar16 *s) + wxUString& operator+=(const wxChar16 *s) { return append( s ); } - inline wxUString& operator+=(const wxChar32 *s) + wxUString& operator+=(const wxChar32 *s) { return append( s ); } - inline wxUString& operator+=(const wxCharBuffer &s) + wxUString& operator+=(const wxScopedCharBuffer &s) { return append( s ); } - inline wxUString& operator+=(const wxU16CharBuffer &s) + wxUString& operator+=(const wxScopedU16CharBuffer &s) { return append( s ); } - inline wxUString& operator+=(const wxU32CharBuffer &s) + wxUString& operator+=(const wxScopedU32CharBuffer &s) { return append( s ); } - inline wxUString& operator+=(const char ch) + wxUString& operator+=(const char ch) { return append( ch ); } - inline wxUString& operator+=(const wxChar16 ch) + wxUString& operator+=(const wxChar16 ch) { return append( ch ); } - inline wxUString& operator+=(const wxChar32 ch) + wxUString& operator+=(const wxChar32 ch) { return append( ch ); } - inline wxUString& operator+=(const wxUniChar ch) + wxUString& operator+=(const wxUniChar ch) { return append( ch ); } - inline wxUString& operator+=(const wxUniCharRef ch) + wxUString& operator+=(const wxUniCharRef ch) { return append( ch ); } - + }; inline wxUString operator+(const wxUString &s1, const wxUString &s2) @@ -597,11 +601,11 @@ inline wxUString operator+(const wxUString &s1, const wxChar16* s2) { return s1 + wxUString(s2); } inline wxUString operator+(const wxUString &s1, const wxChar32 *s2) { return s1 + wxUString(s2); } -inline wxUString operator+(const wxUString &s1, const wxCharBuffer &s2) +inline wxUString operator+(const wxUString &s1, const wxScopedCharBuffer &s2) { return s1 + wxUString(s2); } -inline wxUString operator+(const wxUString &s1, const wxU16CharBuffer &s2) +inline wxUString operator+(const wxUString &s1, const wxScopedU16CharBuffer &s2) { return s1 + wxUString(s2); } -inline wxUString operator+(const wxUString &s1, const wxU32CharBuffer &s2) +inline wxUString operator+(const wxUString &s1, const wxScopedU32CharBuffer &s2) { return s1 + wxUString(s2); } inline wxUString operator+(const wxUString &s1, char s2) { return s1 + wxUString(s2); } @@ -624,11 +628,11 @@ inline wxUString operator+(const wxChar16* s1, const wxUString &s2) { return wxUString(s1) + s2; } inline wxUString operator+(const wxChar32 *s1, const wxUString &s2) { return wxUString(s1) + s2; } -inline wxUString operator+(const wxCharBuffer &s1, const wxUString &s2) +inline wxUString operator+(const wxScopedCharBuffer &s1, const wxUString &s2) { return wxUString(s1) + s2; } -inline wxUString operator+(const wxU16CharBuffer &s1, const wxUString &s2) +inline wxUString operator+(const wxScopedU16CharBuffer &s1, const wxUString &s2) { return wxUString(s1) + s2; } -inline wxUString operator+(const wxU32CharBuffer &s1, const wxUString &s2) +inline wxUString operator+(const wxScopedU32CharBuffer &s1, const wxUString &s2) { return wxUString(s1) + s2; } inline wxUString operator+(char s1, const wxUString &s2) { return wxUString(s1) + s2; } @@ -647,7 +651,7 @@ inline bool operator==(const wxUString& s1, const wxUString& s2) inline bool operator!=(const wxUString& s1, const wxUString& s2) { return s1.compare( s2 ) != 0; } inline bool operator< (const wxUString& s1, const wxUString& s2) - { wxPrintf( "test\n"); return s1.compare( s2 ) < 0; } + { return s1.compare( s2 ) < 0; } inline bool operator> (const wxUString& s1, const wxUString& s2) { return s1.compare( s2 ) > 0; } inline bool operator<=(const wxUString& s1, const wxUString& s2) @@ -686,10 +690,9 @@ wxUSTRING_COMP_OPERATORS( const wxString & ) wxUSTRING_COMP_OPERATORS( const char * ) wxUSTRING_COMP_OPERATORS( const wxChar16 * ) wxUSTRING_COMP_OPERATORS( const wxChar32 * ) -wxUSTRING_COMP_OPERATORS( const wxCharBuffer & ) -wxUSTRING_COMP_OPERATORS( const wxU16CharBuffer & ) -wxUSTRING_COMP_OPERATORS( const wxU32CharBuffer & ) +wxUSTRING_COMP_OPERATORS( const wxScopedCharBuffer & ) +wxUSTRING_COMP_OPERATORS( const wxScopedU16CharBuffer & ) +wxUSTRING_COMP_OPERATORS( const wxScopedU32CharBuffer & ) wxUSTRING_COMP_OPERATORS( const wxCStrData * ) -#endif - // _WX_USTRING_H_BASE_ +#endif // _WX_USTRING_H_