MyGUI 3.4.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#if __cplusplus >= 201703L
38#include <string_view>
39#endif
40#include <stdexcept>
41
42namespace MyGUI
43{
44
45 /* READ THIS NOTICE BEFORE USING IN YOUR OWN APPLICATIONS
46 =NOTICE=
47 This class is not a complete Unicode solution. It purposefully does not
48 provide certain functionality, such as proper lexical sorting for
49 Unicode values. It does provide comparison operators for the sole purpose
50 of using UString as an index with std::map and other operator< sorted
51 containers, but it should NOT be relied upon for meaningful lexical
52 operations, such as alphabetical sorts. If you need this type of
53 functionality, look into using ICU instead (http://icu.sourceforge.net/).
54
55 =REQUIREMENTS=
56 There are a few requirements for proper operation. They are fairly small,
57 and shouldn't restrict usage on any reasonable target.
58 * Compiler must support unsigned 16-bit integer types
59 * Compiler must support signed 32-bit integer types
60 * wchar_t must be either UTF-16 or UTF-32 encoding, and specified as such
61 using the WCHAR_UTF16 macro as outlined below.
62 * You must include <iterator>, <string>, and <wchar>. Probably more, but
63 these are the most obvious.
64
65 =REQUIRED PREPROCESSOR MACROS=
66 This class requires two preprocessor macros to be defined in order to
67 work as advertised.
68 INT32 - must be mapped to a signed 32 bit integer (ex. #define INT32 int)
69 UINT16 - must be mapped to an unsigned 16 bit integer (ex. #define UINT32 unsigned short)
70
71 Additionally, a third macro should be defined to control the evaluation of wchar_t:
72 WCHAR_UTF16 - should be defined when wchar_t represents UTF-16 code points,
73 such as in Windows. Otherwise it is assumed that wchar_t is a 32-bit
74 integer representing UTF-32 code points.
75 */
76
77 // THIS IS A VERY BRIEF AUTO DETECTION. YOU MAY NEED TO TWEAK THIS
78#ifdef __STDC_ISO_10646__
79// for any compiler that provides this, wchar_t is guaranteed to hold any Unicode value with a single code point (32-bit or larger)
80// so we can safely skip the rest of the testing
81#else // #ifdef __STDC_ISO_10646__
82#if defined( __WIN32__ ) || defined( _WIN32 )
83#define WCHAR_UTF16 // All currently known Windows platforms utilize UTF-16 encoding in wchar_t
84#else // #if defined( __WIN32__ ) || defined( _WIN32 )
85#if WCHAR_MAX <= 0xFFFF // this is a last resort fall back test; WCHAR_MAX is defined in <wchar.h>
86#define WCHAR_UTF16 // best we can tell, wchar_t is not larger than 16-bit
87#endif // #if WCHAR_MAX <= 0xFFFF
88#endif // #if defined( __WIN32__ ) || defined( _WIN32 )
89#endif // #ifdef __STDC_ISO_10646__
90
91
92// MYGUI_IS_NATIVE_WCHAR_T means that wchar_t isn't a typedef of
93// uint16_t or uint32_t.
94#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
95
96// Don't define wchar_t related functions since it'll duplicate
97// with UString::code_point related functions when compile
98// without /Zc:wchar_t, because in this case both of them are
99// a typedef of uint16_t.
100# if defined(_NATIVE_WCHAR_T_DEFINED)
101# define MYGUI_IS_NATIVE_WCHAR_T 1
102# else
103# define MYGUI_IS_NATIVE_WCHAR_T 0
104# endif
105#else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
106
107// Assumed wchar_t is natively for other compilers
108# define MYGUI_IS_NATIVE_WCHAR_T 1
109
110#endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
111
112
113#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
114 // disable: warning C4275: non dll-interface class '***' used as base for dll-interface clas '***'
115# pragma warning (push)
116# pragma warning (disable : 4275)
117#endif
118
120
146 // constants used in UTF-8 conversions
147 static const unsigned char _lead1 = 0xC0; //110xxxxx
148 static const unsigned char _lead1_mask = 0x1F; //00011111
149 static const unsigned char _lead2 = 0xE0; //1110xxxx
150 static const unsigned char _lead2_mask = 0x0F; //00001111
151 static const unsigned char _lead3 = 0xF0; //11110xxx
152 static const unsigned char _lead3_mask = 0x07; //00000111
153 static const unsigned char _lead4 = 0xF8; //111110xx
154 static const unsigned char _lead4_mask = 0x03; //00000011
155 static const unsigned char _lead5 = 0xFC; //1111110x
156 static const unsigned char _lead5_mask = 0x01; //00000001
157 static const unsigned char _cont = 0x80; //10xxxxxx
158 static const unsigned char _cont_mask = 0x3F; //00111111
159
160 public:
164 static const size_type npos = static_cast<size_type>(~0);
165
168
171
174
175 using dstring = std::basic_string<code_point>; // data string
176
178 using utf32string = std::basic_string<unicode_char>;
179
181 class MYGUI_EXPORT invalid_data: public std::runtime_error { /* i don't know why the beautifier is freaking out on this line */
182 public:
184 explicit invalid_data( const std::string& _Message ): std::runtime_error( _Message ) {
185 /* The thing is, Bob, it's not that I'm lazy, it's that I just don't care. */
186 }
187 };
188
189 //#########################################################################
192 {
193 friend class UString;
194 protected:
196
198
199 void _seekFwd( size_type c );
200 void _seekRev( size_type c );
201 void _become( const _base_iterator& i );
202 bool _test_begin() const;
203 bool _test_end() const;
204 size_type _get_index() const;
205 void _jump_to( size_type index );
206
207 unicode_char _getCharacter() const;
208 int _setCharacter( unicode_char uc );
209
210 void _moveNext();
211 void _movePrev();
212
213 dstring::iterator mIter;
215 };
216
217 //#########################################################################
218 // FORWARD ITERATORS
219 //#########################################################################
220 class _const_fwd_iterator; // forward declaration
221
224 {
226 public:
228 _fwd_iterator( const _fwd_iterator& i );
229 _fwd_iterator& operator=( const _fwd_iterator& i );
230
232 _fwd_iterator& operator++();
234 _fwd_iterator operator++( int );
235
237 _fwd_iterator& operator--();
239 _fwd_iterator operator--( int );
240
242 _fwd_iterator operator+( difference_type n );
245
247 _fwd_iterator& operator+=( difference_type n );
249 _fwd_iterator& operator-=( difference_type n );
250
252 value_type& operator*() const;
253
255 value_type& operator[]( difference_type n ) const;
256
258 _fwd_iterator& moveNext();
260 _fwd_iterator& movePrev();
262 unicode_char getCharacter() const;
264 int setCharacter( unicode_char uc );
265 };
266
267
268
269 //#########################################################################
271 class MYGUI_EXPORT _const_fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
272 public:
275 _const_fwd_iterator& operator=( const _const_fwd_iterator& i );
277
279 _const_fwd_iterator& operator++();
281 _const_fwd_iterator operator++( int );
282
284 _const_fwd_iterator& operator--();
286 _const_fwd_iterator operator--( int );
287
292
297
299 const value_type& operator*() const;
300
302 const value_type& operator[]( difference_type n ) const;
303
305 _const_fwd_iterator& moveNext();
307 _const_fwd_iterator& movePrev();
309 unicode_char getCharacter() const;
310
312 friend size_type operator-( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
314 friend bool operator==( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
316 friend bool operator!=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
318 friend bool operator<( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
320 friend bool operator<=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
322 friend bool operator>( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
324 friend bool operator>=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
325
326 };
327
328 //#########################################################################
329 // REVERSE ITERATORS
330 //#########################################################################
331 class _const_rev_iterator; // forward declaration
333 class MYGUI_EXPORT _rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
335 public:
337 _rev_iterator( const _rev_iterator& i );
338
340 _rev_iterator& operator++();
342 _rev_iterator operator++( int );
343
345 _rev_iterator& operator--();
347 _rev_iterator operator--( int );
348
350 _rev_iterator operator+( difference_type n );
353
355 _rev_iterator& operator+=( difference_type n );
357 _rev_iterator& operator-=( difference_type n );
358
360 value_type& operator*() const;
361
363 value_type& operator[]( difference_type n ) const;
364 };
365 //#########################################################################
367 class MYGUI_EXPORT _const_rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
368 public:
373 _const_rev_iterator& operator++();
375 _const_rev_iterator operator++( int );
376
378 _const_rev_iterator& operator--();
380 _const_rev_iterator operator--( int );
381
386
391
393 const value_type& operator*() const;
394
396 const value_type& operator[]( difference_type n ) const;
397
399 friend size_type operator-( const _const_rev_iterator& left, const _const_rev_iterator& right );
401 friend bool operator==( const _const_rev_iterator& left, const _const_rev_iterator& right );
403 friend bool operator!=( const _const_rev_iterator& left, const _const_rev_iterator& right );
405 friend bool operator<( const _const_rev_iterator& left, const _const_rev_iterator& right );
407 friend bool operator<=( const _const_rev_iterator& left, const _const_rev_iterator& right );
409 friend bool operator>( const _const_rev_iterator& left, const _const_rev_iterator& right );
411 friend bool operator>=( const _const_rev_iterator& left, const _const_rev_iterator& right );
412 };
413 //#########################################################################
414
419
420
422
423
424 UString();
426 UString( const UString& copy );
428 UString( size_type length, const code_point& ch );
430 UString( const code_point* str );
432 UString( const code_point* str, size_type length );
434 UString( const UString& str, size_type index, size_type length );
435#if MYGUI_IS_NATIVE_WCHAR_T
437 UString( const wchar_t* w_str );
439 UString( const wchar_t* w_str, size_type length );
440#endif
442 UString( const std::wstring& wstr );
444 UString( const char* c_str );
446 UString( const char* c_str, size_type length );
448 UString( const std::string& str );
449
450 explicit UString( const utf32string & str );
451
452 template <size_type num>
453 UString( const char(& str)[num] ) : UString( str, num ) {}
454
455#if __cplusplus >= 201703L
456 UString( std::string_view str ) : UString( str.data(), str.size() ) {}
457#endif
459 ~UString();
461
463
465
466
467 size_type size() const;
469 size_type length() const;
471
472 size_type length_Characters() const;
474 size_type max_size() const;
476 void reserve( size_type size );
478 void resize( size_type num, const code_point& val = 0 );
480 void swap( UString& from );
482 bool empty() const;
484 const code_point* c_str() const;
486 const code_point* data() const;
488 size_type capacity() const;
490 void clear();
492
493 UString substr( size_type index, size_type num = npos ) const;
495 void push_back( unicode_char val );
496#if MYGUI_IS_NATIVE_WCHAR_T
498 void push_back( wchar_t val );
499#endif
501
503 void push_back( code_point val );
505
506 void push_back( char val );
508 bool inString( unicode_char ch ) const;
510
512
514
515
516 const std::string& asUTF8() const;
518 const char* asUTF8_c_str() const;
520 const utf32string& asUTF32() const;
522 const unicode_char* asUTF32_c_str() const;
524 const std::wstring& asWStr() const;
526 const wchar_t* asWStr_c_str() const;
528
530
532
533
534 code_point& at( size_type loc );
536 const code_point& at( size_type loc ) const;
538
542 unicode_char getChar( size_type loc ) const;
544
552 int setChar( size_type loc, unicode_char ch );
554
556
558
559
560 iterator begin();
562 const_iterator begin() const;
564 iterator end();
566 const_iterator end() const;
568 reverse_iterator rbegin();
570 const_reverse_iterator rbegin() const;
572 reverse_iterator rend();
574 const_reverse_iterator rend() const;
576
578
580
581
582 UString& assign( iterator start, iterator end );
584 UString& assign( const UString& str );
586 UString& assign( const code_point* str );
588 UString& assign( const code_point* str, size_type num );
590 UString& assign( const UString& str, size_type index, size_type len );
592 UString& assign( size_type num, const code_point& ch );
594 UString& assign( const std::wstring& wstr );
595#if MYGUI_IS_NATIVE_WCHAR_T
597 UString& assign( const wchar_t* w_str );
599 UString& assign( const wchar_t* w_str, size_type num );
600#endif
602 UString& assign( const std::string& str );
603
604 UString& assign( const utf32string & str );
606 UString& assign( const char* c_str );
608 UString& assign( const char* c_str, size_type num );
610
612
614
615
616 UString& append( const UString& str );
618 UString& append( const code_point* str );
620 UString& append( const UString& str, size_type index, size_type len );
622 UString& append( const code_point* str, size_type num );
624 UString& append( size_type num, code_point ch );
626 UString& append( iterator start, iterator end );
627#if MYGUI_IS_NATIVE_WCHAR_T
629 UString& append( const wchar_t* w_str, size_type num );
632#endif
634 UString& append( const char* c_str, size_type num );
636 UString& append( size_type num, char ch );
638 UString& append( size_type num, unicode_char ch );
640
642
644
645
646 iterator insert( iterator i, const code_point& ch );
648 UString& insert( size_type index, const UString& str );
651 mData.insert( index, str );
652 return *this;
653 }
655 UString& insert( size_type index1, const UString& str, size_type index2, size_type num );
657 void insert( iterator i, iterator start, iterator end );
659 UString& insert( size_type index, const code_point* str, size_type num );
660#if MYGUI_IS_NATIVE_WCHAR_T
662 UString& insert( size_type index, const wchar_t* w_str, size_type num );
663#endif
665 UString& insert( size_type index, const char* c_str, size_type num );
667 UString& insert( size_type index, size_type num, code_point ch );
668#if MYGUI_IS_NATIVE_WCHAR_T
670 UString& insert( size_type index, size_type num, wchar_t ch );
671#endif
673 UString& insert( size_type index, size_type num, char ch );
675 UString& insert( size_type index, size_type num, unicode_char ch );
677 void insert( iterator i, size_type num, const code_point& ch );
678#if MYGUI_IS_NATIVE_WCHAR_T
680 void insert( iterator i, size_type num, const wchar_t& ch );
681#endif
683 void insert( iterator i, size_type num, const char& ch );
685 void insert( iterator i, size_type num, const unicode_char& ch );
687
689
691
692
693 iterator erase( iterator loc );
695 iterator erase( iterator start, iterator end );
697 UString& erase( size_type index = 0, size_type num = npos );
699
701
703
704
705 UString& replace( size_type index1, size_type num1, const UString& str );
711 UString& replace( iterator start, iterator end, const UString& str, size_type num = npos );
715 UString& replace( iterator start, iterator end, size_type num, code_point ch );
717
719
721
722
723 int compare( const UString& str ) const;
725 int compare( const code_point* str ) const;
727 int compare( size_type index, size_type length, const UString& str ) const;
729 int compare( size_type index, size_type length, const UString& str, size_type index2, size_type length2 ) const;
731 int compare( size_type index, size_type length, const code_point* str, size_type length2 ) const;
732#if MYGUI_IS_NATIVE_WCHAR_T
734 int compare( size_type index, size_type length, const wchar_t* w_str, size_type length2 ) const;
735#endif
737 int compare( size_type index, size_type length, const char* c_str, size_type length2 ) const;
739
741
743
744
746 size_type find( const UString& str, size_type index = 0 ) const;
748
749 size_type find( const code_point* cp_str, size_type index, size_type length ) const;
751
752 size_type find( const char* c_str, size_type index, size_type length ) const;
753#if MYGUI_IS_NATIVE_WCHAR_T
755
756 size_type find( const wchar_t* w_str, size_type index, size_type length ) const;
757#endif
759
760 size_type find( char ch, size_type index = 0 ) const;
762
763 size_type find( code_point ch, size_type index = 0 ) const;
764#if MYGUI_IS_NATIVE_WCHAR_T
766
767 size_type find( wchar_t ch, size_type index = 0 ) const;
768#endif
770
771 size_type find( unicode_char ch, size_type index = 0 ) const;
772
774 size_type rfind( const UString& str, size_type index = 0 ) const;
776 size_type rfind( const code_point* cp_str, size_type index, size_type num ) const;
778 size_type rfind( const char* c_str, size_type index, size_type num ) const;
779#if MYGUI_IS_NATIVE_WCHAR_T
781 size_type rfind( const wchar_t* w_str, size_type index, size_type num ) const;
782#endif
784 size_type rfind( char ch, size_type index = 0 ) const;
786 size_type rfind( code_point ch, size_type index ) const;
787#if MYGUI_IS_NATIVE_WCHAR_T
789 size_type rfind( wchar_t ch, size_type index = 0 ) const;
790#endif
792 size_type rfind( unicode_char ch, size_type index = 0 ) const;
794
796
798
799
800 size_type find_first_of( const UString &str, size_type index = 0, size_type num = npos ) const;
802 size_type find_first_of( code_point ch, size_type index = 0 ) const;
804 size_type find_first_of( char ch, size_type index = 0 ) const;
805#if MYGUI_IS_NATIVE_WCHAR_T
807 size_type find_first_of( wchar_t ch, size_type index = 0 ) const;
808#endif
810 size_type find_first_of( unicode_char ch, size_type index = 0 ) const;
811
813 size_type find_first_not_of( const UString& str, size_type index = 0, size_type num = npos ) const;
815 size_type find_first_not_of( code_point ch, size_type index = 0 ) const;
817 size_type find_first_not_of( char ch, size_type index = 0 ) const;
818#if MYGUI_IS_NATIVE_WCHAR_T
820 size_type find_first_not_of( wchar_t ch, size_type index = 0 ) const;
821#endif
823 size_type find_first_not_of( unicode_char ch, size_type index = 0 ) const;
824
826 size_type find_last_of( const UString& str, size_type index = npos, size_type num = npos ) const;
828 size_type find_last_of( code_point ch, size_type index = npos ) const;
830 size_type find_last_of( char ch, size_type index = npos ) const {
831 return find_last_of( static_cast<code_point>( ch ), index );
832 }
833#if MYGUI_IS_NATIVE_WCHAR_T
835 size_type find_last_of( wchar_t ch, size_type index = npos ) const;
836#endif
838 size_type find_last_of( unicode_char ch, size_type index = npos ) const;
839
841 size_type find_last_not_of( const UString& str, size_type index = npos, size_type num = npos ) const;
843 size_type find_last_not_of( code_point ch, size_type index = npos ) const;
845 size_type find_last_not_of( char ch, size_type index = npos ) const;
846#if MYGUI_IS_NATIVE_WCHAR_T
848 size_type find_last_not_of( wchar_t ch, size_type index = npos ) const;
849#endif
851 size_type find_last_not_of( unicode_char ch, size_type index = npos ) const;
853
855
857
858
859 bool operator<( const UString& right ) const;
861 bool operator<=( const UString& right ) const;
863 bool operator>( const UString& right ) const;
865 bool operator>=( const UString& right ) const;
867 bool operator==( const UString& right ) const;
869 bool operator!=( const UString& right ) const;
871 UString& operator=( const UString& s );
873 UString& operator=( code_point ch );
875 UString& operator=( char ch );
876#if MYGUI_IS_NATIVE_WCHAR_T
878 UString& operator=( wchar_t ch );
879#endif
881 UString& operator=( unicode_char ch );
883 code_point& operator[]( size_type index );
885 const code_point& operator[]( size_type index ) const;
887
889
891
892
893 operator std::string() const;
895 operator std::wstring() const;
897
899
901
902
903 static bool _utf16_independent_char( code_point cp );
905 static bool _utf16_surrogate_lead( code_point cp );
907 static bool _utf16_surrogate_follow( code_point cp );
909 static size_t _utf16_char_length( code_point cp );
911 static size_t _utf16_char_length( unicode_char uc );
913
917 static size_t _utf16_to_utf32( const code_point in_cp[2], unicode_char& out_uc );
919
924 static size_t _utf32_to_utf16( const unicode_char& in_uc, code_point out_cp[2] );
926
928
930
931
932 static bool _utf8_start_char( unsigned char cp );
934 static size_t _utf8_char_length( unsigned char cp );
936 static size_t _utf8_char_length( unicode_char uc );
937
939 static size_t _utf8_to_utf32( const unsigned char in_cp[6], unicode_char& out_uc );
941 static size_t _utf32_to_utf8( const unicode_char& in_uc, unsigned char out_cp[6] );
942
944 static size_type _verifyUTF8( const unsigned char* c_str );
946 static size_type _verifyUTF8( const std::string& str );
948 static size_type _verifyUTF8( const char* c_str, size_type num );
950
951 private:
952 //template<class ITER_TYPE> friend class _iterator;
953 dstring mData;
954
956 enum BufferType {
957 bt_none,
958 bt_string,
959 bt_wstring,
960 bt_utf32string
961 };
962
964 void _init();
965
967 // Scratch buffer
969 void _cleanBuffer() const;
970
972 void _getBufferStr() const;
974 void _getBufferWStr() const;
976 void _getBufferUTF32Str() const;
977
978 void _load_buffer_UTF8() const;
979 void _load_buffer_WStr() const;
980 void _load_buffer_UTF32() const;
981
982 mutable BufferType m_bufferType; // identifies the data type held in m_buffer
983 mutable size_t m_bufferSize; // size of the CString buffer
984
985 // multi-purpose buffer used everywhere we need a throw-away buffer
986 union {
987 mutable void* mVoidBuffer;
988 mutable std::string* mStrBuffer;
989 mutable std::wstring* mWStrBuffer;
991 }
992 m_buffer;
993 };
994
996 inline UString operator+( const UString& s1, const UString& s2 ) {
997 return UString( s1 ).append( s2 );
998 }
1001 return UString( s1 ).append( 1, c );
1002 }
1005 return UString( s1 ).append( 1, c );
1006 }
1008 inline UString operator+( const UString& s1, char c ) {
1009 return UString( s1 ).append( 1, c );
1010 }
1011#if MYGUI_IS_NATIVE_WCHAR_T
1013 inline UString operator+( const UString& s1, wchar_t c ) {
1014 return UString( s1 ).append( 1, c );
1015 }
1016#endif
1019 return UString().append( 1, c ).append( s2 );
1020 }
1023 return UString().append( 1, c ).append( s2 );
1024 }
1026 inline UString operator+( char c, const UString& s2 ) {
1027 return UString().append( 1, c ).append( s2 );
1028 }
1029#if MYGUI_IS_NATIVE_WCHAR_T
1031 inline UString operator+( wchar_t c, const UString& s2 ) {
1032 return UString().append( 1, c ).append( s2 );
1033 }
1034#endif
1035
1036 // (const) forward iterator common operators
1038 return ( left.mIter - right.mIter );
1039 }
1041 return left.mIter == right.mIter;
1042 }
1044 return left.mIter != right.mIter;
1045 }
1047 return left.mIter < right.mIter;
1048 }
1050 return left.mIter <= right.mIter;
1051 }
1053 return left.mIter > right.mIter;
1054 }
1056 return left.mIter >= right.mIter;
1057 }
1058
1059 // (const) reverse iterator common operators
1060 // NB: many of these operations are evaluated in reverse because this is a reverse iterator wrapping a forward iterator
1062 return ( right.mIter - left.mIter );
1063 }
1065 return left.mIter == right.mIter;
1066 }
1068 return left.mIter != right.mIter;
1069 }
1071 return right.mIter < left.mIter;
1072 }
1074 return right.mIter <= left.mIter;
1075 }
1077 return right.mIter > left.mIter;
1078 }
1080 return right.mIter >= left.mIter;
1081 }
1082
1084 inline std::ostream& operator << ( std::ostream& os, const UString& s ) {
1085 return os << s.asUTF8();
1086 }
1087
1089 inline std::wostream& operator << ( std::wostream& os, const UString& s ) {
1090 return os << s.asWStr();
1091 }
1092
1093#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1094# pragma warning (pop)
1095#endif
1096
1097} // namespace MyGUI
1098
1099#endif // __MYGUI_U_STRING_H__
#define MYGUI_EXPORT
base iterator class for UString
const forward iterator for UString
const reverse iterator for UString
forward iterator for UString
forward iterator for UString
This exception is used when invalid data streams are encountered.
invalid_data(const std::string &_Message)
constructor takes a string message that can be later retrieved by the what() function
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
std::string * mStrBuffer
UString operator+(UString::code_point c, const UString &s2)
string addition operator
iterator insert(iterator i, const code_point &ch)
inserts ch before the code point denoted by i
size_type find(wchar_t ch, size_type index=0) const
returns the index of the first occurrence ch within the current string, starting at index; returns US...
int compare(size_type index, size_type length, const wchar_t *w_str, size_type length2) const
compare a substring of str to a substring of the current string, where the substring of str begins at...
UString & assign(const wchar_t *w_str)
assign w_str to the current string
UString & assign(const wchar_t *w_str, size_type num)
assign the first num characters of w_str to the current string
UString & insert(size_type index, const code_point *str)
inserts str into the current string, at location index
UString operator+(const UString &s1, UString::unicode_char c)
string addition operator
std::wstring * mWStrBuffer
UString operator+(wchar_t c, const UString &s2)
string addition operator
UString & insert(size_type index, size_type num, wchar_t ch)
inserts num copies of ch into the current string, at location index
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...
size_type find_first_of(wchar_t ch, size_type index=0) const
returns the index of the first occurrence of ch in the current string, starting the search at index; ...
size_type rfind(wchar_t ch, size_type index=0) const
returns the location of the first occurrence of ch in the current string, doing a reverse search from...
std::basic_string< unicode_char > utf32string
string type used for returning UTF-32 formatted data
UString operator+(UString::unicode_char c, const UString &s2)
string addition operator
UString & append(size_type num, wchar_t ch)
appends num repetitions of ch on to the end of the current string
size_type rfind(const wchar_t *w_str, size_type index, size_type num) const
returns the location of the first occurrence of str in the current string, doing a reverse search fro...
UString operator+(const UString &s1, char c)
string addition operator
UString operator+(const UString &s1, const UString &s2)
string addition operator
size_type find_first_not_of(wchar_t ch, size_type index=0) const
returns the index of the first character within the current string that does not match ch,...
UString & insert(size_type index, const wchar_t *w_str, size_type num)
inserts num code points of str into the current string, at location index
std::basic_string< code_point > dstring
UString(const wchar_t *w_str, size_type length)
duplicate of w_str, length characters long
uint16 code_point
a single UTF-16 code point
uint32 unicode_char
a single 32-bit Unicode character
void insert(iterator i, size_type num, const wchar_t &ch)
inserts num copies of ch into the current string, before the code point denoted by i
utf32string * mUTF32StrBuffer
UString & operator=(wchar_t ch)
assignment operator
size_type find_last_of(wchar_t 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...
void push_back(wchar_t val)
appends val to the end of the string
size_type find(const wchar_t *w_str, size_type index, size_type length) const
returns the index of the first occurrence of str within the current string and within length code poi...
UString & append(const UString &str)
appends str on to the end of the current string
UString & append(const wchar_t *w_str, size_type num)
appends num characters of str on to the end of the current string
size_t size_type
size type used to indicate string size and character positions within the string
UString operator+(const UString &s1, UString::code_point c)
string addition operator
size_type find_last_not_of(wchar_t ch, size_type index=npos) const
returns the index of the last occurrence of a character that does not match ch in the current string,...
UString(const char(&str)[num])
UString operator+(const UString &s1, wchar_t c)
string addition operator
UString operator+(char c, const UString &s2)
string addition operator
UString(const wchar_t *w_str)
duplicate of nul-terminated wchar_t array
UString::size_type operator-(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator<=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator==(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator>=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator>(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
uint16_t uint16
Definition MyGUI_Types.h:47
bool operator<(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
uint32_t uint32
Definition MyGUI_Types.h:48