MyGUI  3.4.0
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 
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  using size_type = size_t;
187  static const size_type npos = static_cast<size_type>(~0);
188 
191 
194 
197 
198  using dstring = std::basic_string<code_point>; // data string
199 
201  using utf32string = std::basic_string<unicode_char>;
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  //#########################################################################
215  {
216  friend class UString;
217  protected:
218  typedef ptrdiff_t difference_type;
219 
220  _base_iterator();
221 
222  void _seekFwd( size_type c );
223  void _seekRev( size_type c );
224  void _become( const _base_iterator& i );
225  bool _test_begin() const;
226  bool _test_end() const;
227  size_type _get_index() const;
228  void _jump_to( size_type index );
229 
230  unicode_char _getCharacter() const;
231  int _setCharacter( unicode_char uc );
232 
233  void _moveNext();
234  void _movePrev();
235 
236  dstring::iterator mIter;
238  };
239 
240  //#########################################################################
241  // FORWARD ITERATORS
242  //#########################################################################
243  class _const_fwd_iterator; // forward declaration
244 
247  {
248  friend class _const_fwd_iterator;
249  public:
251  _fwd_iterator( const _fwd_iterator& i );
252  _fwd_iterator& operator=( const _fwd_iterator& i );
253 
255  _fwd_iterator& operator++();
257  _fwd_iterator operator++( int );
258 
260  _fwd_iterator& operator--();
262  _fwd_iterator operator--( int );
263 
265  _fwd_iterator operator+( difference_type n );
268 
270  _fwd_iterator& operator+=( difference_type n );
272  _fwd_iterator& operator-=( difference_type n );
273 
275  value_type& operator*() const;
276 
278  value_type& operator[]( difference_type n ) const;
279 
281  _fwd_iterator& moveNext();
283  _fwd_iterator& movePrev();
285  unicode_char getCharacter() const;
287  int setCharacter( unicode_char uc );
288  };
289 
290 
291 
292  //#########################################################################
294  class MYGUI_EXPORT _const_fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
295  public:
298  _const_fwd_iterator& operator=( const _const_fwd_iterator& i );
300 
302  _const_fwd_iterator& operator++();
304  _const_fwd_iterator operator++( int );
305 
307  _const_fwd_iterator& operator--();
309  _const_fwd_iterator operator--( int );
310 
312  _const_fwd_iterator operator+( difference_type n );
315 
317  _const_fwd_iterator& operator+=( difference_type n );
319  _const_fwd_iterator& operator-=( difference_type n );
320 
322  const value_type& operator*() const;
323 
325  const value_type& operator[]( difference_type n ) const;
326 
328  _const_fwd_iterator& moveNext();
330  _const_fwd_iterator& movePrev();
332  unicode_char getCharacter() const;
333 
335  friend size_type 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 );
343  friend bool operator<=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
345  friend bool operator>( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
347  friend bool operator>=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
348 
349  };
350 
351  //#########################################################################
352  // REVERSE ITERATORS
353  //#########################################################################
354  class _const_rev_iterator; // forward declaration
356  class MYGUI_EXPORT _rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
357  friend class _const_rev_iterator;
358  public:
360  _rev_iterator( const _rev_iterator& i );
361 
363  _rev_iterator& operator++();
365  _rev_iterator operator++( int );
366 
368  _rev_iterator& operator--();
370  _rev_iterator operator--( int );
371 
373  _rev_iterator operator+( difference_type n );
376 
378  _rev_iterator& operator+=( difference_type n );
380  _rev_iterator& operator-=( difference_type n );
381 
383  value_type& operator*() const;
384 
386  value_type& operator[]( difference_type n ) const;
387  };
388  //#########################################################################
390  class MYGUI_EXPORT _const_rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
391  public:
396  _const_rev_iterator& operator++();
398  _const_rev_iterator operator++( int );
399 
401  _const_rev_iterator& operator--();
403  _const_rev_iterator operator--( int );
404 
406  _const_rev_iterator operator+( difference_type n );
409 
411  _const_rev_iterator& operator+=( difference_type n );
413  _const_rev_iterator& operator-=( difference_type n );
414 
416  const value_type& operator*() const;
417 
419  const value_type& operator[]( difference_type n ) const;
420 
422  friend size_type 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 );
430  friend bool operator<=( const _const_rev_iterator& left, const _const_rev_iterator& right );
432  friend bool operator>( const _const_rev_iterator& left, const _const_rev_iterator& right );
434  friend bool operator>=( const _const_rev_iterator& left, const _const_rev_iterator& right );
435  };
436  //#########################################################################
437 
442 
443 
445 
446  UString();
449  UString( const UString& copy );
451  UString( size_type length, const code_point& ch );
453  UString( const code_point* str );
455  UString( const code_point* str, size_type length );
457  UString( const UString& str, size_type index, size_type length );
458 #if MYGUI_IS_NATIVE_WCHAR_T
459  UString( const wchar_t* w_str );
462  UString( const wchar_t* w_str, size_type length );
463 #endif
464  UString( const std::wstring& wstr );
467  UString( const char* c_str );
469  UString( const char* c_str, size_type length );
471  UString( const std::string& str );
472 
474  ~UString();
476 
478 
480 
481  size_type size() const;
484  size_type length() const;
486 
487  size_type length_Characters() const;
489  size_type max_size() const;
491  void reserve( size_type size );
493  void resize( size_type num, const code_point& val = 0 );
495  void swap( UString& from );
497  bool empty() const;
499  const code_point* c_str() const;
501  const code_point* data() const;
503  size_type capacity() const;
505  void clear();
507 
508  UString substr( size_type index, size_type num = npos ) const;
510  void push_back( unicode_char val );
511 #if MYGUI_IS_NATIVE_WCHAR_T
512  void push_back( wchar_t val );
514 #endif
515 
518  void push_back( code_point val );
520 
521  void push_back( char val );
523  bool inString( unicode_char ch ) const;
525 
527 
529 
530  const std::string& asUTF8() const;
533  const char* asUTF8_c_str() const;
535  const utf32string& asUTF32() const;
537  const unicode_char* asUTF32_c_str() const;
539  const std::wstring& asWStr() const;
541  const wchar_t* asWStr_c_str() const;
543 
545 
547 
548  code_point& at( size_type loc );
551  const code_point& at( size_type loc ) const;
553 
557  unicode_char getChar( size_type loc ) const;
559 
567  int setChar( size_type loc, unicode_char ch );
569 
571 
573 
574  iterator begin();
577  const_iterator begin() const;
579  iterator end();
581  const_iterator end() const;
583  reverse_iterator rbegin();
585  const_reverse_iterator rbegin() const;
587  reverse_iterator rend();
589  const_reverse_iterator rend() const;
591 
593 
595 
596  UString& assign( iterator start, iterator end );
599  UString& assign( const UString& str );
601  UString& assign( const code_point* str );
603  UString& assign( const code_point* str, size_type num );
605  UString& assign( const UString& str, size_type index, size_type len );
607  UString& assign( size_type num, const code_point& ch );
609  UString& assign( const std::wstring& wstr );
610 #if MYGUI_IS_NATIVE_WCHAR_T
611  UString& assign( const wchar_t* w_str );
614  UString& assign( const wchar_t* w_str, size_type num );
615 #endif
616  UString& assign( const std::string& str );
619  UString& assign( const char* c_str );
621  UString& assign( const char* c_str, size_type num );
623 
625 
627 
628  UString& append( const UString& str );
631  UString& append( const code_point* str );
633  UString& append( const UString& str, size_type index, size_type len );
635  UString& append( const code_point* str, size_type num );
637  UString& append( size_type num, code_point ch );
639  UString& append( iterator start, iterator end );
640 #if MYGUI_IS_NATIVE_WCHAR_T
641  UString& append( const wchar_t* w_str, size_type num );
644  UString& append( size_type num, wchar_t ch );
645 #endif
646  UString& append( const char* c_str, size_type num );
649  UString& append( size_type num, char ch );
651  UString& append( size_type num, unicode_char ch );
653 
655 
657 
658  iterator insert( iterator i, const code_point& ch );
661  UString& insert( size_type index, const UString& str );
663  UString& insert( size_type index, const code_point* str ) {
664  mData.insert( index, str );
665  return *this;
666  }
668  UString& insert( size_type index1, const UString& str, size_type index2, size_type num );
670  void insert( iterator i, iterator start, iterator end );
672  UString& insert( size_type index, const code_point* str, size_type num );
673 #if MYGUI_IS_NATIVE_WCHAR_T
674  UString& insert( size_type index, const wchar_t* w_str, size_type num );
676 #endif
677  UString& insert( size_type index, const char* c_str, size_type num );
680  UString& insert( size_type index, size_type num, code_point ch );
681 #if MYGUI_IS_NATIVE_WCHAR_T
682  UString& insert( size_type index, size_type num, wchar_t ch );
684 #endif
685  UString& insert( size_type index, size_type num, char ch );
688  UString& insert( size_type index, size_type num, unicode_char ch );
690  void insert( iterator i, size_type num, const code_point& ch );
691 #if MYGUI_IS_NATIVE_WCHAR_T
692  void insert( iterator i, size_type num, const wchar_t& ch );
694 #endif
695  void insert( iterator i, size_type num, const char& ch );
698  void insert( iterator i, size_type num, const unicode_char& ch );
700 
702 
704 
705  iterator erase( iterator loc );
708  iterator erase( iterator start, iterator end );
710  UString& erase( size_type index = 0, size_type num = npos );
712 
714 
716 
717  UString& replace( size_type index1, size_type num1, const UString& str );
720  UString& replace( size_type index1, size_type num1, const UString& str, size_type num2 );
722  UString& replace( size_type index1, size_type num1, const UString& str, size_type index2, size_type num2 );
724  UString& replace( iterator start, iterator end, const UString& str, size_type num = npos );
726  UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
728  UString& replace( iterator start, iterator end, size_type num, code_point ch );
730 
732 
734 
735  int compare( const UString& str ) const;
738  int compare( const code_point* str ) const;
740  int compare( size_type index, size_type length, const UString& str ) const;
742  int compare( size_type index, size_type length, const UString& str, size_type index2, size_type length2 ) const;
744  int compare( size_type index, size_type length, const code_point* str, size_type length2 ) const;
745 #if MYGUI_IS_NATIVE_WCHAR_T
746  int compare( size_type index, size_type length, const wchar_t* w_str, size_type length2 ) const;
748 #endif
749  int compare( size_type index, size_type length, const char* c_str, size_type length2 ) const;
752 
754 
756 
757 
759  size_type find( const UString& str, size_type index = 0 ) const;
761 
762  size_type find( const code_point* cp_str, size_type index, size_type length ) const;
764 
765  size_type find( const char* c_str, size_type index, size_type length ) const;
766 #if MYGUI_IS_NATIVE_WCHAR_T
767 
769  size_type find( const wchar_t* w_str, size_type index, size_type length ) const;
770 #endif
771 
773  size_type find( char ch, size_type index = 0 ) const;
775 
776  size_type find( code_point ch, size_type index = 0 ) const;
777 #if MYGUI_IS_NATIVE_WCHAR_T
778 
780  size_type find( wchar_t ch, size_type index = 0 ) const;
781 #endif
782 
784  size_type find( unicode_char ch, size_type index = 0 ) const;
785 
787  size_type rfind( const UString& str, size_type index = 0 ) const;
789  size_type rfind( const code_point* cp_str, size_type index, size_type num ) const;
791  size_type rfind( const char* c_str, size_type index, size_type num ) const;
792 #if MYGUI_IS_NATIVE_WCHAR_T
793  size_type rfind( const wchar_t* w_str, size_type index, size_type num ) const;
795 #endif
796  size_type rfind( char ch, size_type index = 0 ) const;
799  size_type rfind( code_point ch, size_type index ) const;
800 #if MYGUI_IS_NATIVE_WCHAR_T
801  size_type rfind( wchar_t ch, size_type index = 0 ) const;
803 #endif
804  size_type rfind( unicode_char ch, size_type index = 0 ) const;
807 
809 
811 
812  size_type find_first_of( const UString &str, size_type index = 0, size_type num = npos ) const;
815  size_type find_first_of( code_point ch, size_type index = 0 ) const;
817  size_type find_first_of( char ch, size_type index = 0 ) const;
818 #if MYGUI_IS_NATIVE_WCHAR_T
819  size_type find_first_of( wchar_t ch, size_type index = 0 ) const;
821 #endif
822  size_type find_first_of( unicode_char ch, size_type index = 0 ) const;
824 
826  size_type find_first_not_of( const UString& str, size_type index = 0, size_type num = npos ) const;
828  size_type find_first_not_of( code_point ch, size_type index = 0 ) const;
830  size_type find_first_not_of( char ch, size_type index = 0 ) const;
831 #if MYGUI_IS_NATIVE_WCHAR_T
832  size_type find_first_not_of( wchar_t ch, size_type index = 0 ) const;
834 #endif
835  size_type find_first_not_of( unicode_char ch, size_type index = 0 ) const;
837 
839  size_type find_last_of( const UString& str, size_type index = npos, size_type num = npos ) const;
841  size_type find_last_of( code_point ch, size_type index = npos ) const;
843  size_type find_last_of( char ch, size_type index = npos ) const {
844  return find_last_of( static_cast<code_point>( ch ), index );
845  }
846 #if MYGUI_IS_NATIVE_WCHAR_T
847  size_type find_last_of( wchar_t ch, size_type index = npos ) const;
849 #endif
850  size_type find_last_of( unicode_char ch, size_type index = npos ) const;
852 
854  size_type find_last_not_of( const UString& str, size_type index = npos, size_type num = npos ) const;
856  size_type find_last_not_of( code_point ch, size_type index = npos ) const;
858  size_type find_last_not_of( char ch, size_type index = npos ) const;
859 #if MYGUI_IS_NATIVE_WCHAR_T
860  size_type find_last_not_of( wchar_t ch, size_type index = npos ) const;
862 #endif
863  size_type find_last_not_of( unicode_char ch, size_type index = npos ) const;
866 
868 
870 
871  bool operator<( const UString& right ) const;
874  bool operator<=( const UString& right ) const;
876  bool operator>( const UString& right ) const;
878  bool operator>=( const UString& right ) const;
880  bool operator==( const UString& right ) const;
882  bool operator!=( const UString& right ) const;
884  UString& operator=( const UString& s );
886  UString& operator=( code_point ch );
888  UString& operator=( char ch );
889 #if MYGUI_IS_NATIVE_WCHAR_T
890  UString& operator=( wchar_t ch );
892 #endif
893  UString& operator=( unicode_char ch );
896  code_point& operator[]( size_type index );
898  const code_point& operator[]( size_type index ) const;
900 
902 
904 
905  operator std::string() const;
908  operator std::wstring() const;
910 
912 
914 
915  static bool _utf16_independent_char( code_point cp );
918  static bool _utf16_surrogate_lead( code_point cp );
920  static bool _utf16_surrogate_follow( code_point cp );
922  static size_t _utf16_char_length( code_point cp );
924  static size_t _utf16_char_length( unicode_char uc );
926 
930  static size_t _utf16_to_utf32( const code_point in_cp[2], unicode_char& out_uc );
932 
937  static size_t _utf32_to_utf16( const unicode_char& in_uc, code_point out_cp[2] );
939 
941 
943 
944  static bool _utf8_start_char( unsigned char cp );
947  static size_t _utf8_char_length( unsigned char cp );
949  static size_t _utf8_char_length( unicode_char uc );
950 
952  static size_t _utf8_to_utf32( const unsigned char in_cp[6], unicode_char& out_uc );
954  static size_t _utf32_to_utf8( const unicode_char& in_uc, unsigned char out_cp[6] );
955 
957  static size_type _verifyUTF8( const unsigned char* c_str );
959  static size_type _verifyUTF8( const std::string& str );
961 
962  private:
963  //template<class ITER_TYPE> friend class _iterator;
964  dstring mData;
965 
967  enum BufferType {
968  bt_none,
969  bt_string,
970  bt_wstring,
971  bt_utf32string
972  };
973 
975  void _init();
976 
978  // Scratch buffer
980  void _cleanBuffer() const;
981 
983  void _getBufferStr() const;
985  void _getBufferWStr() const;
987  void _getBufferUTF32Str() const;
988 
989  void _load_buffer_UTF8() const;
990  void _load_buffer_WStr() const;
991  void _load_buffer_UTF32() const;
992 
993  mutable BufferType m_bufferType; // identifies the data type held in m_buffer
994  mutable size_t m_bufferSize; // size of the CString buffer
995 
996  // multi-purpose buffer used everywhere we need a throw-away buffer
997  union {
998  mutable void* mVoidBuffer;
999  mutable std::string* mStrBuffer;
1000  mutable std::wstring* mWStrBuffer;
1002  }
1003  m_buffer;
1004  };
1005 
1007  inline UString operator+( const UString& s1, const UString& s2 ) {
1008  return UString( s1 ).append( s2 );
1009  }
1012  return UString( s1 ).append( 1, c );
1013  }
1016  return UString( s1 ).append( 1, c );
1017  }
1019  inline UString operator+( const UString& s1, char c ) {
1020  return UString( s1 ).append( 1, c );
1021  }
1022 #if MYGUI_IS_NATIVE_WCHAR_T
1023  inline UString operator+( const UString& s1, wchar_t c ) {
1025  return UString( s1 ).append( 1, c );
1026  }
1027 #endif
1028  inline UString operator+( UString::code_point c, const UString& s2 ) {
1030  return UString().append( 1, c ).append( s2 );
1031  }
1034  return UString().append( 1, c ).append( s2 );
1035  }
1037  inline UString operator+( char c, const UString& s2 ) {
1038  return UString().append( 1, c ).append( s2 );
1039  }
1040 #if MYGUI_IS_NATIVE_WCHAR_T
1041  inline UString operator+( wchar_t c, const UString& s2 ) {
1043  return UString().append( 1, c ).append( s2 );
1044  }
1045 #endif
1046 
1047  // (const) forward iterator common operators
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  inline bool operator>( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1064  return left.mIter > right.mIter;
1065  }
1066  inline bool operator>=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1067  return left.mIter >= right.mIter;
1068  }
1069 
1070  // (const) reverse iterator common operators
1071  // NB: many of these operations are evaluated in reverse because this is a reverse iterator wrapping a forward iterator
1073  return ( right.mIter - left.mIter );
1074  }
1075  inline bool operator==( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1076  return left.mIter == right.mIter;
1077  }
1078  inline bool operator!=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1079  return left.mIter != right.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  inline bool operator>( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1088  return right.mIter > left.mIter;
1089  }
1090  inline bool operator>=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1091  return right.mIter >= left.mIter;
1092  }
1093 
1095  inline std::ostream& operator << ( std::ostream& os, const UString& s ) {
1096  return os << s.asUTF8();
1097  }
1098 
1100  inline std::wostream& operator << ( std::wostream& os, const UString& s ) {
1101  return os << s.asWStr();
1102  }
1103 
1104 } // namespace MyGUI
1105 
1106 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1107 # pragma warning (pop)
1108 #endif
1109 
1110 #endif // __MYGUI_U_STRING_H__
MyGUI::UString::invalid_data
This exception is used when invalid data streams are encountered.
Definition: MyGUI_UString.h:204
MyGUI::UString::find
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...
MyGUI::UString::_base_iterator::mString
UString * mString
Definition: MyGUI_UString.h:237
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:843
MyGUI::UString::operator+
UString operator+(UString::unicode_char c, const UString &s2)
string addition operator
Definition: MyGUI_UString.h:1033
MyGUI::uint16
unsigned short uint16
Definition: MyGUI_Types.h:45
MyGUI::UString::unicode_char
uint32 unicode_char
a single 32-bit Unicode character
Definition: MyGUI_UString.h:190
MyGUI::len
float len(float x, float y)
Definition: MyGUI_PolygonalSkin.cpp:31
MyGUI::UString::operator+
UString operator+(const UString &s1, UString::code_point c)
string addition operator
Definition: MyGUI_UString.h:1011
MyGUI::UString::operator+
UString operator+(const UString &s1, const UString &s2)
string addition operator
Definition: MyGUI_UString.h:1007
MyGUI::UString::_base_iterator::mIter
dstring::iterator mIter
Definition: MyGUI_UString.h:236
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::UString
UString(const wchar_t *w_str, size_type length)
duplicate of w_str, length characters long
MyGUI::UString::_rev_iterator
forward iterator for UString
Definition: MyGUI_UString.h:356
MyGUI::UString::mUTF32StrBuffer
utf32string * mUTF32StrBuffer
Definition: MyGUI_UString.h:1001
MyGUI::UString::operator+
UString operator+(const UString &s1, UString::unicode_char c)
string addition operator
Definition: MyGUI_UString.h:1015
MyGUI::UString::_base_iterator
base iterator class for UString
Definition: MyGUI_UString.h:215
MyGUI::UString::value_type
code_point value_type
value type typedef for use in iterators
Definition: MyGUI_UString.h:196
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::mVoidBuffer
void * mVoidBuffer
Definition: MyGUI_UString.h:998
MyGUI::UString::_const_rev_iterator::_const_rev_iterator
_const_rev_iterator()
MyGUI::operator>=
bool operator>=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1066
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:168
MyGUI::operator!=
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1054
MyGUI::UString::_const_fwd_iterator
const forward iterator for UString
Definition: MyGUI_UString.h:294
MyGUI::UString::dstring
std::basic_string< code_point > dstring
Definition: MyGUI_UString.h:198
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::_fwd_iterator::_fwd_iterator
_fwd_iterator()
MyGUI::UString::operator+
UString operator+(const UString &s1, char c)
string addition operator
Definition: MyGUI_UString.h:1019
MyGUI::UString::_fwd_iterator
forward iterator for UString
Definition: MyGUI_UString.h:247
MyGUI_Prerequest.h
MyGUI::operator<
bool operator<(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1057
MyGUI::UString::_rev_iterator::_rev_iterator
_rev_iterator()
MyGUI::uint32
unsigned int uint32
Definition: MyGUI_Types.h:46
MyGUI::operator-
UString::size_type operator-(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1048
MyGUI::UString::operator+
UString operator+(char c, const UString &s2)
string addition operator
Definition: MyGUI_UString.h:1037
MyGUI::UString::mStrBuffer
std::string * mStrBuffer
Definition: MyGUI_UString.h:999
MyGUI::UString::find
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...
MyGUI::operator<=
bool operator<=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1060
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:663
MyGUI::UString::utf32string
std::basic_string< unicode_char > utf32string
string type used for returning UTF-32 formatted data
Definition: MyGUI_UString.h:201
MyGUI::UString::mWStrBuffer
std::wstring * mWStrBuffer
Definition: MyGUI_UString.h:1000
MyGUI::UString::append
UString & append(size_type num, wchar_t ch)
appends num repetitions of ch on to the end of the current string
MyGUI::UString::_const_fwd_iterator::_const_fwd_iterator
_const_fwd_iterator()
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:89
MyGUI_Types.h
MyGUI::UString::assign
UString & assign(const wchar_t *w_str, size_type num)
assign the first num characters of w_str to the current string
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:1063
MyGUI::UString::_base_iterator::difference_type
ptrdiff_t difference_type
Definition: MyGUI_UString.h:218
MyGUI::UString::_const_rev_iterator
const reverse iterator for UString
Definition: MyGUI_UString.h:390
MyGUI
Definition: MyGUI_ActionController.h:15
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:1051