MyGUI: MyGUI_UString.h Source File

MyGUI 3.2.2

MyGUI_UString.h
Go to the documentation of this file.
1 // Modified from OpenGUI under lenient license
2 // Original copyright details and licensing below:
3 // OpenGUI (http://opengui.sourceforge.net)
4 // This source code is released under the BSD License
5
6 // Permission is given to the MyGUI project to use the contents of file within its
7 // source and binary applications, as well as any derivative works, in accordance
8 // with the terms of any license under which MyGUI is or will be distributed.
9 //
10 // MyGUI may relicense its copy of this file, as well as any OpenGUI released updates
11 // to this file, under any terms that it deems fit, and is not required to maintain
12 // the original BSD licensing terms of this file, however OpenGUI retains the right
13 // to present its copy of this file under the terms of any license under which
14 // OpenGUI is distributed.
15 //
16 // MyGUI is not required to release to OpenGUI any future changes that it makes to
17 // this file, and understands and agrees that any such changes that are released
18 // back to OpenGUI will become available under the terms of any license under which
19 // OpenGUI is distributed.
20 //
21 // For brevity, this permission text may be removed from this file if desired.
22 // The original record kept within the SourceForge (http://sourceforge.net/) tracker
23 // is sufficient.
24 //
25 // - Eric Shorkey (zero/zeroskill) <opengui@rightbracket.com> [January 20th, 2007]
26
27 #ifndef MYGUI_U_STRING_H_
28 #define MYGUI_U_STRING_H_
29
30
31 #include "MyGUI_Prerequest.h"
32 #include "MyGUI_Types.h"
33
34 // these are explained later
35 #include <iterator>
36 #include <string>
37 #include <stdexcept>
38
39 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
40 // disable: warning C4275: non dll-interface class '***' used as base for dll-interface clas '***'
41 # pragma warning (push)
42 # pragma warning (disable : 4275)
43 #endif
44
45 // Workaround for VC7:
46 // when build with /MD or /MDd, VC7 have both std::basic_string<unsigned short> and
47 // basic_string<__wchar_t> instantiated in msvcprt[d].lib/MSVCP71[D].dll, but the header
48 // files tells compiler that only one of them is over there (based on /Zc:wchar_t compile
49 // option). And since this file used both of them, causing compiler instantiating another
50 // one in user object code, which lead to duplicate symbols with msvcprt.lib/MSVCP71[D].dll.
51 //
52 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && (1300 <= MYGUI_COMP_VER && MYGUI_COMP_VER <= 1310)
53
54 # if defined(_DLL_CPPLIB)
55
56 namespace std
57 {
58 template class _CRTIMP2 basic_string<unsigned short, char_traits<unsigned short>,
59 allocator<unsigned short> >;
60
61 template class _CRTIMP2 basic_string<__wchar_t, char_traits<__wchar_t>,
62 allocator<__wchar_t> >;
63 }
64
65 # endif // defined(_DLL_CPPLIB)
66
67 #endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER == 1300
68
69
70 namespace MyGUI
71 {
72
73 /* READ THIS NOTICE BEFORE USING IN YOUR OWN APPLICATIONS
74 =NOTICE=
75 This class is not a complete Unicode solution. It purposefully does not
76 provide certain functionality, such as proper lexical sorting for
77 Unicode values. It does provide comparison operators for the sole purpose
78 of using UString as an index with std::map and other operator< sorted
79 containers, but it should NOT be relied upon for meaningful lexical
80 operations, such as alphabetical sorts. If you need this type of
81 functionality, look into using ICU instead (http://icu.sourceforge.net/).
82
83 =REQUIREMENTS=
84 There are a few requirements for proper operation. They are fairly small,
85 and shouldn't restrict usage on any reasonable target.
86 * Compiler must support unsigned 16-bit integer types
87 * Compiler must support signed 32-bit integer types
88 * wchar_t must be either UTF-16 or UTF-32 encoding, and specified as such
89 using the WCHAR_UTF16 macro as outlined below.
90 * You must include <iterator>, <string>, and <wchar>. Probably more, but
91 these are the most obvious.
92
93 =REQUIRED PREPROCESSOR MACROS=
94 This class requires two preprocessor macros to be defined in order to
95 work as advertised.
96 INT32 - must be mapped to a signed 32 bit integer (ex. #define INT32 int)
97 UINT16 - must be mapped to an unsigned 16 bit integer (ex. #define UINT32 unsigned short)
98
99 Additionally, a third macro should be defined to control the evaluation of wchar_t:
100 WCHAR_UTF16 - should be defined when wchar_t represents UTF-16 code points,
101 such as in Windows. Otherwise it is assumed that wchar_t is a 32-bit
102 integer representing UTF-32 code points.
103 */
104
105 // THIS IS A VERY BRIEF AUTO DETECTION. YOU MAY NEED TO TWEAK THIS
106 #ifdef __STDC_ISO_10646__
107 // for any compiler that provides this, wchar_t is guaranteed to hold any Unicode value with a single code point (32-bit or larger)
108 // so we can safely skip the rest of the testing
109 #else // #ifdef __STDC_ISO_10646__
110 #if defined( __WIN32__ ) || defined( _WIN32 )
111 #define WCHAR_UTF16 // All currently known Windows platforms utilize UTF-16 encoding in wchar_t
112 #else // #if defined( __WIN32__ ) || defined( _WIN32 )
113 #if MYGUI_COMPILER != MYGUI_COMPILER_GCCE
114 #if WCHAR_MAX <= 0xFFFF // this is a last resort fall back test; WCHAR_MAX is defined in <wchar.h>
115 #define WCHAR_UTF16 // best we can tell, wchar_t is not larger than 16-bit
116 #endif // #if WCHAR_MAX <= 0xFFFF
117 #endif
118 #endif // #if defined( __WIN32__ ) || defined( _WIN32 )
119 #endif // #ifdef __STDC_ISO_10646__
120
121
122 // MYGUI_IS_NATIVE_WCHAR_T means that wchar_t isn't a typedef of
123 // uint16_t or uint32_t.
124 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
125
126 // Don't define wchar_t related functions since it'll duplicate
127 // with UString::code_point related functions when compile
128 // without /Zc:wchar_t, because in this case both of them are
129 // a typedef of uint16_t.
130 # if defined(_NATIVE_WCHAR_T_DEFINED)
131 # define MYGUI_IS_NATIVE_WCHAR_T 1
132 # else
133 # define MYGUI_IS_NATIVE_WCHAR_T 0
134 # endif
135 #else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
136
137 // Assumed wchar_t is natively for other compilers
138 # define MYGUI_IS_NATIVE_WCHAR_T 1
139
140 #endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
141
143
168 class MYGUI_EXPORT UString {
169 // constants used in UTF-8 conversions
170 static const unsigned char _lead1 = 0xC0; //110xxxxx
171 static const unsigned char _lead1_mask = 0x1F; //00011111
172 static const unsigned char _lead2 = 0xE0; //1110xxxx
173 static const unsigned char _lead2_mask = 0x0F; //00001111
174 static const unsigned char _lead3 = 0xF0; //11110xxx
175 static const unsigned char _lead3_mask = 0x07; //00000111
176 static const unsigned char _lead4 = 0xF8; //111110xx
177 static const unsigned char _lead4_mask = 0x03; //00000011
178 static const unsigned char _lead5 = 0xFC; //1111110x
179 static const unsigned char _lead5_mask = 0x01; //00000001
180 static const unsigned char _cont = 0x80; //10xxxxxx
181 static const unsigned char _cont_mask = 0x3F; //00111111
182
183 public:
185 typedef size_t size_type;
187 static const size_type npos = static_cast<size_type>(~0);
188
190 typedef uint32 unicode_char;
191
193 typedef uint16 code_point;
194
196 typedef code_point value_type;
197
198 typedef std::basic_string<code_point> dstring; // data string
199
201 typedef std::basic_string<unicode_char> utf32string;
202
204 class MYGUI_EXPORT invalid_data: public std::runtime_error { /* i don't know why the beautifier is freaking out on this line */
205 public:
207 explicit invalid_data( const std::string& _Message ): std::runtime_error( _Message ) {
208 /* The thing is, Bob, it's not that I'm lazy, it's that I just don't care. */
209 }
210 };
211
212 //#########################################################################
214 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 */
215 friend class UString;
216 protected:
217 _base_iterator();
218
219 void _seekFwd( size_type c );
220 void _seekRev( size_type c );
221 void _become( const _base_iterator& i );
222 bool _test_begin() const;
223 bool _test_end() const;
224 size_type _get_index() const;
225 void _jump_to( size_type index );
226
227 unicode_char _getCharacter() const;
228 int _setCharacter( unicode_char uc );
229
230 void _moveNext();
231 void _movePrev();
232
233 dstring::iterator mIter;
234 UString* mString;
235 };
236
237 //#########################################################################
238 // FORWARD ITERATORS
239 //#########################################################################
240 class _const_fwd_iterator; // forward declaration
241
243 class MYGUI_EXPORT _fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
244 friend class _const_fwd_iterator;
245 public:
246 _fwd_iterator();
247 _fwd_iterator( const _fwd_iterator& i );
248
250 _fwd_iterator& operator++();
252 _fwd_iterator operator++( int );
253
255 _fwd_iterator& operator--();
257 _fwd_iterator operator--( int );
258
260 _fwd_iterator operator+( difference_type n );
262 _fwd_iterator operator-( difference_type n );
263
265 _fwd_iterator& operator+=( difference_type n );
267 _fwd_iterator& operator-=( difference_type n );
268
270 value_type& operator*() const;
271
273 value_type& operator[]( difference_type n ) const;
274
276 _fwd_iterator& moveNext();
278 _fwd_iterator& movePrev();
280 unicode_char getCharacter() const;
282 int setCharacter( unicode_char uc );
283 };
284
285
286
287 //#########################################################################
289 class MYGUI_EXPORT _const_fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
290 public:
291 _const_fwd_iterator();
292 _const_fwd_iterator( const _const_fwd_iterator& i );
293 _const_fwd_iterator( const _fwd_iterator& i );
294
296 _const_fwd_iterator& operator++();
298 _const_fwd_iterator operator++( int );
299
301 _const_fwd_iterator& operator--();
303 _const_fwd_iterator operator--( int );
304
306 _const_fwd_iterator operator+( difference_type n );
308 _const_fwd_iterator operator-( difference_type n );
309
311 _const_fwd_iterator& operator+=( difference_type n );
313 _const_fwd_iterator& operator-=( difference_type n );
314
316 const value_type& operator*() const;
317
319 const value_type& operator[]( difference_type n ) const;
320
322 _const_fwd_iterator& moveNext();
324 _const_fwd_iterator& movePrev();
326 unicode_char getCharacter() const;
327
329 friend size_type operator-( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
331 friend bool operator==( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
333 friend bool operator!=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
335 friend bool operator<( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
337 friend bool operator<=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
339 friend bool operator>( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
341 friend bool operator>=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
342
343 };
344
345 //#########################################################################
346 // REVERSE ITERATORS
347 //#########################################################################
348 class _const_rev_iterator; // forward declaration
350 class MYGUI_EXPORT _rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
351 friend class _const_rev_iterator;
352 public:
353 _rev_iterator();
354 _rev_iterator( const _rev_iterator& i );
355
357 _rev_iterator& operator++();
359 _rev_iterator operator++( int );
360
362 _rev_iterator& operator--();
364 _rev_iterator operator--( int );
365
367 _rev_iterator operator+( difference_type n );
369 _rev_iterator operator-( difference_type n );
370
372 _rev_iterator& operator+=( difference_type n );
374 _rev_iterator& operator-=( difference_type n );
375
377 value_type& operator*() const;
378
380 value_type& operator[]( difference_type n ) const;
381 };
382 //#########################################################################
384 class MYGUI_EXPORT _const_rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
385 public:
386 _const_rev_iterator();
387 _const_rev_iterator( const _const_rev_iterator& i );
388 _const_rev_iterator( const _rev_iterator& i );
390 _const_rev_iterator& operator++();
392 _const_rev_iterator operator++( int );
393
395 _const_rev_iterator& operator--();
397 _const_rev_iterator operator--( int );
398
400 _const_rev_iterator operator+( difference_type n );
402 _const_rev_iterator operator-( difference_type n );
403
405 _const_rev_iterator& operator+=( difference_type n );
407 _const_rev_iterator& operator-=( difference_type n );
408
410 const value_type& operator*() const;
411
413 const value_type& operator[]( difference_type n ) const;
414
416 friend size_type operator-( const _const_rev_iterator& left, const _const_rev_iterator& right );
418 friend bool operator==( const _const_rev_iterator& left, const _const_rev_iterator& right );
420 friend bool operator!=( const _const_rev_iterator& left, const _const_rev_iterator& right );
422 friend bool operator<( const _const_rev_iterator& left, const _const_rev_iterator& right );
424 friend bool operator<=( const _const_rev_iterator& left, const _const_rev_iterator& right );
426 friend bool operator>( const _const_rev_iterator& left, const _const_rev_iterator& right );
428 friend bool operator>=( const _const_rev_iterator& left, const _const_rev_iterator& right );
429 };
430 //#########################################################################
431
432 typedef _fwd_iterator iterator;
433 typedef _rev_iterator reverse_iterator;
434 typedef _const_fwd_iterator const_iterator;
435 typedef _const_rev_iterator const_reverse_iterator;
436
437
439
440 UString();
443 UString( const UString& copy );
445 UString( size_type length, const code_point& ch );
447 UString( const code_point* str );
449 UString( const code_point* str, size_type length );
451 UString( const UString& str, size_type index, size_type length );
452 #if MYGUI_IS_NATIVE_WCHAR_T
453 UString( const wchar_t* w_str );
456 UString( const wchar_t* w_str, size_type length );
457 #endif
458 UString( const std::wstring& wstr );
461 UString( const char* c_str );
463 UString( const char* c_str, size_type length );
465 UString( const std::string& str );
466
468 ~UString();
470
472
474
475 size_type size() const;
478 size_type length() const;
480
481 size_type length_Characters() const;
483 size_type max_size() const;
485 void reserve( size_type size );
487 void resize( size_type num, const code_point& val = 0 );
489 void swap( UString& from );
491 bool empty() const;
493 const code_point* c_str() const;
495 const code_point* data() const;
497 size_type capacity() const;
499 void clear();
501
502 UString substr( size_type index, size_type num = npos ) const;
504 void push_back( unicode_char val );
505 #if MYGUI_IS_NATIVE_WCHAR_T
506 void push_back( wchar_t val );
508 #endif
509
512 void push_back( code_point val );
514
515 void push_back( char val );
517 bool inString( unicode_char ch ) const;
519
521
523
524 const std::string& asUTF8() const;
527 const char* asUTF8_c_str() const;
529 const utf32string& asUTF32() const;
531 const unicode_char* asUTF32_c_str() const;
533 const std::wstring& asWStr() const;
535 const wchar_t* asWStr_c_str() const;
537
539
541
542 code_point& at( size_type loc );
545 const code_point& at( size_type loc ) const;
547
551 unicode_char getChar( size_type loc ) const;
553
561 int setChar( size_type loc, unicode_char ch );
563
565
567
568 iterator begin();
571 const_iterator begin() const;
573 iterator end();
575 const_iterator end() const;
577 reverse_iterator rbegin();
579 const_reverse_iterator rbegin() const;
581 reverse_iterator rend();
583 const_reverse_iterator rend() const;
585
587
589
590 UString& assign( iterator start, iterator end );
593 UString& assign( const UString& str );
595 UString& assign( const code_point* str );
597 UString& assign( const code_point* str, size_type num );
599 UString& assign( const UString& str, size_type index, size_type len );
601 UString& assign( size_type num, const code_point& ch );
603 UString& assign( const std::wstring& wstr );
604 #if MYGUI_IS_NATIVE_WCHAR_T
605 UString& assign( const wchar_t* w_str );
608 UString& assign( const wchar_t* w_str, size_type num );
609 #endif
610 UString& assign( const std::string& str );
613 UString& assign( const char* c_str );
615 UString& assign( const char* c_str, size_type num );
617
619
621
622 UString& append( const UString& str );
625 UString& append( const code_point* str );
627 UString& append( const UString& str, size_type index, size_type len );
629 UString& append( const code_point* str, size_type num );
631 UString& append( size_type num, code_point ch );
633 UString& append( iterator start, iterator end );
634 #if MYGUI_IS_NATIVE_WCHAR_T
635 UString& append( const wchar_t* w_str, size_type num );
638 UString& append( size_type num, wchar_t ch );
639 #endif
640 UString& append( const char* c_str, size_type num );
643 UString& append( size_type num, char ch );
645 UString& append( size_type num, unicode_char ch );
647
649
651
652 iterator insert( iterator i, const code_point& ch );
655 UString& insert( size_type index, const UString& str );
657 UString& insert( size_type index, const code_point* str ) {
658 mData.insert( index, str );
659 return *this;
660 }
662 UString& insert( size_type index1, const UString& str, size_type index2, size_type num );
664 void insert( iterator i, iterator start, iterator end );
666 UString& insert( size_type index, const code_point* str, size_type num );
667 #if MYGUI_IS_NATIVE_WCHAR_T
668 UString& insert( size_type index, const wchar_t* w_str, size_type num );
670 #endif
671 UString& insert( size_type index, const char* c_str, size_type num );
674 UString& insert( size_type index, size_type num, code_point ch );
675 #if MYGUI_IS_NATIVE_WCHAR_T
676 UString& insert( size_type index, size_type num, wchar_t ch );
678 #endif
679 UString& insert( size_type index, size_type num, char ch );
682 UString& insert( size_type index, size_type num, unicode_char ch );
684 void insert( iterator i, size_type num, const code_point& ch );
685 #if MYGUI_IS_NATIVE_WCHAR_T
686 void insert( iterator i, size_type num, const wchar_t& ch );
688 #endif
689 void insert( iterator i, size_type num, const char& ch );
692 void insert( iterator i, size_type num, const unicode_char& ch );
694
696
698
699 iterator erase( iterator loc );
702 iterator erase( iterator start, iterator end );
704 UString& erase( size_type index = 0, size_type num = npos );
706
708
710
711 UString& replace( size_type index1, size_type num1, const UString& str );
714 UString& replace( size_type index1, size_type num1, const UString& str, size_type num2 );
716 UString& replace( size_type index1, size_type num1, const UString& str, size_type index2, size_type num2 );
718 UString& replace( iterator start, iterator end, const UString& str, size_type num = npos );
720 UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
722 UString& replace( iterator start, iterator end, size_type num, code_point ch );
724
726
728
729 int compare( const UString& str ) const;
732 int compare( const code_point* str ) const;
734 int compare( size_type index, size_type length, const UString& str ) const;
736 int compare( size_type index, size_type length, const UString& str, size_type index2, size_type length2 ) const;
738 int compare( size_type index, size_type length, const code_point* str, size_type length2 ) const;
739 #if MYGUI_IS_NATIVE_WCHAR_T
740 int compare( size_type index, size_type length, const wchar_t* w_str, size_type length2 ) const;
742 #endif
743 int compare( size_type index, size_type length, const char* c_str, size_type length2 ) const;
746
748
750
751
753 size_type find( const UString& str, size_type index = 0 ) const;
755
756 size_type find( const code_point* cp_str, size_type index, size_type length ) const;
758
759 size_type find( const char* c_str, size_type index, size_type length ) const;
760 #if MYGUI_IS_NATIVE_WCHAR_T
761
763 size_type find( const wchar_t* w_str, size_type index, size_type length ) const;
764 #endif
765
767 size_type find( char ch, size_type index = 0 ) const;
769
770 size_type find( code_point ch, size_type index = 0 ) const;
771 #if MYGUI_IS_NATIVE_WCHAR_T
772
774 size_type find( wchar_t ch, size_type index = 0 ) const;
775 #endif
776
778 size_type find( unicode_char ch, size_type index = 0 ) const;
779
781 size_type rfind( const UString& str, size_type index = 0 ) const;
783 size_type rfind( const code_point* cp_str, size_type index, size_type num ) const;
785 size_type rfind( const char* c_str, size_type index, size_type num ) const;
786 #if MYGUI_IS_NATIVE_WCHAR_T
787 size_type rfind( const wchar_t* w_str, size_type index, size_type num ) const;
789 #endif
790 size_type rfind( char ch, size_type index = 0 ) const;
793 size_type rfind( code_point ch, size_type index ) const;
794 #if MYGUI_IS_NATIVE_WCHAR_T
795 size_type rfind( wchar_t ch, size_type index = 0 ) const;
797 #endif
798 size_type rfind( unicode_char ch, size_type index = 0 ) const;
801
803
805
806 size_type find_first_of( const UString &str, size_type index = 0, size_type num = npos ) const;
809 size_type find_first_of( code_point ch, size_type index = 0 ) const;
811 size_type find_first_of( char ch, size_type index = 0 ) const;
812 #if MYGUI_IS_NATIVE_WCHAR_T
813 size_type find_first_of( wchar_t ch, size_type index = 0 ) const;
815 #endif
816 size_type find_first_of( unicode_char ch, size_type index = 0 ) const;
818
820 size_type find_first_not_of( const UString& str, size_type index = 0, size_type num = npos ) const;
822 size_type find_first_not_of( code_point ch, size_type index = 0 ) const;
824 size_type find_first_not_of( char ch, size_type index = 0 ) const;
825 #if MYGUI_IS_NATIVE_WCHAR_T
826 size_type find_first_not_of( wchar_t ch, size_type index = 0 ) const;
828 #endif
829 size_type find_first_not_of( unicode_char ch, size_type index = 0 ) const;
831
833 size_type find_last_of( const UString& str, size_type index = npos, size_type num = npos ) const;
835 size_type find_last_of( code_point ch, size_type index = npos ) const;
837 size_type find_last_of( char ch, size_type index = npos ) const {
838 return find_last_of( static_cast<code_point>( ch ), index );
839 }
840 #if MYGUI_IS_NATIVE_WCHAR_T
841 size_type find_last_of( wchar_t ch, size_type index = npos ) const;
843 #endif
844 size_type find_last_of( unicode_char ch, size_type index = npos ) const;
846
848 size_type find_last_not_of( const UString& str, size_type index = npos, size_type num = npos ) const;
850 size_type find_last_not_of( code_point ch, size_type index = npos ) const;
852 size_type find_last_not_of( char ch, size_type index = npos ) const;
853 #if MYGUI_IS_NATIVE_WCHAR_T
854 size_type find_last_not_of( wchar_t ch, size_type index = npos ) const;
856 #endif
857 size_type find_last_not_of( unicode_char ch, size_type index = npos ) const;
860
862
864
865 bool operator<( const UString& right ) const;
868 bool operator<=( const UString& right ) const;
870 bool operator>( const UString& right ) const;
872 bool operator>=( const UString& right ) const;
874 bool operator==( const UString& right ) const;
876 bool operator!=( const UString& right ) const;
878 UString& operator=( const UString& s );
880 UString& operator=( code_point ch );
882 UString& operator=( char ch );
883 #if MYGUI_IS_NATIVE_WCHAR_T
884 UString& operator=( wchar_t ch );
886 #endif
887 UString& operator=( unicode_char ch );
890 code_point& operator[]( size_type index );
892 const code_point& operator[]( size_type index ) const;
894
896
898
899 operator std::string() const;
902 operator std::wstring() const;
904
906
908
909 static bool _utf16_independent_char( code_point cp );
912 static bool _utf16_surrogate_lead( code_point cp );
914 static bool _utf16_surrogate_follow( code_point cp );
916 static size_t _utf16_char_length( code_point cp );
918 static size_t _utf16_char_length( unicode_char uc );
920
924 static size_t _utf16_to_utf32( const code_point in_cp[2], unicode_char& out_uc );
926
931 static size_t _utf32_to_utf16( const unicode_char& in_uc, code_point out_cp[2] );
933
935
937
938 static bool _utf8_start_char( unsigned char cp );
941 static size_t _utf8_char_length( unsigned char cp );
943 static size_t _utf8_char_length( unicode_char uc );
944
946 static size_t _utf8_to_utf32( const unsigned char in_cp[6], unicode_char& out_uc );
948 static size_t _utf32_to_utf8( const unicode_char& in_uc, unsigned char out_cp[6] );
949
951 static size_type _verifyUTF8( const unsigned char* c_str );
953 static size_type _verifyUTF8( const std::string& str );
955
956 private:
957 //template<class ITER_TYPE> friend class _iterator;
958 dstring mData;
959
961 enum BufferType {
962 bt_none,
963 bt_string,
964 bt_wstring,
965 bt_utf32string
966 };
967
969 void _init();
970
972 // Scratch buffer
974 void _cleanBuffer() const;
975
977 void _getBufferStr() const;
979 void _getBufferWStr() const;
981 void _getBufferUTF32Str() const;
982
983 void _load_buffer_UTF8() const;
984 void _load_buffer_WStr() const;
985 void _load_buffer_UTF32() const;
986
987 mutable BufferType m_bufferType; // identifies the data type held in m_buffer
988 mutable size_t m_bufferSize; // size of the CString buffer
989
990 // multi-purpose buffer used everywhere we need a throw-away buffer
991 union {
992 mutable void* mVoidBuffer;
993 mutable std::string* mStrBuffer;
994 mutable std::wstring* mWStrBuffer;
995 mutable utf32string* mUTF32StrBuffer;
996 }
997 m_buffer;
998 };
999
1001 inline UString operator+( const UString& s1, const UString& s2 ) {
1002 return UString( s1 ).append( s2 );
1003 }
1005 inline UString operator+( const UString& s1, UString::code_point c ) {
1006 return UString( s1 ).append( 1, c );
1007 }
1009 inline UString operator+( const UString& s1, UString::unicode_char c ) {
1010 return UString( s1 ).append( 1, c );
1011 }
1013 inline UString operator+( const UString& s1, char c ) {
1014 return UString( s1 ).append( 1, c );
1015 }
1016 #if MYGUI_IS_NATIVE_WCHAR_T
1017 inline UString operator+( const UString& s1, wchar_t c ) {
1019 return UString( s1 ).append( 1, c );
1020 }
1021 #endif
1022 inline UString operator+( UString::code_point c, const UString& s2 ) {
1024 return UString().append( 1, c ).append( s2 );
1025 }
1027 inline UString operator+( UString::unicode_char c, const UString& s2 ) {
1028 return UString().append( 1, c ).append( s2 );
1029 }
1031 inline UString operator+( char c, const UString& s2 ) {
1032 return UString().append( 1, c ).append( s2 );
1033 }
1034 #if MYGUI_IS_NATIVE_WCHAR_T
1035 inline UString operator+( wchar_t c, const UString& s2 ) {
1037 return UString().append( 1, c ).append( s2 );
1038 }
1039 #endif
1040
1041 // (const) forward iterator common operators
1042 inline UString::size_type operator-( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1043 return ( left.mIter - right.mIter );
1044 }
1045 inline bool operator==( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1046 return left.mIter == right.mIter;
1047 }
1048 inline bool operator!=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1049 return left.mIter != right.mIter;
1050 }
1051 inline bool operator<( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1052 return left.mIter < right.mIter;
1053 }
1054 inline bool operator<=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1055 return left.mIter <= right.mIter;
1056 }
1057 inline bool operator>( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1058 return left.mIter > right.mIter;
1059 }
1060 inline bool operator>=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1061 return left.mIter >= right.mIter;
1062 }
1063
1064 // (const) reverse iterator common operators
1065 // NB: many of these operations are evaluated in reverse because this is a reverse iterator wrapping a forward iterator
1066 inline UString::size_type operator-( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1067 return ( right.mIter - left.mIter );
1068 }
1069 inline bool operator==( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1070 return left.mIter == right.mIter;
1071 }
1072 inline bool operator!=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1073 return left.mIter != right.mIter;
1074 }
1075 inline bool operator<( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1076 return right.mIter < left.mIter;
1077 }
1078 inline bool operator<=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1079 return right.mIter <= left.mIter;
1080 }
1081 inline bool operator>( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1082 return right.mIter > left.mIter;
1083 }
1084 inline bool operator>=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1085 return right.mIter >= left.mIter;
1086 }
1087
1089 inline std::ostream& operator << ( std::ostream& os, const UString& s ) {
1090 return os << s.asUTF8();
1091 }
1092
1094 inline std::wostream& operator << ( std::wostream& os, const UString& s ) {
1095 return os << s.asWStr();
1096 }
1097
1098 } // namespace MyGUI
1099
1100 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1101 # pragma warning (pop)
1102 #endif
1103
1104 #endif // __MYGUI_U_STRING_H__
MyGUI::uint16
unsigned short uint16
Definition: MyGUI_Types.h:47
MyGUI::UString::invalid_data
This exception is used when invalid data streams are encountered.
Definition: MyGUI_UString.h:204
MyGUI::UString::_base_iterator::mString
UString * mString
Definition: MyGUI_UString.h:234
MyGUI::UString::dstring
std::basic_string< code_point > dstring
Definition: MyGUI_UString.h:198
MyGUI::UString::find_last_of
size_type find_last_of(char ch, size_type index=npos) const
returns the index of the first occurrence of ch in the current string, doing a reverse search from in...
Definition: MyGUI_UString.h:837
MyGUI::UString::operator+
UString operator+(UString::unicode_char c, const UString &s2)
string addition operator
Definition: MyGUI_UString.h:1027
MyGUI::len
float len(float x, float y)
Definition: MyGUI_PolygonalSkin.cpp:35
MyGUI::UString::operator+
UString operator+(const UString &s1, UString::code_point c)
string addition operator
Definition: MyGUI_UString.h:1005
MyGUI::UString::operator+
UString operator+(const UString &s1, const UString &s2)
string addition operator
Definition: MyGUI_UString.h:1001
MyGUI::UString::_base_iterator::mIter
dstring::iterator mIter
Definition: MyGUI_UString.h:233
MyGUI::UString::_rev_iterator
forward iterator for UString
Definition: MyGUI_UString.h:350
MyGUI::UString::mUTF32StrBuffer
utf32string * mUTF32StrBuffer
Definition: MyGUI_UString.h:995
MyGUI::UString::operator+
UString operator+(const UString &s1, UString::unicode_char c)
string addition operator
Definition: MyGUI_UString.h:1009
MyGUI::UString::_base_iterator
base iterator class for UString
Definition: MyGUI_UString.h:214
MyGUI::UString::code_point
uint16 code_point
a single UTF-16 code point
Definition: MyGUI_UString.h:193
MyGUI::UString::append
UString & append(const UString &str)
appends str on to the end of the current string
Definition: MyGUI_UString.cpp:974
MyGUI::UString::size_type
size_t size_type
size type used to indicate string size and character positions within the string
Definition: MyGUI_UString.h:185
MyGUI::UString::mVoidBuffer
void * mVoidBuffer
Definition: MyGUI_UString.h:992
MyGUI::UString::reverse_iterator
_rev_iterator reverse_iterator
reverse iterator
Definition: MyGUI_UString.h:433
MyGUI::UString::const_iterator
_const_fwd_iterator const_iterator
const iterator
Definition: MyGUI_UString.h:434
MyGUI::operator>=
bool operator>=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1060
MyGUI::uint32
unsigned int uint32
Definition: MyGUI_Types.h:48
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:168
MyGUI::UString::const_reverse_iterator
_const_rev_iterator const_reverse_iterator
const reverse iterator
Definition: MyGUI_UString.h:435
MyGUI::UString::utf32string
std::basic_string< unicode_char > utf32string
string type used for returning UTF-32 formatted data
Definition: MyGUI_UString.h:201
MyGUI::operator!=
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1048
MyGUI::UString::_const_fwd_iterator
const forward iterator for UString
Definition: MyGUI_UString.h:289
MyGUI::UString::iterator
_fwd_iterator iterator
iterator
Definition: MyGUI_UString.h:432
MyGUI::UString::asUTF8
const std::string & asUTF8() const
returns the current string in UTF-8 form within a std::string
Definition: MyGUI_UString.cpp:697
MyGUI::UString::operator+
UString operator+(const UString &s1, char c)
string addition operator
Definition: MyGUI_UString.h:1013
MyGUI::UString::_fwd_iterator
forward iterator for UString
Definition: MyGUI_UString.h:243
MyGUI::UString::value_type
code_point value_type
value type typedef for use in iterators
Definition: MyGUI_UString.h:196
MyGUI_Prerequest.h
MyGUI::operator<
bool operator<(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1051
MyGUI::operator-
UString::size_type operator-(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1042
MyGUI::UString::operator+
UString operator+(char c, const UString &s2)
string addition operator
Definition: MyGUI_UString.h:1031
MyGUI::UString::mStrBuffer
std::string * mStrBuffer
Definition: MyGUI_UString.h:993
MyGUI::operator<=
bool operator<=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1054
MyGUI::UString::insert
UString & insert(size_type index, const code_point *str)
inserts str into the current string, at location index
Definition: MyGUI_UString.h:657
MyGUI::UString::mWStrBuffer
std::wstring * mWStrBuffer
Definition: MyGUI_UString.h:994
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103
MyGUI_Types.h
MyGUI::UString::unicode_char
uint32 unicode_char
a single 32-bit Unicode character
Definition: MyGUI_UString.h:190
MyGUI::UString::asWStr
const std::wstring & asWStr() const
returns the current string in the native form of std::wstring
Definition: MyGUI_UString.cpp:721
MyGUI::UString::invalid_data::invalid_data
invalid_data(const std::string &_Message)
constructor takes a string message that can be later retrieved by the what() function
Definition: MyGUI_UString.h:207
MyGUI::operator>
bool operator>(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1057
MyGUI::UString::_const_rev_iterator
const reverse iterator for UString
Definition: MyGUI_UString.h:384
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::UString::insert
iterator insert(iterator i, const code_point &ch)
inserts ch before the code point denoted by i
Definition: MyGUI_UString.cpp:1051
MyGUI::operator==
bool operator==(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1045