MyGUI  3.4.1
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 namespace MyGUI
40 {
41 
42  /* READ THIS NOTICE BEFORE USING IN YOUR OWN APPLICATIONS
43  =NOTICE=
44  This class is not a complete Unicode solution. It purposefully does not
45  provide certain functionality, such as proper lexical sorting for
46  Unicode values. It does provide comparison operators for the sole purpose
47  of using UString as an index with std::map and other operator< sorted
48  containers, but it should NOT be relied upon for meaningful lexical
49  operations, such as alphabetical sorts. If you need this type of
50  functionality, look into using ICU instead (http://icu.sourceforge.net/).
51 
52  =REQUIREMENTS=
53  There are a few requirements for proper operation. They are fairly small,
54  and shouldn't restrict usage on any reasonable target.
55  * Compiler must support unsigned 16-bit integer types
56  * Compiler must support signed 32-bit integer types
57  * wchar_t must be either UTF-16 or UTF-32 encoding, and specified as such
58  using the WCHAR_UTF16 macro as outlined below.
59  * You must include <iterator>, <string>, and <wchar>. Probably more, but
60  these are the most obvious.
61 
62  =REQUIRED PREPROCESSOR MACROS=
63  This class requires two preprocessor macros to be defined in order to
64  work as advertised.
65  INT32 - must be mapped to a signed 32 bit integer (ex. #define INT32 int)
66  UINT16 - must be mapped to an unsigned 16 bit integer (ex. #define UINT32 unsigned short)
67 
68  Additionally, a third macro should be defined to control the evaluation of wchar_t:
69  WCHAR_UTF16 - should be defined when wchar_t represents UTF-16 code points,
70  such as in Windows. Otherwise it is assumed that wchar_t is a 32-bit
71  integer representing UTF-32 code points.
72  */
73 
74  // THIS IS A VERY BRIEF AUTO DETECTION. YOU MAY NEED TO TWEAK THIS
75 #ifdef __STDC_ISO_10646__
76 // for any compiler that provides this, wchar_t is guaranteed to hold any Unicode value with a single code point (32-bit or larger)
77 // so we can safely skip the rest of the testing
78 #else // #ifdef __STDC_ISO_10646__
79 #if defined( __WIN32__ ) || defined( _WIN32 )
80 #define WCHAR_UTF16 // All currently known Windows platforms utilize UTF-16 encoding in wchar_t
81 #else // #if defined( __WIN32__ ) || defined( _WIN32 )
82 #if WCHAR_MAX <= 0xFFFF // this is a last resort fall back test; WCHAR_MAX is defined in <wchar.h>
83 #define WCHAR_UTF16 // best we can tell, wchar_t is not larger than 16-bit
84 #endif // #if WCHAR_MAX <= 0xFFFF
85 #endif // #if defined( __WIN32__ ) || defined( _WIN32 )
86 #endif // #ifdef __STDC_ISO_10646__
87 
88 
89 // MYGUI_IS_NATIVE_WCHAR_T means that wchar_t isn't a typedef of
90 // uint16_t or uint32_t.
91 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
92 
93 // Don't define wchar_t related functions since it'll duplicate
94 // with UString::code_point related functions when compile
95 // without /Zc:wchar_t, because in this case both of them are
96 // a typedef of uint16_t.
97 # if defined(_NATIVE_WCHAR_T_DEFINED)
98 # define MYGUI_IS_NATIVE_WCHAR_T 1
99 # else
100 # define MYGUI_IS_NATIVE_WCHAR_T 0
101 # endif
102 #else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
103 
104 // Assumed wchar_t is natively for other compilers
105 # define MYGUI_IS_NATIVE_WCHAR_T 1
106 
107 #endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
108 
110 
136  // constants used in UTF-8 conversions
137  static const unsigned char _lead1 = 0xC0; //110xxxxx
138  static const unsigned char _lead1_mask = 0x1F; //00011111
139  static const unsigned char _lead2 = 0xE0; //1110xxxx
140  static const unsigned char _lead2_mask = 0x0F; //00001111
141  static const unsigned char _lead3 = 0xF0; //11110xxx
142  static const unsigned char _lead3_mask = 0x07; //00000111
143  static const unsigned char _lead4 = 0xF8; //111110xx
144  static const unsigned char _lead4_mask = 0x03; //00000011
145  static const unsigned char _lead5 = 0xFC; //1111110x
146  static const unsigned char _lead5_mask = 0x01; //00000001
147  static const unsigned char _cont = 0x80; //10xxxxxx
148  static const unsigned char _cont_mask = 0x3F; //00111111
149 
150  public:
152  using size_type = size_t;
154  static const size_type npos = static_cast<size_type>(~0);
155 
158 
161 
164 
165  using dstring = std::basic_string<code_point>; // data string
166 
168  using utf32string = std::basic_string<unicode_char>;
169 
171  class MYGUI_EXPORT invalid_data: public std::runtime_error { /* i don't know why the beautifier is freaking out on this line */
172  public:
174  explicit invalid_data( const std::string& _Message ): std::runtime_error( _Message ) {
175  /* The thing is, Bob, it's not that I'm lazy, it's that I just don't care. */
176  }
177  };
178 
179  //#########################################################################
182  {
183  friend class UString;
184  protected:
185  typedef ptrdiff_t difference_type;
186 
187  _base_iterator();
188 
189  void _seekFwd( size_type c );
190  void _seekRev( size_type c );
191  void _become( const _base_iterator& i );
192  bool _test_begin() const;
193  bool _test_end() const;
194  size_type _get_index() const;
195  void _jump_to( size_type index );
196 
197  unicode_char _getCharacter() const;
198  int _setCharacter( unicode_char uc );
199 
200  void _moveNext();
201  void _movePrev();
202 
203  dstring::iterator mIter;
205  };
206 
207  //#########################################################################
208  // FORWARD ITERATORS
209  //#########################################################################
210  class _const_fwd_iterator; // forward declaration
211 
214  {
215  friend class _const_fwd_iterator;
216  public:
218  _fwd_iterator( const _fwd_iterator& i );
219  _fwd_iterator& operator=( const _fwd_iterator& i );
220 
222  _fwd_iterator& operator++();
224  _fwd_iterator operator++( int );
225 
227  _fwd_iterator& operator--();
229  _fwd_iterator operator--( int );
230 
232  _fwd_iterator operator+( difference_type n );
235 
237  _fwd_iterator& operator+=( difference_type n );
239  _fwd_iterator& operator-=( difference_type n );
240 
242  value_type& operator*() const;
243 
245  value_type& operator[]( difference_type n ) const;
246 
248  _fwd_iterator& moveNext();
250  _fwd_iterator& movePrev();
252  unicode_char getCharacter() const;
254  int setCharacter( unicode_char uc );
255  };
256 
257 
258 
259  //#########################################################################
261  class MYGUI_EXPORT _const_fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
262  public:
265  _const_fwd_iterator& operator=( const _const_fwd_iterator& i );
267 
269  _const_fwd_iterator& operator++();
271  _const_fwd_iterator operator++( int );
272 
274  _const_fwd_iterator& operator--();
276  _const_fwd_iterator operator--( int );
277 
279  _const_fwd_iterator operator+( difference_type n );
282 
284  _const_fwd_iterator& operator+=( difference_type n );
286  _const_fwd_iterator& operator-=( difference_type n );
287 
289  const value_type& operator*() const;
290 
292  const value_type& operator[]( difference_type n ) const;
293 
295  _const_fwd_iterator& moveNext();
297  _const_fwd_iterator& movePrev();
299  unicode_char getCharacter() const;
300 
302  friend size_type operator-( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
304  friend bool operator==( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
306  friend bool operator!=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
308  friend bool operator<( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
310  friend bool operator<=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
312  friend bool 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 );
315 
316  };
317 
318  //#########################################################################
319  // REVERSE ITERATORS
320  //#########################################################################
321  class _const_rev_iterator; // forward declaration
323  class MYGUI_EXPORT _rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
324  friend class _const_rev_iterator;
325  public:
327  _rev_iterator( const _rev_iterator& i );
328 
330  _rev_iterator& operator++();
332  _rev_iterator operator++( int );
333 
335  _rev_iterator& operator--();
337  _rev_iterator operator--( int );
338 
340  _rev_iterator operator+( difference_type n );
343 
345  _rev_iterator& operator+=( difference_type n );
347  _rev_iterator& operator-=( difference_type n );
348 
350  value_type& operator*() const;
351 
353  value_type& operator[]( difference_type n ) const;
354  };
355  //#########################################################################
357  class MYGUI_EXPORT _const_rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
358  public:
363  _const_rev_iterator& operator++();
365  _const_rev_iterator operator++( int );
366 
368  _const_rev_iterator& operator--();
370  _const_rev_iterator operator--( int );
371 
373  _const_rev_iterator operator+( difference_type n );
376 
378  _const_rev_iterator& operator+=( difference_type n );
380  _const_rev_iterator& operator-=( difference_type n );
381 
383  const value_type& operator*() const;
384 
386  const value_type& operator[]( difference_type n ) const;
387 
389  friend size_type operator-( const _const_rev_iterator& left, const _const_rev_iterator& right );
391  friend bool operator==( const _const_rev_iterator& left, const _const_rev_iterator& right );
393  friend bool operator!=( const _const_rev_iterator& left, const _const_rev_iterator& right );
395  friend bool operator<( const _const_rev_iterator& left, const _const_rev_iterator& right );
397  friend bool operator<=( const _const_rev_iterator& left, const _const_rev_iterator& right );
399  friend bool 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 );
402  };
403  //#########################################################################
404 
409 
410 
412 
413  UString();
416  UString( const UString& copy );
418  UString( size_type length, const code_point& ch );
420  UString( const code_point* str );
422  UString( const code_point* str, size_type length );
424  UString( const UString& str, size_type index, size_type length );
425 #if MYGUI_IS_NATIVE_WCHAR_T
427  UString( const wchar_t* w_str );
429  UString( const wchar_t* w_str, size_type length );
430 #endif
432  UString( const std::wstring& wstr );
434  UString( const char* c_str );
436  UString( const char* c_str, size_type length );
438  UString( const std::string& str );
439 
440  explicit UString( const utf32string & str );
441 
443  ~UString();
445 
447 
449 
450  size_type size() const;
453  size_type length() const;
455 
456  size_type length_Characters() const;
458  size_type max_size() const;
460  void reserve( size_type size );
462  void resize( size_type num, const code_point& val = 0 );
464  void swap( UString& from );
466  bool empty() const;
468  const code_point* c_str() const;
470  const code_point* data() const;
472  size_type capacity() const;
474  void clear();
476 
477  UString substr( size_type index, size_type num = npos ) const;
479  void push_back( unicode_char val );
480 #if MYGUI_IS_NATIVE_WCHAR_T
482  void push_back( wchar_t val );
483 #endif
485 
487  void push_back( code_point val );
489 
490  void push_back( char val );
492  bool inString( unicode_char ch ) const;
494 
496 
498 
499  const std::string& asUTF8() const;
502  const char* asUTF8_c_str() const;
504  const utf32string& asUTF32() const;
506  const unicode_char* asUTF32_c_str() const;
508  const std::wstring& asWStr() const;
510  const wchar_t* asWStr_c_str() const;
512 
514 
516 
517  code_point& at( size_type loc );
520  const code_point& at( size_type loc ) const;
522 
526  unicode_char getChar( size_type loc ) const;
528 
536  int setChar( size_type loc, unicode_char ch );
538 
540 
542 
543  iterator begin();
546  const_iterator begin() const;
548  iterator end();
550  const_iterator end() const;
552  reverse_iterator rbegin();
554  const_reverse_iterator rbegin() const;
556  reverse_iterator rend();
558  const_reverse_iterator rend() const;
560 
562 
564 
565  UString& assign( iterator start, iterator end );
568  UString& assign( const UString& str );
570  UString& assign( const code_point* str );
572  UString& assign( const code_point* str, size_type num );
574  UString& assign( const UString& str, size_type index, size_type len );
576  UString& assign( size_type num, const code_point& ch );
578  UString& assign( const std::wstring& wstr );
579 #if MYGUI_IS_NATIVE_WCHAR_T
581  UString& assign( const wchar_t* w_str );
583  UString& assign( const wchar_t* w_str, size_type num );
584 #endif
586  UString& assign( const std::string& str );
587 
588  UString& assign( const utf32string & str );
590  UString& assign( const char* c_str );
592  UString& assign( const char* c_str, size_type num );
594 
596 
598 
599  UString& append( const UString& str );
602  UString& append( const code_point* str );
604  UString& append( const UString& str, size_type index, size_type len );
606  UString& append( const code_point* str, size_type num );
608  UString& append( size_type num, code_point ch );
610  UString& append( iterator start, iterator end );
611 #if MYGUI_IS_NATIVE_WCHAR_T
613  UString& append( const wchar_t* w_str, size_type num );
615  UString& append( size_type num, wchar_t ch );
616 #endif
618  UString& append( const char* c_str, size_type num );
620  UString& append( size_type num, char ch );
622  UString& append( size_type num, unicode_char ch );
624 
626 
628 
629  iterator insert( iterator i, const code_point& ch );
632  UString& insert( size_type index, const UString& str );
634  UString& insert( size_type index, const code_point* str ) {
635  mData.insert( index, str );
636  return *this;
637  }
639  UString& insert( size_type index1, const UString& str, size_type index2, size_type num );
641  void insert( iterator i, iterator start, iterator end );
643  UString& insert( size_type index, const code_point* str, size_type num );
644 #if MYGUI_IS_NATIVE_WCHAR_T
646  UString& insert( size_type index, const wchar_t* w_str, size_type num );
647 #endif
649  UString& insert( size_type index, const char* c_str, size_type num );
651  UString& insert( size_type index, size_type num, code_point ch );
652 #if MYGUI_IS_NATIVE_WCHAR_T
654  UString& insert( size_type index, size_type num, wchar_t ch );
655 #endif
657  UString& insert( size_type index, size_type num, char ch );
659  UString& insert( size_type index, size_type num, unicode_char ch );
661  void insert( iterator i, size_type num, const code_point& ch );
662 #if MYGUI_IS_NATIVE_WCHAR_T
664  void insert( iterator i, size_type num, const wchar_t& ch );
665 #endif
667  void insert( iterator i, size_type num, const char& ch );
669  void insert( iterator i, size_type num, const unicode_char& ch );
671 
673 
675 
676  iterator erase( iterator loc );
679  iterator erase( iterator start, iterator end );
681  UString& erase( size_type index = 0, size_type num = npos );
683 
685 
687 
688  UString& replace( size_type index1, size_type num1, const UString& str );
691  UString& replace( size_type index1, size_type num1, const UString& str, size_type num2 );
693  UString& replace( size_type index1, size_type num1, const UString& str, size_type index2, size_type num2 );
695  UString& replace( iterator start, iterator end, const UString& str, size_type num = npos );
697  UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
699  UString& replace( iterator start, iterator end, size_type num, code_point ch );
701 
703 
705 
706  int compare( const UString& str ) const;
709  int compare( const code_point* str ) const;
711  int compare( size_type index, size_type length, const UString& str ) const;
713  int compare( size_type index, size_type length, const UString& str, size_type index2, size_type length2 ) const;
715  int compare( size_type index, size_type length, const code_point* str, size_type length2 ) const;
716 #if MYGUI_IS_NATIVE_WCHAR_T
718  int compare( size_type index, size_type length, const wchar_t* w_str, size_type length2 ) const;
719 #endif
721  int compare( size_type index, size_type length, const char* c_str, size_type length2 ) const;
723 
725 
727 
728 
730  size_type find( const UString& str, size_type index = 0 ) const;
732 
733  size_type find( const code_point* cp_str, size_type index, size_type length ) const;
735 
736  size_type find( const char* c_str, size_type index, size_type length ) const;
737 #if MYGUI_IS_NATIVE_WCHAR_T
739 
740  size_type find( const wchar_t* w_str, size_type index, size_type length ) const;
741 #endif
743 
744  size_type find( char ch, size_type index = 0 ) const;
746 
747  size_type find( code_point ch, size_type index = 0 ) const;
748 #if MYGUI_IS_NATIVE_WCHAR_T
750 
751  size_type find( wchar_t ch, size_type index = 0 ) const;
752 #endif
754 
755  size_type find( unicode_char ch, size_type index = 0 ) const;
756 
758  size_type rfind( const UString& str, size_type index = 0 ) const;
760  size_type rfind( const code_point* cp_str, size_type index, size_type num ) const;
762  size_type rfind( const char* c_str, size_type index, size_type num ) const;
763 #if MYGUI_IS_NATIVE_WCHAR_T
765  size_type rfind( const wchar_t* w_str, size_type index, size_type num ) const;
766 #endif
768  size_type rfind( char ch, size_type index = 0 ) const;
770  size_type rfind( code_point ch, size_type index ) const;
771 #if MYGUI_IS_NATIVE_WCHAR_T
773  size_type rfind( wchar_t ch, size_type index = 0 ) const;
774 #endif
776  size_type rfind( unicode_char ch, size_type index = 0 ) const;
778 
780 
782 
783  size_type find_first_of( const UString &str, size_type index = 0, size_type num = npos ) const;
786  size_type find_first_of( code_point ch, size_type index = 0 ) const;
788  size_type find_first_of( char ch, size_type index = 0 ) const;
789 #if MYGUI_IS_NATIVE_WCHAR_T
791  size_type find_first_of( wchar_t ch, size_type index = 0 ) const;
792 #endif
794  size_type find_first_of( unicode_char ch, size_type index = 0 ) const;
795 
797  size_type find_first_not_of( const UString& str, size_type index = 0, size_type num = npos ) const;
799  size_type find_first_not_of( code_point ch, size_type index = 0 ) const;
801  size_type find_first_not_of( char ch, size_type index = 0 ) const;
802 #if MYGUI_IS_NATIVE_WCHAR_T
804  size_type find_first_not_of( wchar_t ch, size_type index = 0 ) const;
805 #endif
807  size_type find_first_not_of( unicode_char ch, size_type index = 0 ) const;
808 
810  size_type find_last_of( const UString& str, size_type index = npos, size_type num = npos ) const;
812  size_type find_last_of( code_point ch, size_type index = npos ) const;
814  size_type find_last_of( char ch, size_type index = npos ) const {
815  return find_last_of( static_cast<code_point>( ch ), index );
816  }
817 #if MYGUI_IS_NATIVE_WCHAR_T
819  size_type find_last_of( wchar_t ch, size_type index = npos ) const;
820 #endif
822  size_type find_last_of( unicode_char ch, size_type index = npos ) const;
823 
825  size_type find_last_not_of( const UString& str, size_type index = npos, size_type num = npos ) const;
827  size_type find_last_not_of( code_point ch, size_type index = npos ) const;
829  size_type find_last_not_of( char ch, size_type index = npos ) const;
830 #if MYGUI_IS_NATIVE_WCHAR_T
832  size_type find_last_not_of( wchar_t ch, size_type index = npos ) const;
833 #endif
835  size_type find_last_not_of( unicode_char ch, size_type index = npos ) const;
837 
839 
841 
842  bool operator<( const UString& right ) const;
845  bool operator<=( const UString& right ) const;
847  bool operator>( const UString& right ) const;
849  bool operator>=( const UString& right ) const;
851  bool operator==( const UString& right ) const;
853  bool operator!=( const UString& right ) const;
855  UString& operator=( const UString& s );
857  UString& operator=( code_point ch );
859  UString& operator=( char ch );
860 #if MYGUI_IS_NATIVE_WCHAR_T
862  UString& operator=( wchar_t ch );
863 #endif
865  UString& operator=( unicode_char ch );
867  code_point& operator[]( size_type index );
869  const code_point& operator[]( size_type index ) const;
871 
873 
875 
876  operator std::string() const;
879  operator std::wstring() const;
881 
883 
885 
886  static bool _utf16_independent_char( code_point cp );
889  static bool _utf16_surrogate_lead( code_point cp );
891  static bool _utf16_surrogate_follow( code_point cp );
893  static size_t _utf16_char_length( code_point cp );
895  static size_t _utf16_char_length( unicode_char uc );
897 
901  static size_t _utf16_to_utf32( const code_point in_cp[2], unicode_char& out_uc );
903 
908  static size_t _utf32_to_utf16( const unicode_char& in_uc, code_point out_cp[2] );
910 
912 
914 
915  static bool _utf8_start_char( unsigned char cp );
918  static size_t _utf8_char_length( unsigned char cp );
920  static size_t _utf8_char_length( unicode_char uc );
921 
923  static size_t _utf8_to_utf32( const unsigned char in_cp[6], unicode_char& out_uc );
925  static size_t _utf32_to_utf8( const unicode_char& in_uc, unsigned char out_cp[6] );
926 
928  static size_type _verifyUTF8( const unsigned char* c_str );
930  static size_type _verifyUTF8( const std::string& str );
932 
933  private:
934  //template<class ITER_TYPE> friend class _iterator;
935  dstring mData;
936 
938  enum BufferType {
939  bt_none,
940  bt_string,
941  bt_wstring,
942  bt_utf32string
943  };
944 
946  void _init();
947 
949  // Scratch buffer
951  void _cleanBuffer() const;
952 
954  void _getBufferStr() const;
956  void _getBufferWStr() const;
958  void _getBufferUTF32Str() const;
959 
960  void _load_buffer_UTF8() const;
961  void _load_buffer_WStr() const;
962  void _load_buffer_UTF32() const;
963 
964  mutable BufferType m_bufferType; // identifies the data type held in m_buffer
965  mutable size_t m_bufferSize; // size of the CString buffer
966 
967  // multi-purpose buffer used everywhere we need a throw-away buffer
968  union {
969  mutable void* mVoidBuffer;
970  mutable std::string* mStrBuffer;
971  mutable std::wstring* mWStrBuffer;
973  }
974  m_buffer;
975  };
976 
978  inline UString operator+( const UString& s1, const UString& s2 ) {
979  return UString( s1 ).append( s2 );
980  }
982  inline UString operator+( const UString& s1, UString::code_point c ) {
983  return UString( s1 ).append( 1, c );
984  }
987  return UString( s1 ).append( 1, c );
988  }
990  inline UString operator+( const UString& s1, char c ) {
991  return UString( s1 ).append( 1, c );
992  }
993 #if MYGUI_IS_NATIVE_WCHAR_T
995  inline UString operator+( const UString& s1, wchar_t c ) {
996  return UString( s1 ).append( 1, c );
997  }
998 #endif
1001  return UString().append( 1, c ).append( s2 );
1002  }
1005  return UString().append( 1, c ).append( s2 );
1006  }
1008  inline UString operator+( char c, const UString& s2 ) {
1009  return UString().append( 1, c ).append( s2 );
1010  }
1011 #if MYGUI_IS_NATIVE_WCHAR_T
1013  inline UString operator+( wchar_t c, const UString& s2 ) {
1014  return UString().append( 1, c ).append( s2 );
1015  }
1016 #endif
1017 
1018  // (const) forward iterator common operators
1020  return ( left.mIter - right.mIter );
1021  }
1022  inline bool operator==( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1023  return left.mIter == right.mIter;
1024  }
1025  inline bool operator!=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1026  return left.mIter != right.mIter;
1027  }
1028  inline bool operator<( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1029  return left.mIter < right.mIter;
1030  }
1031  inline bool operator<=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1032  return left.mIter <= right.mIter;
1033  }
1034  inline bool operator>( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1035  return left.mIter > right.mIter;
1036  }
1037  inline bool operator>=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1038  return left.mIter >= right.mIter;
1039  }
1040 
1041  // (const) reverse iterator common operators
1042  // NB: many of these operations are evaluated in reverse because this is a reverse iterator wrapping a forward iterator
1044  return ( right.mIter - left.mIter );
1045  }
1046  inline bool operator==( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1047  return left.mIter == right.mIter;
1048  }
1049  inline bool operator!=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1050  return left.mIter != right.mIter;
1051  }
1052  inline bool operator<( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1053  return right.mIter < left.mIter;
1054  }
1055  inline bool operator<=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1056  return right.mIter <= left.mIter;
1057  }
1058  inline bool operator>( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1059  return right.mIter > left.mIter;
1060  }
1061  inline bool operator>=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1062  return right.mIter >= left.mIter;
1063  }
1064 
1066  inline std::ostream& operator << ( std::ostream& os, const UString& s ) {
1067  return os << s.asUTF8();
1068  }
1069 
1071  inline std::wostream& operator << ( std::wostream& os, const UString& s ) {
1072  return os << s.asWStr();
1073  }
1074 
1075 } // namespace MyGUI
1076 
1077 #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 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
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...
code_point value_type
value type typedef for use in iterators
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
UString & assign(const wchar_t *w_str, size_type num)
assign the first num characters of w_str to the current string
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...
UString & append(size_type num, wchar_t ch)
appends num repetitions of ch on to the end of the current string
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
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,...
std::basic_string< code_point > dstring
UString(const wchar_t *w_str, size_type length)
duplicate of w_str, length characters long
UString & operator=(wchar_t ch)
assignment operator
UString & insert(size_type index, size_type num, wchar_t ch)
inserts num copies of ch into the current string, at location index
uint16 code_point
a single UTF-16 code point
UString & insert(size_type index, const code_point *str)
inserts str into the current string, at location index
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
const std::wstring & asWStr() const
returns the current string in the native form of std::wstring
utf32string * mUTF32StrBuffer
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...
UString & append(const wchar_t *w_str, size_type num)
appends num characters of str on to the end of the current string
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
size_t size_type
size type used to indicate string size and character positions within the string
UString & assign(const wchar_t *w_str)
assign w_str to the current string
const std::string & asUTF8() const
returns the current string in UTF-8 form within a std::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 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:46
float len(float x, float y)
bool operator<(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
uint32_t uint32
Definition: MyGUI_Types.h:47