MyGUI  3.2.1
MyGUI_UString.h
Go to the documentation of this file.
00001 // Modified from OpenGUI under lenient license
00002 // Original copyright details and licensing below:
00003 // OpenGUI (http://opengui.sourceforge.net)
00004 // This source code is released under the BSD License
00005 
00006 // Permission is given to the MyGUI project to use the contents of file within its
00007 // source and binary applications, as well as any derivative works, in accordance
00008 // with the terms of any license under which MyGUI is or will be distributed.
00009 //
00010 // MyGUI may relicense its copy of this file, as well as any OpenGUI released updates
00011 // to this file, under any terms that it deems fit, and is not required to maintain
00012 // the original BSD licensing terms of this file, however OpenGUI retains the right
00013 // to present its copy of this file under the terms of any license under which
00014 // OpenGUI is distributed.
00015 //
00016 // MyGUI is not required to release to OpenGUI any future changes that it makes to
00017 // this file, and understands and agrees that any such changes that are released
00018 // back to OpenGUI will become available under the terms of any license under which
00019 // OpenGUI is distributed.
00020 //
00021 // For brevity, this permission text may be removed from this file if desired.
00022 // The original record kept within the SourceForge (http://sourceforge.net/) tracker
00023 // is sufficient.
00024 //
00025 // - Eric Shorkey (zero/zeroskill) <opengui@rightbracket.com> [January 20th, 2007]
00026 
00027 #ifndef __MYGUI_U_STRING_H__
00028 #define __MYGUI_U_STRING_H__
00029 
00030 
00031 #include "MyGUI_Prerequest.h"
00032 #include "MyGUI_Types.h"
00033 
00034 // these are explained later
00035 #include <iterator>
00036 #include <string>
00037 #include <stdexcept>
00038 
00039 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
00040 // disable: warning C4275: non dll-interface class '***' used as base for dll-interface clas '***'
00041 #   pragma warning (push)
00042 #   pragma warning (disable : 4275)
00043 #endif
00044 
00045 // Workaround for VC7:
00046 //      when build with /MD or /MDd, VC7 have both std::basic_string<unsigned short> and
00047 // basic_string<__wchar_t> instantiated in msvcprt[d].lib/MSVCP71[D].dll, but the header
00048 // files tells compiler that only one of them is over there (based on /Zc:wchar_t compile
00049 // option). And since this file used both of them, causing compiler instantiating another
00050 // one in user object code, which lead to duplicate symbols with msvcprt.lib/MSVCP71[D].dll.
00051 //
00052 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && (1300 <= MYGUI_COMP_VER && MYGUI_COMP_VER <= 1310)
00053 
00054 # if defined(_DLL_CPPLIB)
00055 
00056 namespace std
00057 {
00058     template class _CRTIMP2 basic_string<unsigned short, char_traits<unsigned short>,
00059         allocator<unsigned short> >;
00060 
00061     template class _CRTIMP2 basic_string<__wchar_t, char_traits<__wchar_t>,
00062         allocator<__wchar_t> >;
00063 }
00064 
00065 # endif // defined(_DLL_CPPLIB)
00066 
00067 #endif  // MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER == 1300
00068 
00069 
00070 namespace MyGUI
00071 {
00072 
00073     /* READ THIS NOTICE BEFORE USING IN YOUR OWN APPLICATIONS
00074     =NOTICE=
00075     This class is not a complete Unicode solution. It purposefully does not
00076     provide certain functionality, such as proper lexical sorting for
00077     Unicode values. It does provide comparison operators for the sole purpose
00078     of using UString as an index with std::map and other operator< sorted
00079     containers, but it should NOT be relied upon for meaningful lexical
00080     operations, such as alphabetical sorts. If you need this type of
00081     functionality, look into using ICU instead (http://icu.sourceforge.net/).
00082 
00083     =REQUIREMENTS=
00084     There are a few requirements for proper operation. They are fairly small,
00085     and shouldn't restrict usage on any reasonable target.
00086     * Compiler must support unsigned 16-bit integer types
00087     * Compiler must support signed 32-bit integer types
00088     * wchar_t must be either UTF-16 or UTF-32 encoding, and specified as such
00089         using the WCHAR_UTF16 macro as outlined below.
00090     * You must include <iterator>, <string>, and <wchar>. Probably more, but
00091         these are the most obvious.
00092 
00093     =REQUIRED PREPROCESSOR MACROS=
00094     This class requires two preprocessor macros to be defined in order to
00095     work as advertised.
00096     INT32 - must be mapped to a signed 32 bit integer (ex. #define INT32 int)
00097     UINT16 - must be mapped to an unsigned 16 bit integer (ex. #define UINT32 unsigned short)
00098 
00099     Additionally, a third macro should be defined to control the evaluation of wchar_t:
00100     WCHAR_UTF16 - should be defined when wchar_t represents UTF-16 code points,
00101         such as in Windows. Otherwise it is assumed that wchar_t is a 32-bit
00102         integer representing UTF-32 code points.
00103     */
00104 
00105     // THIS IS A VERY BRIEF AUTO DETECTION. YOU MAY NEED TO TWEAK THIS
00106 #ifdef __STDC_ISO_10646__
00107 // for any compiler that provides this, wchar_t is guaranteed to hold any Unicode value with a single code point (32-bit or larger)
00108 // so we can safely skip the rest of the testing
00109 #else // #ifdef __STDC_ISO_10646__
00110 #if defined( __WIN32__ ) || defined( _WIN32 )
00111 #define WCHAR_UTF16 // All currently known Windows platforms utilize UTF-16 encoding in wchar_t
00112 #else // #if defined( __WIN32__ ) || defined( _WIN32 )
00113 #if MYGUI_COMPILER != MYGUI_COMPILER_GCCE
00114 #if WCHAR_MAX <= 0xFFFF // this is a last resort fall back test; WCHAR_MAX is defined in <wchar.h>
00115 #define WCHAR_UTF16 // best we can tell, wchar_t is not larger than 16-bit
00116 #endif // #if WCHAR_MAX <= 0xFFFF
00117 #endif
00118 #endif // #if defined( __WIN32__ ) || defined( _WIN32 )
00119 #endif // #ifdef __STDC_ISO_10646__
00120 
00121 
00122 // MYGUI_IS_NATIVE_WCHAR_T means that wchar_t isn't a typedef of
00123 // uint16_t or uint32_t.
00124 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
00125 
00126 // Don't define wchar_t related functions since it'll duplicate
00127 // with UString::code_point related functions when compile
00128 // without /Zc:wchar_t, because in this case both of them are
00129 // a typedef of uint16_t.
00130 # if defined(_NATIVE_WCHAR_T_DEFINED)
00131 #   define MYGUI_IS_NATIVE_WCHAR_T      1
00132 # else
00133 #   define MYGUI_IS_NATIVE_WCHAR_T      0
00134 # endif
00135 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_SYMBIAN
00136 #   define MYGUI_IS_NATIVE_WCHAR_T      0
00137 #else   // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
00138 
00139 // Assumed wchar_t is natively for other compilers
00140 #   define MYGUI_IS_NATIVE_WCHAR_T     1
00141 
00142 #endif  // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
00143 
00145 
00170     class MYGUI_EXPORT UString {
00171         // constants used in UTF-8 conversions
00172         static const unsigned char _lead1 = 0xC0;      //110xxxxx
00173         static const unsigned char _lead1_mask = 0x1F; //00011111
00174         static const unsigned char _lead2 = 0xE0;      //1110xxxx
00175         static const unsigned char _lead2_mask = 0x0F; //00001111
00176         static const unsigned char _lead3 = 0xF0;      //11110xxx
00177         static const unsigned char _lead3_mask = 0x07; //00000111
00178         static const unsigned char _lead4 = 0xF8;      //111110xx
00179         static const unsigned char _lead4_mask = 0x03; //00000011
00180         static const unsigned char _lead5 = 0xFC;      //1111110x
00181         static const unsigned char _lead5_mask = 0x01; //00000001
00182         static const unsigned char _cont = 0x80;       //10xxxxxx
00183         static const unsigned char _cont_mask = 0x3F;  //00111111
00184 
00185     public:
00187         typedef size_t size_type;
00189         static const size_type npos = static_cast<size_type>(~0);
00190 
00192         typedef uint32 unicode_char;
00193 
00195         typedef uint16 code_point;
00196 
00198         typedef code_point value_type;
00199 
00200         typedef std::basic_string<code_point> dstring; // data string
00201 
00203         typedef std::basic_string<unicode_char> utf32string;
00204 
00206     class MYGUI_EXPORT invalid_data: public std::runtime_error { /* i don't know why the beautifier is freaking out on this line */
00207         public:
00209             explicit invalid_data( const std::string& _Message ): std::runtime_error( _Message ) {
00210                 /* The thing is, Bob, it's not that I'm lazy, it's that I just don't care. */
00211             }
00212         };
00213 
00214         //#########################################################################
00216     class MYGUI_EXPORT _base_iterator: public std::iterator<std::random_access_iterator_tag, value_type> { /* i don't know why the beautifier is freaking out on this line */
00217             friend class UString;
00218         protected:
00219             _base_iterator();
00220 
00221             void _seekFwd( size_type c );
00222             void _seekRev( size_type c );
00223             void _become( const _base_iterator& i );
00224             bool _test_begin() const;
00225             bool _test_end() const;
00226             size_type _get_index() const;
00227             void _jump_to( size_type index );
00228 
00229             unicode_char _getCharacter() const;
00230             int _setCharacter( unicode_char uc );
00231 
00232             void _moveNext();
00233             void _movePrev();
00234 
00235             dstring::iterator mIter;
00236             UString* mString;
00237         };
00238 
00239         //#########################################################################
00240         // FORWARD ITERATORS
00241         //#########################################################################
00242         class _const_fwd_iterator; // forward declaration
00243 
00245     class MYGUI_EXPORT _fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
00246             friend class _const_fwd_iterator;
00247         public:
00248             _fwd_iterator();
00249             _fwd_iterator( const _fwd_iterator& i );
00250 
00252             _fwd_iterator& operator++();
00254             _fwd_iterator operator++( int );
00255 
00257             _fwd_iterator& operator--();
00259             _fwd_iterator operator--( int );
00260 
00262             _fwd_iterator operator+( difference_type n );
00264             _fwd_iterator operator-( difference_type n );
00265 
00267             _fwd_iterator& operator+=( difference_type n );
00269             _fwd_iterator& operator-=( difference_type n );
00270 
00272             value_type& operator*() const;
00273 
00275             value_type& operator[]( difference_type n ) const;
00276 
00278             _fwd_iterator& moveNext();
00280             _fwd_iterator& movePrev();
00282             unicode_char getCharacter() const;
00284             int setCharacter( unicode_char uc );
00285         };
00286 
00287 
00288 
00289         //#########################################################################
00291     class MYGUI_EXPORT _const_fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
00292         public:
00293             _const_fwd_iterator();
00294             _const_fwd_iterator( const _const_fwd_iterator& i );
00295             _const_fwd_iterator( const _fwd_iterator& i );
00296 
00298             _const_fwd_iterator& operator++();
00300             _const_fwd_iterator operator++( int );
00301 
00303             _const_fwd_iterator& operator--();
00305             _const_fwd_iterator operator--( int );
00306 
00308             _const_fwd_iterator operator+( difference_type n );
00310             _const_fwd_iterator operator-( difference_type n );
00311 
00313             _const_fwd_iterator& operator+=( difference_type n );
00315             _const_fwd_iterator& operator-=( difference_type n );
00316 
00318             const value_type& operator*() const;
00319 
00321             const value_type& operator[]( difference_type n ) const;
00322 
00324             _const_fwd_iterator& moveNext();
00326             _const_fwd_iterator& movePrev();
00328             unicode_char getCharacter() const;
00329 
00331             friend size_type operator-( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
00333             friend bool operator==( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
00335             friend bool operator!=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
00337             friend bool operator<( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
00339             friend bool operator<=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
00341             friend bool operator>( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
00343             friend bool operator>=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
00344 
00345         };
00346 
00347         //#########################################################################
00348         // REVERSE ITERATORS
00349         //#########################################################################
00350         class _const_rev_iterator; // forward declaration
00352     class MYGUI_EXPORT _rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
00353             friend class _const_rev_iterator;
00354         public:
00355             _rev_iterator();
00356             _rev_iterator( const _rev_iterator& i );
00357 
00359             _rev_iterator& operator++();
00361             _rev_iterator operator++( int );
00362 
00364             _rev_iterator& operator--();
00366             _rev_iterator operator--( int );
00367 
00369             _rev_iterator operator+( difference_type n );
00371             _rev_iterator operator-( difference_type n );
00372 
00374             _rev_iterator& operator+=( difference_type n );
00376             _rev_iterator& operator-=( difference_type n );
00377 
00379             value_type& operator*() const;
00380 
00382             value_type& operator[]( difference_type n ) const;
00383         };
00384         //#########################################################################
00386     class MYGUI_EXPORT _const_rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
00387         public:
00388             _const_rev_iterator();
00389             _const_rev_iterator( const _const_rev_iterator& i );
00390             _const_rev_iterator( const _rev_iterator& i );
00392             _const_rev_iterator& operator++();
00394             _const_rev_iterator operator++( int );
00395 
00397             _const_rev_iterator& operator--();
00399             _const_rev_iterator operator--( int );
00400 
00402             _const_rev_iterator operator+( difference_type n );
00404             _const_rev_iterator operator-( difference_type n );
00405 
00407             _const_rev_iterator& operator+=( difference_type n );
00409             _const_rev_iterator& operator-=( difference_type n );
00410 
00412             const value_type& operator*() const;
00413 
00415             const value_type& operator[]( difference_type n ) const;
00416 
00418             friend size_type operator-( const _const_rev_iterator& left, const _const_rev_iterator& right );
00420             friend bool operator==( const _const_rev_iterator& left, const _const_rev_iterator& right );
00422             friend bool operator!=( const _const_rev_iterator& left, const _const_rev_iterator& right );
00424             friend bool operator<( const _const_rev_iterator& left, const _const_rev_iterator& right );
00426             friend bool operator<=( const _const_rev_iterator& left, const _const_rev_iterator& right );
00428             friend bool operator>( const _const_rev_iterator& left, const _const_rev_iterator& right );
00430             friend bool operator>=( const _const_rev_iterator& left, const _const_rev_iterator& right );
00431         };
00432         //#########################################################################
00433 
00434         typedef _fwd_iterator iterator;                     
00435         typedef _rev_iterator reverse_iterator;             
00436         typedef _const_fwd_iterator const_iterator;         
00437         typedef _const_rev_iterator const_reverse_iterator; 
00438 
00439 
00441 
00442 
00443         UString();
00445         UString( const UString& copy );
00447         UString( size_type length, const code_point& ch );
00449         UString( const code_point* str );
00451         UString( const code_point* str, size_type length );
00453         UString( const UString& str, size_type index, size_type length );
00454 #if MYGUI_IS_NATIVE_WCHAR_T
00455 
00456         UString( const wchar_t* w_str );
00458         UString( const wchar_t* w_str, size_type length );
00459 #endif
00460 
00461         UString( const std::wstring& wstr );
00463         UString( const char* c_str );
00465         UString( const char* c_str, size_type length );
00467         UString( const std::string& str );
00468 
00470         ~UString();
00472 
00474 
00476 
00477 
00478         size_type size() const;
00480         size_type length() const;
00482 
00483         size_type length_Characters() const;
00485         size_type max_size() const;
00487         void reserve( size_type size );
00489         void resize( size_type num, const code_point& val = 0 );
00491         void swap( UString& from );
00493         bool empty() const;
00495         const code_point* c_str() const;
00497         const code_point* data() const;
00499         size_type capacity() const;
00501         void clear();
00503 
00504         UString substr( size_type index, size_type num = npos ) const;
00506         void push_back( unicode_char val );
00507 #if MYGUI_IS_NATIVE_WCHAR_T
00508 
00509         void push_back( wchar_t val );
00510 #endif
00511 
00512 
00514         void push_back( code_point val );
00516 
00517         void push_back( char val );
00519         bool inString( unicode_char ch ) const;
00521 
00523 
00525 
00526 
00527         const std::string& asUTF8() const;
00529         const char* asUTF8_c_str() const;
00531         const utf32string& asUTF32() const;
00533         const unicode_char* asUTF32_c_str() const;
00535         const std::wstring& asWStr() const;
00537         const wchar_t* asWStr_c_str() const;
00539 
00541 
00543 
00544 
00545         code_point& at( size_type loc );
00547         const code_point& at( size_type loc ) const;
00549 
00553         unicode_char getChar( size_type loc ) const;
00555 
00563         int setChar( size_type loc, unicode_char ch );
00565 
00567 
00569 
00570 
00571         iterator begin();
00573         const_iterator begin() const;
00575         iterator end();
00577         const_iterator end() const;
00579         reverse_iterator rbegin();
00581         const_reverse_iterator rbegin() const;
00583         reverse_iterator rend();
00585         const_reverse_iterator rend() const;
00587 
00589 
00591 
00592 
00593         UString& assign( iterator start, iterator end );
00595         UString& assign( const UString& str );
00597         UString& assign( const code_point* str );
00599         UString& assign( const code_point* str, size_type num );
00601         UString& assign( const UString& str, size_type index, size_type len );
00603         UString& assign( size_type num, const code_point& ch );
00605         UString& assign( const std::wstring& wstr );
00606 #if MYGUI_IS_NATIVE_WCHAR_T
00607 
00608         UString& assign( const wchar_t* w_str );
00610         UString& assign( const wchar_t* w_str, size_type num );
00611 #endif
00612 
00613         UString& assign( const std::string& str );
00615         UString& assign( const char* c_str );
00617         UString& assign( const char* c_str, size_type num );
00619 
00621 
00623 
00624 
00625         UString& append( const UString& str );
00627         UString& append( const code_point* str );
00629         UString& append( const UString& str, size_type index, size_type len );
00631         UString& append( const code_point* str, size_type num );
00633         UString& append( size_type num, code_point ch );
00635         UString& append( iterator start, iterator end );
00636 #if MYGUI_IS_NATIVE_WCHAR_T
00637 
00638         UString& append( const wchar_t* w_str, size_type num );
00640         UString& append( size_type num, wchar_t ch );
00641 #endif
00642 
00643         UString& append( const char* c_str, size_type num );
00645         UString& append( size_type num, char ch );
00647         UString& append( size_type num, unicode_char ch );
00649 
00651 
00653 
00654 
00655         iterator insert( iterator i, const code_point& ch );
00657         UString& insert( size_type index, const UString& str );
00659         UString& insert( size_type index, const code_point* str ) {
00660             mData.insert( index, str );
00661             return *this;
00662         }
00664         UString& insert( size_type index1, const UString& str, size_type index2, size_type num );
00666         void insert( iterator i, iterator start, iterator end );
00668         UString& insert( size_type index, const code_point* str, size_type num );
00669 #if MYGUI_IS_NATIVE_WCHAR_T
00670 
00671         UString& insert( size_type index, const wchar_t* w_str, size_type num );
00672 #endif
00673 
00674         UString& insert( size_type index, const char* c_str, size_type num );
00676         UString& insert( size_type index, size_type num, code_point ch );
00677 #if MYGUI_IS_NATIVE_WCHAR_T
00678 
00679         UString& insert( size_type index, size_type num, wchar_t ch );
00680 #endif
00681 
00682         UString& insert( size_type index, size_type num, char ch );
00684         UString& insert( size_type index, size_type num, unicode_char ch );
00686         void insert( iterator i, size_type num, const code_point& ch );
00687 #if MYGUI_IS_NATIVE_WCHAR_T
00688 
00689         void insert( iterator i, size_type num, const wchar_t& ch );
00690 #endif
00691 
00692         void insert( iterator i, size_type num, const char& ch );
00694         void insert( iterator i, size_type num, const unicode_char& ch );
00696 
00698 
00700 
00701 
00702         iterator erase( iterator loc );
00704         iterator erase( iterator start, iterator end );
00706         UString& erase( size_type index = 0, size_type num = npos );
00708 
00710 
00712 
00713 
00714         UString& replace( size_type index1, size_type num1, const UString& str );
00716         UString& replace( size_type index1, size_type num1, const UString& str, size_type num2 );
00718         UString& replace( size_type index1, size_type num1, const UString& str, size_type index2, size_type num2 );
00720         UString& replace( iterator start, iterator end, const UString& str, size_type num = npos );
00722         UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
00724         UString& replace( iterator start, iterator end, size_type num, code_point ch );
00726 
00728 
00730 
00731 
00732         int compare( const UString& str ) const;
00734         int compare( const code_point* str ) const;
00736         int compare( size_type index, size_type length, const UString& str ) const;
00738         int compare( size_type index, size_type length, const UString& str, size_type index2, size_type length2 ) const;
00740         int compare( size_type index, size_type length, const code_point* str, size_type length2 ) const;
00741 #if MYGUI_IS_NATIVE_WCHAR_T
00742 
00743         int compare( size_type index, size_type length, const wchar_t* w_str, size_type length2 ) const;
00744 #endif
00745 
00746         int compare( size_type index, size_type length, const char* c_str, size_type length2 ) const;
00748 
00750 
00752 
00753 
00754 
00755         size_type find( const UString& str, size_type index = 0 ) const;
00757 
00758         size_type find( const code_point* cp_str, size_type index, size_type length ) const;
00760 
00761         size_type find( const char* c_str, size_type index, size_type length ) const;
00762 #if MYGUI_IS_NATIVE_WCHAR_T
00763 
00764 
00765         size_type find( const wchar_t* w_str, size_type index, size_type length ) const;
00766 #endif
00767 
00768 
00769         size_type find( char ch, size_type index = 0 ) const;
00771 
00772         size_type find( code_point ch, size_type index = 0 ) const;
00773 #if MYGUI_IS_NATIVE_WCHAR_T
00774 
00775 
00776         size_type find( wchar_t ch, size_type index = 0 ) const;
00777 #endif
00778 
00779 
00780         size_type find( unicode_char ch, size_type index = 0 ) const;
00781 
00783         size_type rfind( const UString& str, size_type index = 0 ) const;
00785         size_type rfind( const code_point* cp_str, size_type index, size_type num ) const;
00787         size_type rfind( const char* c_str, size_type index, size_type num ) const;
00788 #if MYGUI_IS_NATIVE_WCHAR_T
00789 
00790         size_type rfind( const wchar_t* w_str, size_type index, size_type num ) const;
00791 #endif
00792 
00793         size_type rfind( char ch, size_type index = 0 ) const;
00795         size_type rfind( code_point ch, size_type index ) const;
00796 #if MYGUI_IS_NATIVE_WCHAR_T
00797 
00798         size_type rfind( wchar_t ch, size_type index = 0 ) const;
00799 #endif
00800 
00801         size_type rfind( unicode_char ch, size_type index = 0 ) const;
00803 
00805 
00807 
00808 
00809         size_type find_first_of( const UString &str, size_type index = 0, size_type num = npos ) const;
00811         size_type find_first_of( code_point ch, size_type index = 0 ) const;
00813         size_type find_first_of( char ch, size_type index = 0 ) const;
00814 #if MYGUI_IS_NATIVE_WCHAR_T
00815 
00816         size_type find_first_of( wchar_t ch, size_type index = 0 ) const;
00817 #endif
00818 
00819         size_type find_first_of( unicode_char ch, size_type index = 0 ) const;
00820 
00822         size_type find_first_not_of( const UString& str, size_type index = 0, size_type num = npos ) const;
00824         size_type find_first_not_of( code_point ch, size_type index = 0 ) const;
00826         size_type find_first_not_of( char ch, size_type index = 0 ) const;
00827 #if MYGUI_IS_NATIVE_WCHAR_T
00828 
00829         size_type find_first_not_of( wchar_t ch, size_type index = 0 ) const;
00830 #endif
00831 
00832         size_type find_first_not_of( unicode_char ch, size_type index = 0 ) const;
00833 
00835         size_type find_last_of( const UString& str, size_type index = npos, size_type num = npos ) const;
00837         size_type find_last_of( code_point ch, size_type index = npos ) const;
00839         size_type find_last_of( char ch, size_type index = npos ) const {
00840             return find_last_of( static_cast<code_point>( ch ), index );
00841         }
00842 #if MYGUI_IS_NATIVE_WCHAR_T
00843 
00844         size_type find_last_of( wchar_t ch, size_type index = npos ) const;
00845 #endif
00846 
00847         size_type find_last_of( unicode_char ch, size_type index = npos ) const;
00848 
00850         size_type find_last_not_of( const UString& str, size_type index = npos, size_type num = npos ) const;
00852         size_type find_last_not_of( code_point ch, size_type index = npos ) const;
00854         size_type find_last_not_of( char ch, size_type index = npos ) const;
00855 #if MYGUI_IS_NATIVE_WCHAR_T
00856 
00857         size_type find_last_not_of( wchar_t ch, size_type index = npos ) const;
00858 #endif
00859 
00860         size_type find_last_not_of( unicode_char ch, size_type index = npos ) const;
00862 
00864 
00866 
00867 
00868         bool operator<( const UString& right ) const;
00870         bool operator<=( const UString& right ) const;
00872         bool operator>( const UString& right ) const;
00874         bool operator>=( const UString& right ) const;
00876         bool operator==( const UString& right ) const;
00878         bool operator!=( const UString& right ) const;
00880         UString& operator=( const UString& s );
00882         UString& operator=( code_point ch );
00884         UString& operator=( char ch );
00885 #if MYGUI_IS_NATIVE_WCHAR_T
00886 
00887         UString& operator=( wchar_t ch );
00888 #endif
00889 
00890         UString& operator=( unicode_char ch );
00892         code_point& operator[]( size_type index );
00894         const code_point& operator[]( size_type index ) const;
00896 
00898 
00900 
00901 
00902         operator std::string() const;
00904         operator std::wstring() const;
00906 
00908 
00910 
00911 
00912         static bool _utf16_independent_char( code_point cp );
00914         static bool _utf16_surrogate_lead( code_point cp );
00916         static bool _utf16_surrogate_follow( code_point cp );
00918         static size_t _utf16_char_length( code_point cp );
00920         static size_t _utf16_char_length( unicode_char uc );
00922 
00926         static size_t _utf16_to_utf32( const code_point in_cp[2], unicode_char& out_uc );
00928 
00933         static size_t _utf32_to_utf16( const unicode_char& in_uc, code_point out_cp[2] );
00935 
00937 
00939 
00940 
00941         static bool _utf8_start_char( unsigned char cp );
00943         static size_t _utf8_char_length( unsigned char cp );
00945         static size_t _utf8_char_length( unicode_char uc );
00946 
00948         static size_t _utf8_to_utf32( const unsigned char in_cp[6], unicode_char& out_uc );
00950         static size_t _utf32_to_utf8( const unicode_char& in_uc, unsigned char out_cp[6] );
00951 
00953         static size_type _verifyUTF8( const unsigned char* c_str );
00955         static size_type _verifyUTF8( const std::string& str );
00957 
00958     private:
00959         //template<class ITER_TYPE> friend class _iterator;
00960         dstring mData;
00961 
00963         enum BufferType {
00964             bt_none,
00965             bt_string,
00966             bt_wstring,
00967             bt_utf32string
00968         };
00969 
00971         void _init();
00972 
00974         // Scratch buffer
00976         void _cleanBuffer() const;
00977 
00979         void _getBufferStr() const;
00981         void _getBufferWStr() const;
00983         void _getBufferUTF32Str() const;
00984 
00985         void _load_buffer_UTF8() const;
00986         void _load_buffer_WStr() const;
00987         void _load_buffer_UTF32() const;
00988 
00989         mutable BufferType m_bufferType; // identifies the data type held in m_buffer
00990         mutable size_t m_bufferSize; // size of the CString buffer
00991 
00992         // multi-purpose buffer used everywhere we need a throw-away buffer
00993         union {
00994             mutable void* mVoidBuffer;
00995             mutable std::string* mStrBuffer;
00996             mutable std::wstring* mWStrBuffer;
00997             mutable utf32string* mUTF32StrBuffer;
00998         }
00999         m_buffer;
01000     };
01001 
01003     inline UString operator+( const UString& s1, const UString& s2 ) {
01004         return UString( s1 ).append( s2 );
01005     }
01007     inline UString operator+( const UString& s1, UString::code_point c ) {
01008         return UString( s1 ).append( 1, c );
01009     }
01011     inline UString operator+( const UString& s1, UString::unicode_char c ) {
01012         return UString( s1 ).append( 1, c );
01013     }
01015     inline UString operator+( const UString& s1, char c ) {
01016         return UString( s1 ).append( 1, c );
01017     }
01018 #if MYGUI_IS_NATIVE_WCHAR_T
01019 
01020     inline UString operator+( const UString& s1, wchar_t c ) {
01021         return UString( s1 ).append( 1, c );
01022     }
01023 #endif
01024 
01025     inline UString operator+( UString::code_point c, const UString& s2 ) {
01026         return UString().append( 1, c ).append( s2 );
01027     }
01029     inline UString operator+( UString::unicode_char c, const UString& s2 ) {
01030         return UString().append( 1, c ).append( s2 );
01031     }
01033     inline UString operator+( char c, const UString& s2 ) {
01034         return UString().append( 1, c ).append( s2 );
01035     }
01036 #if MYGUI_IS_NATIVE_WCHAR_T
01037 
01038     inline UString operator+( wchar_t c, const UString& s2 ) {
01039         return UString().append( 1, c ).append( s2 );
01040     }
01041 #endif
01042 
01043     // (const) forward iterator common operators
01044     inline UString::size_type operator-( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
01045         return ( left.mIter - right.mIter );
01046     }
01047     inline bool operator==( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
01048         return left.mIter == right.mIter;
01049     }
01050     inline bool operator!=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
01051         return left.mIter != right.mIter;
01052     }
01053     inline bool operator<( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
01054         return left.mIter < right.mIter;
01055     }
01056     inline bool operator<=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
01057         return left.mIter <= right.mIter;
01058     }
01059     inline bool operator>( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
01060         return left.mIter > right.mIter;
01061     }
01062     inline bool operator>=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
01063         return left.mIter >= right.mIter;
01064     }
01065 
01066     // (const) reverse iterator common operators
01067     // NB: many of these operations are evaluated in reverse because this is a reverse iterator wrapping a forward iterator
01068     inline UString::size_type operator-( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
01069         return ( right.mIter - left.mIter );
01070     }
01071     inline bool operator==( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
01072         return left.mIter == right.mIter;
01073     }
01074     inline bool operator!=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
01075         return left.mIter != right.mIter;
01076     }
01077     inline bool operator<( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
01078         return right.mIter < left.mIter;
01079     }
01080     inline bool operator<=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
01081         return right.mIter <= left.mIter;
01082     }
01083     inline bool operator>( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
01084         return right.mIter > left.mIter;
01085     }
01086     inline bool operator>=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
01087         return right.mIter >= left.mIter;
01088     }
01089 
01091     inline std::ostream& operator << ( std::ostream& os, const UString& s ) {
01092         return os << s.asUTF8();
01093     }
01094 
01096     inline std::wostream& operator << ( std::wostream& os, const UString& s ) {
01097         return os << s.asWStr();
01098     }
01099 
01100 } // namespace MyGUI
01101 
01102 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
01103 #   pragma warning (pop)
01104 #endif
01105 
01106 #endif  // __MYGUI_U_STRING_H__