MyGUI 3.4.3
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 <string_view>
38#include <stdexcept>
39
40namespace MyGUI
41{
42
43 /* READ THIS NOTICE BEFORE USING IN YOUR OWN APPLICATIONS
44 =NOTICE=
45 This class is not a complete Unicode solution. It purposefully does not
46 provide certain functionality, such as proper lexical sorting for
47 Unicode values. It does provide comparison operators for the sole purpose
48 of using UString as an index with std::map and other operator< sorted
49 containers, but it should NOT be relied upon for meaningful lexical
50 operations, such as alphabetical sorts. If you need this type of
51 functionality, look into using ICU instead (http://icu.sourceforge.net/).
52
53 =REQUIREMENTS=
54 There are a few requirements for proper operation. They are fairly small,
55 and shouldn't restrict usage on any reasonable target.
56 * Compiler must support unsigned 16-bit integer types
57 * Compiler must support signed 32-bit integer types
58 * wchar_t must be either UTF-16 or UTF-32 encoding, and specified as such
59 using the WCHAR_UTF16 macro as outlined below.
60 * You must include <iterator>, <string>, and <wchar>. Probably more, but
61 these are the most obvious.
62
63 =REQUIRED PREPROCESSOR MACROS=
64 This class requires two preprocessor macros to be defined in order to
65 work as advertised.
66 INT32 - must be mapped to a signed 32 bit integer (ex. #define INT32 int)
67 UINT16 - must be mapped to an unsigned 16 bit integer (ex. #define UINT32 unsigned short)
68
69 Additionally, a third macro should be defined to control the evaluation of wchar_t:
70 WCHAR_UTF16 - should be defined when wchar_t represents UTF-16 code points,
71 such as in Windows. Otherwise it is assumed that wchar_t is a 32-bit
72 integer representing UTF-32 code points.
73 */
74
75 // THIS IS A VERY BRIEF AUTO DETECTION. YOU MAY NEED TO TWEAK THIS
76#ifdef __STDC_ISO_10646__
77// for any compiler that provides this, wchar_t is guaranteed to hold any Unicode value with a single code point (32-bit or larger)
78// so we can safely skip the rest of the testing
79#else // #ifdef __STDC_ISO_10646__
80 #if defined(__WIN32__) || defined(_WIN32)
81 #define WCHAR_UTF16 // All currently known Windows platforms utilize UTF-16 encoding in wchar_t
82 #else // #if defined( __WIN32__ ) || defined( _WIN32 )
83 #if WCHAR_MAX <= 0xFFFF // this is a last resort fall back test; WCHAR_MAX is defined in <wchar.h>
84 #define WCHAR_UTF16 // best we can tell, wchar_t is not larger than 16-bit
85 #endif // #if WCHAR_MAX <= 0xFFFF
86 #endif // #if defined( __WIN32__ ) || defined( _WIN32 )
87#endif // #ifdef __STDC_ISO_10646__
88
89
90// MYGUI_IS_NATIVE_WCHAR_T means that wchar_t isn't a typedef of
91// uint16_t or uint32_t.
92#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
93
94 // Don't define wchar_t related functions since it'll duplicate
95 // with UString::code_point related functions when compile
96 // without /Zc:wchar_t, because in this case both of them are
97 // a typedef of uint16_t.
98 #if defined(_NATIVE_WCHAR_T_DEFINED)
99 #define MYGUI_IS_NATIVE_WCHAR_T 1
100 #else
101 #define MYGUI_IS_NATIVE_WCHAR_T 0
102 #endif
103#else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
104
105 // Assumed wchar_t is natively for other compilers
106 #define MYGUI_IS_NATIVE_WCHAR_T 1
107
108#endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
109
110
111#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
112 // disable: warning C4275: non dll-interface class '***' used as base for dll-interface clas '***'
113 #pragma warning(push)
114 #pragma warning(disable : 4275)
115#endif
116
118
144 {
145 // constants used in UTF-8 conversions
146 static const unsigned char _lead1 = 0xC0; //110xxxxx
147 static const unsigned char _lead1_mask = 0x1F; //00011111
148 static const unsigned char _lead2 = 0xE0; //1110xxxx
149 static const unsigned char _lead2_mask = 0x0F; //00001111
150 static const unsigned char _lead3 = 0xF0; //11110xxx
151 static const unsigned char _lead3_mask = 0x07; //00000111
152 static const unsigned char _lead4 = 0xF8; //111110xx
153 static const unsigned char _lead4_mask = 0x03; //00000011
154 static const unsigned char _lead5 = 0xFC; //1111110x
155 static const unsigned char _lead5_mask = 0x01; //00000001
156 static const unsigned char _cont = 0x80; //10xxxxxx
157 static const unsigned char _cont_mask = 0x3F; //00111111
158
159 public:
161 using size_type = size_t;
163 static const size_type npos = std::numeric_limits<size_t>::max();
164
167
170
173
174 using dstring = std::basic_string<code_point>; // data string
175
177 using utf32string = std::basic_string<unicode_char>;
178
180 class MYGUI_EXPORT invalid_data : public std::runtime_error
181 {
182 public:
184 explicit invalid_data(const std::string& _message) :
185 std::runtime_error(_message)
186 {
187 /* The thing is, Bob, it's not that I'm lazy, it's that I just don't care. */
188 }
189 };
190
191 //#########################################################################
194 {
195 friend class UString;
196
197 protected:
198 using difference_type = ptrdiff_t;
199
200 void _seekFwd(size_type c);
201 void _seekRev(size_type c);
202 void _become(const _base_iterator& i);
203 bool _test_begin() const;
204 bool _test_end() const;
205 size_type _get_index() const;
206 void _jump_to(size_type index);
207
208 unicode_char _getCharacter() const;
209 int _setCharacter(unicode_char uc);
210
211 void _moveNext();
212 void _movePrev();
213
214 dstring::iterator mIter;
215 UString* mString{nullptr};
216 };
217
218 //#########################################################################
219 // FORWARD ITERATORS
220 //#########################################################################
221 class _const_fwd_iterator; // forward declaration
222
225 {
226 public:
228 _fwd_iterator& operator++();
230 _fwd_iterator operator++(int);
231
233 _fwd_iterator& operator--();
235 _fwd_iterator operator--(int);
236
241
243 _fwd_iterator& operator+=(difference_type n);
245 _fwd_iterator& operator-=(difference_type n);
246
248 value_type& operator*() const;
249
251 value_type& operator[](difference_type n) const;
252
254 _fwd_iterator& moveNext();
256 _fwd_iterator& movePrev();
258 unicode_char getCharacter() const;
260 int setCharacter(unicode_char uc);
261 };
262
263
264 //#########################################################################
267 {
268 public:
270
272
274 _const_fwd_iterator& operator++();
276 _const_fwd_iterator operator++(int);
277
279 _const_fwd_iterator& operator--();
281 _const_fwd_iterator operator--(int);
282
287
292
294 const value_type& operator*() const;
295
297 const value_type& operator[](difference_type n) const;
298
300 _const_fwd_iterator& moveNext();
302 _const_fwd_iterator& movePrev();
304 unicode_char getCharacter() const;
305
307 friend size_type operator-(const _const_fwd_iterator& left, const _const_fwd_iterator& right);
309 friend bool operator==(const _const_fwd_iterator& left, const _const_fwd_iterator& right);
311 friend bool operator!=(const _const_fwd_iterator& left, const _const_fwd_iterator& right);
313 friend bool operator<(const _const_fwd_iterator& left, const _const_fwd_iterator& right);
315 friend bool operator<=(const _const_fwd_iterator& left, const _const_fwd_iterator& right);
317 friend bool operator>(const _const_fwd_iterator& left, const _const_fwd_iterator& right);
319 friend bool operator>=(const _const_fwd_iterator& left, const _const_fwd_iterator& right);
320 };
321
322 //#########################################################################
323 // REVERSE ITERATORS
324 //#########################################################################
325 class _const_rev_iterator; // forward declaration
328 {
329 public:
331 _rev_iterator& operator++();
333 _rev_iterator operator++(int);
334
336 _rev_iterator& operator--();
338 _rev_iterator operator--(int);
339
344
346 _rev_iterator& operator+=(difference_type n);
348 _rev_iterator& operator-=(difference_type n);
349
351 value_type& operator*() const;
352
354 value_type& operator[](difference_type n) const;
355 };
356 //#########################################################################
359 {
360 public:
362
365 _const_rev_iterator& operator++();
367 _const_rev_iterator operator++(int);
368
370 _const_rev_iterator& operator--();
372 _const_rev_iterator operator--(int);
373
378
383
385 const value_type& operator*() const;
386
388 const value_type& operator[](difference_type n) const;
389
391 friend size_type 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);
403 friend bool operator>=(const _const_rev_iterator& left, const _const_rev_iterator& right);
404 };
405 //#########################################################################
406
411
412
414
415
416 UString();
418 UString(const UString& copy);
420 UString(size_type length, const code_point& ch);
422 UString(const code_point* str);
424 UString(const code_point* str, size_type length);
426 UString(const UString& str, size_type index, size_type length);
427#if MYGUI_IS_NATIVE_WCHAR_T
429 UString(const wchar_t* w_str);
431 UString(const wchar_t* w_str, size_type length);
432#endif
434 UString(const std::wstring& wstr);
436 UString(const char* c_str);
438 UString(const char* c_str, size_type length);
440 UString(const std::string& str);
441
442 explicit UString(const utf32string& str);
443
444 template<size_type num>
445 UString(const char (&str)[num]) :
446 UString(str, num)
447 {
448 }
449
450 explicit UString(std::string_view str) :
451 UString(str.data(), str.size())
452 {
453 }
455 ~UString();
457
459
461
462
463 size_type size() const;
465 size_type length() const;
467
468 size_type length_Characters() const;
470 size_type max_size() const;
472 void reserve(size_type size);
474 void resize(size_type num, const code_point& val = 0);
476 void swap(UString& from);
478 bool empty() const;
480 const code_point* c_str() const;
482 const code_point* data() const;
484 size_type capacity() const;
486 void clear();
488
489 UString substr(size_type index, size_type num = npos) const;
491 void push_back(unicode_char val);
492#if MYGUI_IS_NATIVE_WCHAR_T
494 void push_back(wchar_t val);
495#endif
497
499 void push_back(code_point val);
501
502 void push_back(char val);
504 bool inString(unicode_char ch) const;
506
508
510
511
512 const std::string& asUTF8() const;
514 const char* asUTF8_c_str() const;
516 const utf32string& asUTF32() const;
518 const unicode_char* asUTF32_c_str() const;
520 const std::wstring& asWStr() const;
522 const wchar_t* asWStr_c_str() const;
524
526
528
529
530 code_point& at(size_type loc);
532 const code_point& at(size_type loc) const;
534
538 unicode_char getChar(size_type loc) const;
540
548 int setChar(size_type loc, unicode_char ch);
550
552
554
555
556 iterator begin();
558 const_iterator begin() const;
560 iterator end();
562 const_iterator end() const;
564 reverse_iterator rbegin();
566 const_reverse_iterator rbegin() const;
568 reverse_iterator rend();
570 const_reverse_iterator rend() const;
572
574
576
577
578 UString& assign(iterator start, iterator end);
580 UString& assign(const UString& str);
582 UString& assign(const code_point* str);
584 UString& assign(const code_point* str, size_type num);
586 UString& assign(const UString& str, size_type index, size_type len);
588 UString& assign(size_type num, const code_point& ch);
590 UString& assign(const std::wstring& wstr);
591#if MYGUI_IS_NATIVE_WCHAR_T
593 UString& assign(const wchar_t* w_str);
595 UString& assign(const wchar_t* w_str, size_type num);
596#endif
598 UString& assign(std::string_view str)
599 {
600 return assign(str.data(), str.size());
601 }
602
603 UString& assign(const utf32string& str);
605 UString& assign(const char* c_str, size_type num);
607
609
611
612
613 UString& append(const UString& str);
615 UString& append(const code_point* str);
617 UString& append(const UString& str, size_type index, size_type len);
619 UString& append(const code_point* str, size_type num);
621 UString& append(size_type num, code_point ch);
623 UString& append(iterator start, iterator end);
624#if MYGUI_IS_NATIVE_WCHAR_T
626 UString& append(const wchar_t* w_str, size_type num);
628 UString& append(size_type num, wchar_t ch);
629#endif
631 UString& append(const char* c_str, size_type num);
633 UString& append(size_type num, char ch);
635 UString& append(size_type num, unicode_char ch);
637
639
641
642
643 iterator insert(iterator i, const code_point& ch);
645 UString& insert(size_type index, const UString& str);
647 UString& insert(size_type index, const code_point* str)
648 {
649 mData.insert(index, str);
650 return *this;
651 }
653 UString& insert(size_type index1, const UString& str, size_type index2, size_type num);
655 void insert(iterator i, iterator start, iterator end);
657 UString& insert(size_type index, const code_point* str, size_type num);
658#if MYGUI_IS_NATIVE_WCHAR_T
660 UString& insert(size_type index, const wchar_t* w_str, size_type num);
661#endif
663 UString& insert(size_type index, const char* c_str, size_type num);
665 UString& insert(size_type index, size_type num, code_point ch);
666#if MYGUI_IS_NATIVE_WCHAR_T
668 UString& insert(size_type index, size_type num, wchar_t ch);
669#endif
671 UString& insert(size_type index, size_type num, char ch);
673 UString& insert(size_type index, size_type num, unicode_char ch);
675 void insert(iterator i, size_type num, const code_point& ch);
676#if MYGUI_IS_NATIVE_WCHAR_T
678 void insert(iterator i, size_type num, const wchar_t& ch);
679#endif
681 void insert(iterator i, size_type num, const char& ch);
683 void insert(iterator i, size_type num, const unicode_char& ch);
685
687
689
690
691 iterator erase(iterator loc);
693 iterator erase(iterator start, iterator end);
695 UString& erase(size_type index = 0, size_type num = npos);
697
699
701
702
703 UString& replace(size_type index1, size_type num1, const UString& str);
705 UString& replace(size_type index1, size_type num1, const UString& str, size_type num2);
707 UString& replace(size_type index1, size_type num1, const UString& str, size_type index2, size_type num2);
709 UString& replace(iterator start, iterator end, const UString& str, size_type num = npos);
711 UString& replace(size_type index, size_type num1, size_type num2, code_point ch);
713 UString& replace(iterator start, iterator end, size_type num, code_point ch);
715
717
719
720
721 int compare(const UString& str) const;
723 int compare(const code_point* str) const;
725 int compare(size_type index, size_type length, const UString& str) const;
727 int compare(size_type index, size_type length, const UString& str, size_type index2, size_type length2) const;
729 int compare(size_type index, size_type length, const code_point* str, size_type length2) const;
730#if MYGUI_IS_NATIVE_WCHAR_T
732 int compare(size_type index, size_type length, const wchar_t* w_str, size_type length2) const;
733#endif
735 int compare(size_type index, size_type length, const char* c_str, size_type length2) const;
737
739
741
742
744 size_type find(const UString& str, size_type index = 0) const;
746
747 size_type find(const code_point* cp_str, size_type index, size_type length) const;
749
750 size_type find(const char* c_str, size_type index, size_type length) const;
751#if MYGUI_IS_NATIVE_WCHAR_T
753
754 size_type find(const wchar_t* w_str, size_type index, size_type length) const;
755#endif
757
758 size_type find(char ch, size_type index = 0) const;
760
761 size_type find(code_point ch, size_type index = 0) const;
762#if MYGUI_IS_NATIVE_WCHAR_T
764
765 size_type find(wchar_t ch, size_type index = 0) const;
766#endif
768
769 size_type find(unicode_char ch, size_type index = 0) const;
770
772 size_type rfind(const UString& str, size_type index = 0) const;
774 size_type rfind(const code_point* cp_str, size_type index, size_type num) const;
776 size_type rfind(const char* c_str, size_type index, size_type num) const;
777#if MYGUI_IS_NATIVE_WCHAR_T
779 size_type rfind(const wchar_t* w_str, size_type index, size_type num) const;
780#endif
782 size_type rfind(char ch, size_type index = 0) const;
784 size_type rfind(code_point ch, size_type index) const;
785#if MYGUI_IS_NATIVE_WCHAR_T
787 size_type rfind(wchar_t ch, size_type index = 0) const;
788#endif
790 size_type rfind(unicode_char ch, size_type index = 0) const;
792
794
796
797
798 size_type find_first_of(const UString& str, size_type index = 0, size_type num = npos) const;
800 size_type find_first_of(code_point ch, size_type index = 0) const;
802 size_type find_first_of(char ch, size_type index = 0) const;
803#if MYGUI_IS_NATIVE_WCHAR_T
805 size_type find_first_of(wchar_t ch, size_type index = 0) const;
806#endif
808 size_type find_first_of(unicode_char ch, size_type index = 0) const;
809
811 size_type find_first_not_of(const UString& str, size_type index = 0, size_type num = npos) const;
813 size_type find_first_not_of(code_point ch, size_type index = 0) const;
815 size_type find_first_not_of(char ch, size_type index = 0) const;
816#if MYGUI_IS_NATIVE_WCHAR_T
818 size_type find_first_not_of(wchar_t ch, size_type index = 0) const;
819#endif
821 size_type find_first_not_of(unicode_char ch, size_type index = 0) const;
822
824 size_type find_last_of(const UString& str, size_type index = npos, size_type num = npos) const;
826 size_type find_last_of(code_point ch, size_type index = npos) const;
828 size_type find_last_of(char ch, size_type index = npos) const
829 {
830 return find_last_of(static_cast<code_point>(ch), index);
831 }
832#if MYGUI_IS_NATIVE_WCHAR_T
834 size_type find_last_of(wchar_t ch, size_type index = npos) const;
835#endif
837 size_type find_last_of(unicode_char ch, size_type index = npos) const;
838
840 size_type find_last_not_of(const UString& str, size_type index = npos, size_type num = npos) const;
842 size_type find_last_not_of(code_point ch, size_type index = npos) const;
844 size_type find_last_not_of(char ch, size_type index = npos) const;
845#if MYGUI_IS_NATIVE_WCHAR_T
847 size_type find_last_not_of(wchar_t ch, size_type index = npos) const;
848#endif
850 size_type find_last_not_of(unicode_char ch, size_type index = npos) const;
852
854
856
857
858 bool operator<(const UString& right) const;
860 bool operator<=(const UString& right) const;
862 bool operator>(const UString& right) const;
864 bool operator>=(const UString& right) const;
866 bool operator==(const UString& right) const;
868 bool operator!=(const UString& right) const;
870 UString& operator=(const UString& s);
872 UString& operator=(code_point ch);
874 UString& operator=(char ch);
875#if MYGUI_IS_NATIVE_WCHAR_T
877 UString& operator=(wchar_t ch);
878#endif
880 UString& operator=(unicode_char ch);
882 code_point& operator[](size_type index);
884 const code_point& operator[](size_type index) const;
886
888
890
891
892 operator std::string() const;
894 operator std::wstring() const;
896 operator std::string_view() const
897 {
898 return asUTF8();
899 }
901
903
905
906
907 static bool _utf16_independent_char(code_point cp);
909 static bool _utf16_surrogate_lead(code_point cp);
911 static bool _utf16_surrogate_follow(code_point cp);
913 static size_t _utf16_char_length(code_point cp);
915 static size_t _utf16_char_length(unicode_char uc);
917
921 static size_t _utf16_to_utf32(const code_point in_cp[2], unicode_char& out_uc);
923
928 static size_t _utf32_to_utf16(const unicode_char& in_uc, code_point out_cp[2]);
930
932
934
935
936 static bool _utf8_start_char(unsigned char cp);
938 static size_t _utf8_char_length(unsigned char cp);
940 static size_t _utf8_char_length(unicode_char uc);
941
943 static size_t _utf8_to_utf32(const unsigned char in_cp[6], unicode_char& out_uc);
945 static size_t _utf32_to_utf8(const unicode_char& in_uc, unsigned char out_cp[6]);
946
948 static size_type _verifyUTF8(const unsigned char* c_str);
950 static size_type _verifyUTF8(std::string_view str)
951 {
952 return _verifyUTF8(str.data(), str.size());
953 }
955 static size_type _verifyUTF8(const char* c_str, size_type num);
957
958 private:
959 dstring mData;
960
962 enum BufferType
963 {
964 bt_none,
965 bt_string,
966 bt_wstring,
967 bt_utf32string
968 };
969
971 void _init();
972
974 // Scratch buffer
976 void _cleanBuffer() const;
977
979 void _getBufferStr() const;
981 void _getBufferWStr() const;
983 void _getBufferUTF32Str() const;
984
985 void _load_buffer_UTF8() const;
986 void _load_buffer_WStr() const;
987 void _load_buffer_UTF32() const;
988
989 mutable BufferType m_bufferType; // identifies the data type held in m_buffer
990 mutable size_t m_bufferSize; // size of the CString buffer
991
992 // multi-purpose buffer used everywhere we need a throw-away buffer
993 union
994 {
995 mutable void* mVoidBuffer;
996 mutable std::string* mStrBuffer;
997 mutable std::wstring* mWStrBuffer;
999 } m_buffer;
1000 };
1001
1003 inline UString operator+(const UString& s1, const UString& s2)
1004 {
1005 return UString(s1).append(s2);
1006 }
1009 {
1010 return UString(s1).append(1, c);
1011 }
1014 {
1015 return UString(s1).append(1, c);
1016 }
1018 inline UString operator+(const UString& s1, char c)
1019 {
1020 return UString(s1).append(1, c);
1021 }
1022#if MYGUI_IS_NATIVE_WCHAR_T
1024 inline UString operator+(const UString& s1, wchar_t c)
1025 {
1026 return UString(s1).append(1, c);
1027 }
1028#endif
1031 {
1032 return UString().append(1, c).append(s2);
1033 }
1036 {
1037 return UString().append(1, c).append(s2);
1038 }
1040 inline UString operator+(char c, const UString& s2)
1041 {
1042 return UString().append(1, c).append(s2);
1043 }
1044#if MYGUI_IS_NATIVE_WCHAR_T
1046 inline UString operator+(wchar_t c, const UString& s2)
1047 {
1048 return UString().append(1, c).append(s2);
1049 }
1050#endif
1051
1052 // (const) forward iterator common operators
1054 const UString::_const_fwd_iterator& left,
1055 const UString::_const_fwd_iterator& right)
1056 {
1057 return (left.mIter - right.mIter);
1058 }
1060 {
1061 return left.mIter == right.mIter;
1062 }
1064 {
1065 return left.mIter != right.mIter;
1066 }
1068 {
1069 return left.mIter < right.mIter;
1070 }
1072 {
1073 return left.mIter <= right.mIter;
1074 }
1076 {
1077 return left.mIter > right.mIter;
1078 }
1080 {
1081 return left.mIter >= right.mIter;
1082 }
1083
1084 // (const) reverse iterator common operators
1085 // NB: many of these operations are evaluated in reverse because this is a reverse iterator wrapping a forward iterator
1087 const UString::_const_rev_iterator& left,
1088 const UString::_const_rev_iterator& right)
1089 {
1090 return (right.mIter - left.mIter);
1091 }
1093 {
1094 return left.mIter == right.mIter;
1095 }
1097 {
1098 return left.mIter != right.mIter;
1099 }
1101 {
1102 return right.mIter < left.mIter;
1103 }
1105 {
1106 return right.mIter <= left.mIter;
1107 }
1109 {
1110 return right.mIter > left.mIter;
1111 }
1113 {
1114 return right.mIter >= left.mIter;
1115 }
1116
1118 inline std::ostream& operator<<(std::ostream& os, const UString& s)
1119 {
1120 return os << s.asUTF8();
1121 }
1122
1124 inline std::wostream& operator<<(std::wostream& os, const UString& s)
1125 {
1126 return os << s.asWStr();
1127 }
1128
1129#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1130 #pragma warning(pop)
1131#endif
1132
1133} // namespace MyGUI
1134
1135#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...
static size_type _verifyUTF8(std::string_view str)
verifies a UTF-8 stream, returning the total number of Unicode characters found
UString & assign(const wchar_t *w_str)
assign w_str to the current string
UString & assign(std::string_view str)
assign str to the current string (str is treated as a UTF-8 stream)
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...
code_point value_type
value type typedef for use in iterators
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
std::ostream & operator<<(std::ostream &os, const UString &s)
std::ostream write operator
UString(std::string_view str)
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
const std::wstring & asWStr() const
returns the current string in the native form of std::wstring
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
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(const char(&str)[num])
UString operator+(const UString &s1, wchar_t c)
string addition operator
std::wostream & operator<<(std::wostream &os, const UString &s)
std::wostream write operator
UString operator+(char c, const UString &s2)
string addition operator
UString(const wchar_t *w_str)
duplicate of nul-terminated wchar_t array
uint32_t uint32
Definition MyGUI_Types.h:48
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)
uint16_t uint16
Definition MyGUI_Types.h:47
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)