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
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.
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.
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.
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
25
// - Eric Shorkey (zero/zeroskill) <opengui@rightbracket.com> [January 20th, 2007]
27
#ifndef __MYGUI_U_STRING_H__
28
#define __MYGUI_U_STRING_H__
31
#include "MyGUI_Prerequest.h"
32
#include "MyGUI_Types.h"
34
// these are explained later
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 (disable : 4275)
44
// Workaround for VC7:
45
// when build with /MD or /MDd, VC7 have both std::basic_string<unsigned short> and
46
// basic_string<__wchar_t> instantiated in msvcprt[d].lib/MSVCP71[D].dll, but the header
47
// files tells compiler that only one of them is over there (based on /Zc:wchar_t compile
48
// option). And since this file used both of them, causing compiler instantiating another
49
// one in user object code, which lead to duplicate symbols with msvcprt.lib/MSVCP71[D].dll.
51
#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && (1300 <= MYGUI_COMP_VER && MYGUI_COMP_VER <= 1310)
53
# if defined(_DLL_CPPLIB)
57
template class _CRTIMP2 basic_string<unsigned short, char_traits<unsigned short>,
58
allocator<unsigned short> >;
60
template class _CRTIMP2 basic_string<__wchar_t, char_traits<__wchar_t>,
61
allocator<__wchar_t> >;
64
# endif // defined(_DLL_CPPLIB)
66
#endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER == 1300
72
/* READ THIS NOTICE BEFORE USING IN YOUR OWN APPLICATIONS
74
This class is not a complete Unicode solution. It purposefully does not
75
provide certain functionality, such as proper lexical sorting for
76
Unicode values. It does provide comparison operators for the sole purpose
77
of using UString as an index with std::map and other operator< sorted
78
containers, but it should NOT be relied upon for meaningful lexical
79
operations, such as alphabetical sorts. If you need this type of
80
functionality, look into using ICU instead (http://icu.sourceforge.net/).
83
There are a few requirements for proper operation. They are fairly small,
84
and shouldn't restrict usage on any reasonable target.
85
* Compiler must support unsigned 16-bit integer types
86
* Compiler must support signed 32-bit integer types
87
* wchar_t must be either UTF-16 or UTF-32 encoding, and specified as such
88
using the WCHAR_UTF16 macro as outlined below.
89
* You must include <iterator>, <string>, and <wchar>. Probably more, but
90
these are the most obvious.
92
=REQUIRED PREPROCESSOR MACROS=
93
This class requires two preprocessor macros to be defined in order to
95
INT32 - must be mapped to a signed 32 bit integer (ex. #define INT32 int)
96
UINT16 - must be mapped to an unsigned 16 bit integer (ex. #define UINT32 unsigned short)
98
Additionally, a third macro should be defined to control the evaluation of wchar_t:
99
WCHAR_UTF16 - should be defined when wchar_t represents UTF-16 code points,
100
such as in Windows. Otherwise it is assumed that wchar_t is a 32-bit
101
integer representing UTF-32 code points.
104
// THIS IS A VERY BRIEF AUTO DETECTION. YOU MAY NEED TO TWEAK THIS
105
#ifdef __STDC_ISO_10646__
106
// for any compiler that provides this, wchar_t is guaranteed to hold any Unicode value with a single code point (32-bit or larger)
107
// so we can safely skip the rest of the testing
108
#else // #ifdef __STDC_ISO_10646__
109
#if defined( __WIN32__ ) || defined( _WIN32 )
110
#define WCHAR_UTF16 // All currently known Windows platforms utilize UTF-16 encoding in wchar_t
111
#else // #if defined( __WIN32__ ) || defined( _WIN32 )
112
#if MYGUI_COMPILER != MYGUI_COMPILER_GCCE
113
#if WCHAR_MAX <= 0xFFFF // this is a last resort fall back test; WCHAR_MAX is defined in <wchar.h>
114
#define WCHAR_UTF16 // best we can tell, wchar_t is not larger than 16-bit
115
#endif // #if WCHAR_MAX <= 0xFFFF
117
#endif // #if defined( __WIN32__ ) || defined( _WIN32 )
118
#endif // #ifdef __STDC_ISO_10646__
121
// MYGUI_IS_NATIVE_WCHAR_T means that wchar_t isn't a typedef of
122
// uint16_t or uint32_t.
123
#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
125
// Don't define wchar_t related functions since it'll duplicate
126
// with UString::code_point related functions when compile
127
// without /Zc:wchar_t, because in this case both of them are
128
// a typedef of uint16_t.
129
# if defined(_NATIVE_WCHAR_T_DEFINED)
130
# define MYGUI_IS_NATIVE_WCHAR_T 1
132
# define MYGUI_IS_NATIVE_WCHAR_T 0
134
#elif MYGUI_PLATFORM == MYGUI_PLATFORM_SYMBIAN
135
# define MYGUI_IS_NATIVE_WCHAR_T 0
136
#else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
138
// Assumed wchar_t is natively for other compilers
139
# define MYGUI_IS_NATIVE_WCHAR_T 1
141
#endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
143
//! A UTF-16 string with implicit conversion to/from std::string and std::wstring
144
/*! This class provides a complete 1 to 1 map of most std::string functions (at least to my
145
knowledge). Implicit conversions allow this string class to work with all common C++ string
146
formats, with specialty functions defined where implicit conversion would cause potential
147
problems or is otherwise unavailable.
149
Some additional functionality is present to assist in working with characters using the
150
32-bit UTF-32 encoding. (Which is guaranteed to fit any Unicode character into a single
151
code point.) \b Note: Reverse iterators do not have this functionality due to the
152
ambiguity that surrounds working with UTF-16 in reverse. (Such as, where should an
153
iterator point to represent the beginning of a surrogate pair?)
156
\par Supported Input Types
157
The supported string types for input, and their assumed encoding schemes, are:
158
- std::string (UTF-8)
160
- std::wstring (autodetected UTF-16 / UTF-32 based on compiler)
161
- wchar_t* (autodetected UTF-16 / UTF-32 based on compiler)
165
- For additional information on UTF-16 encoding: http://en.wikipedia.org/wiki/UTF-16
166
- For additional information on UTF-8 encoding: http://en.wikipedia.org/wiki/UTF-8
167
- For additional information on UTF-32 encoding: http://en.wikipedia.org/wiki/UTF-32
169
class MYGUI_EXPORT UString {
170
// constants used in UTF-8 conversions
171
static const unsigned char _lead1 = 0xC0; //110xxxxx
172
static const unsigned char _lead1_mask = 0x1F; //00011111
173
static const unsigned char _lead2 = 0xE0; //1110xxxx
174
static const unsigned char _lead2_mask = 0x0F; //00001111
175
static const unsigned char _lead3 = 0xF0; //11110xxx
176
static const unsigned char _lead3_mask = 0x07; //00000111
177
static const unsigned char _lead4 = 0xF8; //111110xx
178
static const unsigned char _lead4_mask = 0x03; //00000011
179
static const unsigned char _lead5 = 0xFC; //1111110x
180
static const unsigned char _lead5_mask = 0x01; //00000001
181
static const unsigned char _cont = 0x80; //10xxxxxx
182
static const unsigned char _cont_mask = 0x3F; //00111111
185
//! size type used to indicate string size and character positions within the string
186
typedef size_t size_type;
187
//! the usual constant representing: not found, no limit, etc
188
static const size_type npos = static_cast<size_type>(~0);
190
//! a single 32-bit Unicode character
191
typedef uint32 unicode_char;
193
//! a single UTF-16 code point
194
typedef uint16 code_point;
196
//! value type typedef for use in iterators
197
typedef code_point value_type;
199
typedef std::basic_string<code_point> dstring; // data string
201
//! string type used for returning UTF-32 formatted data
202
typedef std::basic_string<unicode_char> utf32string;
204
//! This exception is used when invalid data streams are encountered
205
class MYGUI_EXPORT invalid_data: public std::runtime_error { /* i don't know why the beautifier is freaking out on this line */
207
//! constructor takes a string message that can be later retrieved by the what() function
208
explicit invalid_data( const std::string& _Message ): std::runtime_error( _Message ) {
209
/* The thing is, Bob, it's not that I'm lazy, it's that I just don't care. */
213
//#########################################################################
214
//! base iterator class for UString
215
class MYGUI_EXPORT _base_iterator: public std::iterator<std::random_access_iterator_tag, value_type> { /* i don't know why the beautifier is freaking out on this line */
216
friend class UString;
220
void _seekFwd( size_type c );
221
void _seekRev( size_type c );
222
void _become( const _base_iterator& i );
223
bool _test_begin() const;
224
bool _test_end() const;
225
size_type _get_index() const;
226
void _jump_to( size_type index );
228
unicode_char _getCharacter() const;
229
int _setCharacter( unicode_char uc );
234
dstring::iterator mIter;
238
//#########################################################################
240
//#########################################################################
241
class _const_fwd_iterator; // forward declaration
243
//! forward iterator for UString
244
class MYGUI_EXPORT _fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
245
friend class _const_fwd_iterator;
248
_fwd_iterator( const _fwd_iterator& i );
251
_fwd_iterator& operator++();
253
_fwd_iterator operator++( int );
256
_fwd_iterator& operator--();
258
_fwd_iterator operator--( int );
260
//! addition operator
261
_fwd_iterator operator+( difference_type n );
262
//! subtraction operator
263
_fwd_iterator operator-( difference_type n );
265
//! addition assignment operator
266
_fwd_iterator& operator+=( difference_type n );
267
//! subtraction assignment operator
268
_fwd_iterator& operator-=( difference_type n );
270
//! dereference operator
271
value_type& operator*() const;
273
//! dereference at offset operator
274
value_type& operator[]( difference_type n ) const;
276
//! advances to the next Unicode character, honoring surrogate pairs in the UTF-16 stream
277
_fwd_iterator& moveNext();
278
//! rewinds to the previous Unicode character, honoring surrogate pairs in the UTF-16 stream
279
_fwd_iterator& movePrev();
280
//! Returns the Unicode value of the character at the current position (decodes surrogate pairs if needed)
281
unicode_char getCharacter() const;
282
//! Sets the Unicode value of the character at the current position (adding a surrogate pair if needed); returns the amount of string length change caused by the operation
283
int setCharacter( unicode_char uc );
288
//#########################################################################
289
//! const forward iterator for UString
290
class MYGUI_EXPORT _const_fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
292
_const_fwd_iterator();
293
_const_fwd_iterator( const _const_fwd_iterator& i );
294
_const_fwd_iterator( const _fwd_iterator& i );
297
_const_fwd_iterator& operator++();
299
_const_fwd_iterator operator++( int );
302
_const_fwd_iterator& operator--();
304
_const_fwd_iterator operator--( int );
306
//! addition operator
307
_const_fwd_iterator operator+( difference_type n );
308
//! subtraction operator
309
_const_fwd_iterator operator-( difference_type n );
311
//! addition assignment operator
312
_const_fwd_iterator& operator+=( difference_type n );
313
//! subtraction assignment operator
314
_const_fwd_iterator& operator-=( difference_type n );
316
//! dereference operator
317
const value_type& operator*() const;
319
//! dereference at offset operator
320
const value_type& operator[]( difference_type n ) const;
322
//! advances to the next Unicode character, honoring surrogate pairs in the UTF-16 stream
323
_const_fwd_iterator& moveNext();
324
//! rewinds to the previous Unicode character, honoring surrogate pairs in the UTF-16 stream
325
_const_fwd_iterator& movePrev();
326
//! Returns the Unicode value of the character at the current position (decodes surrogate pairs if needed)
327
unicode_char getCharacter() const;
329
//! difference operator
330
friend size_type operator-( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
331
//! equality operator
332
friend bool operator==( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
333
//! inequality operator
334
friend bool operator!=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
336
friend bool operator<( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
337
//! less than or equal
338
friend bool operator<=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
340
friend bool operator>( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
341
//! greater than or equal
342
friend bool operator>=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
346
//#########################################################################
348
//#########################################################################
349
class _const_rev_iterator; // forward declaration
350
//! forward iterator for UString
351
class MYGUI_EXPORT _rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
352
friend class _const_rev_iterator;
355
_rev_iterator( const _rev_iterator& i );
358
_rev_iterator& operator++();
360
_rev_iterator operator++( int );
363
_rev_iterator& operator--();
365
_rev_iterator operator--( int );
367
//! addition operator
368
_rev_iterator operator+( difference_type n );
369
//! subtraction operator
370
_rev_iterator operator-( difference_type n );
372
//! addition assignment operator
373
_rev_iterator& operator+=( difference_type n );
374
//! subtraction assignment operator
375
_rev_iterator& operator-=( difference_type n );
377
//! dereference operator
378
value_type& operator*() const;
380
//! dereference at offset operator
381
value_type& operator[]( difference_type n ) const;
383
//#########################################################################
384
//! const reverse iterator for UString
385
class MYGUI_EXPORT _const_rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
387
_const_rev_iterator();
388
_const_rev_iterator( const _const_rev_iterator& i );
389
_const_rev_iterator( const _rev_iterator& i );
391
_const_rev_iterator& operator++();
393
_const_rev_iterator operator++( int );
396
_const_rev_iterator& operator--();
398
_const_rev_iterator operator--( int );
400
//! addition operator
401
_const_rev_iterator operator+( difference_type n );
402
//! subtraction operator
403
_const_rev_iterator operator-( difference_type n );
405
//! addition assignment operator
406
_const_rev_iterator& operator+=( difference_type n );
407
//! subtraction assignment operator
408
_const_rev_iterator& operator-=( difference_type n );
410
//! dereference operator
411
const value_type& operator*() const;
413
//! dereference at offset operator
414
const value_type& operator[]( difference_type n ) const;
416
//! difference operator
417
friend size_type operator-( const _const_rev_iterator& left, const _const_rev_iterator& right );
418
//! equality operator
419
friend bool operator==( const _const_rev_iterator& left, const _const_rev_iterator& right );
420
//! inequality operator
421
friend bool operator!=( const _const_rev_iterator& left, const _const_rev_iterator& right );
423
friend bool operator<( const _const_rev_iterator& left, const _const_rev_iterator& right );
424
//! less than or equal
425
friend bool operator<=( const _const_rev_iterator& left, const _const_rev_iterator& right );
427
friend bool operator>( const _const_rev_iterator& left, const _const_rev_iterator& right );
428
//! greater than or equal
429
friend bool operator>=( const _const_rev_iterator& left, const _const_rev_iterator& right );
431
//#########################################################################
433
typedef _fwd_iterator iterator; //!< iterator
434
typedef _rev_iterator reverse_iterator; //!< reverse iterator
435
typedef _const_fwd_iterator const_iterator; //!< const iterator
436
typedef _const_rev_iterator const_reverse_iterator; //!< const reverse iterator
439
//!\name Constructors/Destructor
441
//! default constructor, creates an empty string
444
UString( const UString& copy );
445
//! \a length copies of \a ch
446
UString( size_type length, const code_point& ch );
447
//! duplicate of nul-terminated sequence \a str
448
UString( const code_point* str );
449
//! duplicate of \a str, \a length code points long
450
UString( const code_point* str, size_type length );
451
//! substring of \a str starting at \a index and \a length code points long
452
UString( const UString& str, size_type index, size_type length );
453
#if MYGUI_IS_NATIVE_WCHAR_T
454
//! duplicate of nul-terminated \c wchar_t array
455
UString( const wchar_t* w_str );
456
//! duplicate of \a w_str, \a length characters long
457
UString( const wchar_t* w_str, size_type length );
459
//! duplicate of \a wstr
460
UString( const std::wstring& wstr );
461
//! duplicate of nul-terminated C-string \a c_str (UTF-8 encoding)
462
UString( const char* c_str );
463
//! duplicate of \a c_str, \a length characters long (UTF-8 encoding)
464
UString( const char* c_str, size_type length );
465
//! duplicate of \a str (UTF-8 encoding)
466
UString( const std::string& str );
472
//////////////////////////////////////////////////////////////////////////
474
//!\name Utility functions
476
//! Returns the number of code points in the current string
477
size_type size() const;
478
//! Returns the number of code points in the current string
479
size_type length() const;
480
//! Returns the number of Unicode characters in the string
481
/*! Executes in linear time. */
482
size_type length_Characters() const;
483
//! returns the maximum number of UTF-16 code points that the string can hold
484
size_type max_size() const;
485
//! sets the capacity of the string to at least \a size code points
486
void reserve( size_type size );
487
//! changes the size of the string to \a size, filling in any new area with \a val
488
void resize( size_type num, const code_point& val = 0 );
489
//! exchanges the elements of the current string with those of \a from
490
void swap( UString& from );
491
//! returns \c true if the string has no elements, \c false otherwise
493
//! returns a pointer to the first character in the current string
494
const code_point* c_str() const;
495
//! returns a pointer to the first character in the current string
496
const code_point* data() const;
497
//! returns the number of elements that the string can hold before it will need to allocate more space
498
size_type capacity() const;
499
//! deletes all of the elements in the string
501
//! returns a substring of the current string, starting at \a index, and \a num characters long.
502
/*! If \a num is omitted, it will default to \c UString::npos, and the substr() function will simply return the remainder of the string starting at \a index. */
503
UString substr( size_type index, size_type num = npos ) const;
504
//! appends \a val to the end of the string
505
void push_back( unicode_char val );
506
#if MYGUI_IS_NATIVE_WCHAR_T
507
//! appends \a val to the end of the string
508
void push_back( wchar_t val );
510
//! appends \a val to the end of the string
511
/*! This can be used to push surrogate pair code points, you'll just need to push them
512
one after the other. */
513
void push_back( code_point val );
514
//! appends \a val to the end of the string
515
/*! Limited to characters under the 127 value barrier. */
516
void push_back( char val );
517
//! returns \c true if the given Unicode character \a ch is in this string
518
bool inString( unicode_char ch ) const;
521
//////////////////////////////////////////////////////////////////////////
523
//!\name Stream variations
525
//! returns the current string in UTF-8 form within a std::string
526
const std::string& asUTF8() const;
527
//! returns the current string in UTF-8 form as a nul-terminated char array
528
const char* asUTF8_c_str() const;
529
//! returns the current string in UTF-32 form within a utf32string
530
const utf32string& asUTF32() const;
531
//! returns the current string in UTF-32 form as a nul-terminated unicode_char array
532
const unicode_char* asUTF32_c_str() const;
533
//! returns the current string in the native form of std::wstring
534
const std::wstring& asWStr() const;
535
//! returns the current string in the native form of a nul-terminated wchar_t array
536
const wchar_t* asWStr_c_str() const;
539
//////////////////////////////////////////////////////////////////////////
541
//!\name Single Character Access
543
//! returns a reference to the element in the string at index \c loc
544
code_point& at( size_type loc );
545
//! returns a reference to the element in the string at index \c loc
546
const code_point& at( size_type loc ) const;
547
//! returns the data point \a loc evaluated as a UTF-32 value
548
/*! This function will will only properly decode surrogate pairs when \a loc points to the index
549
of a lead code point that is followed by a trailing code point. Evaluating the trailing code point
550
itself, or pointing to a code point that is a sentinel value (part of a broken pair) will return
551
the value of just that code point (not a valid Unicode value, but useful as a sentinel value). */
552
unicode_char getChar( size_type loc ) const;
553
//! sets the value of the character at \a loc to the Unicode value \a ch (UTF-32)
554
/*! Providing sentinel values (values between U+D800-U+DFFF) are accepted, but you should be aware
555
that you can also unwittingly create a valid surrogate pair if you don't pay attention to what you
556
are doing. \note This operation may also lengthen the string if a surrogate pair is needed to
557
represent the value given, but one is not available to replace; or alternatively shorten the string
558
if an existing surrogate pair is replaced with a character that is representable without a surrogate
559
pair. The return value will signify any lengthening or shortening performed, returning 0 if no change
560
was made, -1 if the string was shortened, or 1 if the string was lengthened. Any single call can
561
only change the string length by + or - 1. */
562
int setChar( size_type loc, unicode_char ch );
565
//////////////////////////////////////////////////////////////////////////
567
//!\name iterator acquisition
569
//! returns an iterator to the first element of the string
571
//! returns an iterator to the first element of the string
572
const_iterator begin() const;
573
//! returns an iterator just past the end of the string
575
//! returns an iterator just past the end of the string
576
const_iterator end() const;
577
//! returns a reverse iterator to the last element of the string
578
reverse_iterator rbegin();
579
//! returns a reverse iterator to the last element of the string
580
const_reverse_iterator rbegin() const;
581
//! returns a reverse iterator just past the beginning of the string
582
reverse_iterator rend();
583
//! returns a reverse iterator just past the beginning of the string
584
const_reverse_iterator rend() const;
587
//////////////////////////////////////////////////////////////////////////
591
//! gives the current string the values from \a start to \a end
592
UString& assign( iterator start, iterator end );
593
//! assign \a str to the current string
594
UString& assign( const UString& str );
595
//! assign the nul-terminated \a str to the current string
596
UString& assign( const code_point* str );
597
//! assign the first \a num characters of \a str to the current string
598
UString& assign( const code_point* str, size_type num );
599
//! assign \a len entries from \a str to the current string, starting at \a index
600
UString& assign( const UString& str, size_type index, size_type len );
601
//! assign \a num copies of \a ch to the current string
602
UString& assign( size_type num, const code_point& ch );
603
//! assign \a wstr to the current string (\a wstr is treated as a UTF-16 stream)
604
UString& assign( const std::wstring& wstr );
605
#if MYGUI_IS_NATIVE_WCHAR_T
606
//! assign \a w_str to the current string
607
UString& assign( const wchar_t* w_str );
608
//! assign the first \a num characters of \a w_str to the current string
609
UString& assign( const wchar_t* w_str, size_type num );
611
//! assign \a str to the current string (\a str is treated as a UTF-8 stream)
612
UString& assign( const std::string& str );
613
//! assign \a c_str to the current string (\a c_str is treated as a UTF-8 stream)
614
UString& assign( const char* c_str );
615
//! assign the first \a num characters of \a c_str to the current string (\a c_str is treated as a UTF-8 stream)
616
UString& assign( const char* c_str, size_type num );
619
//////////////////////////////////////////////////////////////////////////
623
//! appends \a str on to the end of the current string
624
UString& append( const UString& str );
625
//! appends \a str on to the end of the current string
626
UString& append( const code_point* str );
627
//! appends a substring of \a str starting at \a index that is \a len characters long on to the end of the current string
628
UString& append( const UString& str, size_type index, size_type len );
629
//! appends \a num characters of \a str on to the end of the current string
630
UString& append( const code_point* str, size_type num );
631
//! appends \a num repetitions of \a ch on to the end of the current string
632
UString& append( size_type num, code_point ch );
633
//! appends the sequence denoted by \a start and \a end on to the end of the current string
634
UString& append( iterator start, iterator end );
635
#if MYGUI_IS_NATIVE_WCHAR_T
636
//! appends \a num characters of \a str on to the end of the current string
637
UString& append( const wchar_t* w_str, size_type num );
638
//! appends \a num repetitions of \a ch on to the end of the current string
639
UString& append( size_type num, wchar_t ch );
641
//! appends \a num characters of \a str on to the end of the current string (UTF-8 encoding)
642
UString& append( const char* c_str, size_type num );
643
//! appends \a num repetitions of \a ch on to the end of the current string (Unicode values less than 128)
644
UString& append( size_type num, char ch );
645
//! appends \a num repetitions of \a ch on to the end of the current string (Full Unicode spectrum)
646
UString& append( size_type num, unicode_char ch );
649
//////////////////////////////////////////////////////////////////////////
653
//! inserts \a ch before the code point denoted by \a i
654
iterator insert( iterator i, const code_point& ch );
655
//! inserts \a str into the current string, at location \a index
656
UString& insert( size_type index, const UString& str );
657
//! inserts \a str into the current string, at location \a index
658
UString& insert( size_type index, const code_point* str ) {
659
mData.insert( index, str );
662
//! inserts a substring of \a str (starting at \a index2 and \a num code points long) into the current string, at location \a index1
663
UString& insert( size_type index1, const UString& str, size_type index2, size_type num );
664
//! inserts the code points denoted by \a start and \a end into the current string, before the code point specified by \a i
665
void insert( iterator i, iterator start, iterator end );
666
//! inserts \a num code points of \a str into the current string, at location \a index
667
UString& insert( size_type index, const code_point* str, size_type num );
668
#if MYGUI_IS_NATIVE_WCHAR_T
669
//! inserts \a num code points of \a str into the current string, at location \a index
670
UString& insert( size_type index, const wchar_t* w_str, size_type num );
672
//! inserts \a num code points of \a str into the current string, at location \a index
673
UString& insert( size_type index, const char* c_str, size_type num );
674
//! inserts \a num copies of \a ch into the current string, at location \a index
675
UString& insert( size_type index, size_type num, code_point ch );
676
#if MYGUI_IS_NATIVE_WCHAR_T
677
//! inserts \a num copies of \a ch into the current string, at location \a index
678
UString& insert( size_type index, size_type num, wchar_t ch );
680
//! inserts \a num copies of \a ch into the current string, at location \a index
681
UString& insert( size_type index, size_type num, char ch );
682
//! inserts \a num copies of \a ch into the current string, at location \a index
683
UString& insert( size_type index, size_type num, unicode_char ch );
684
//! inserts \a num copies of \a ch into the current string, before the code point denoted by \a i
685
void insert( iterator i, size_type num, const code_point& ch );
686
#if MYGUI_IS_NATIVE_WCHAR_T
687
//! inserts \a num copies of \a ch into the current string, before the code point denoted by \a i
688
void insert( iterator i, size_type num, const wchar_t& ch );
690
//! inserts \a num copies of \a ch into the current string, before the code point denoted by \a i
691
void insert( iterator i, size_type num, const char& ch );
692
//! inserts \a num copies of \a ch into the current string, before the code point denoted by \a i
693
void insert( iterator i, size_type num, const unicode_char& ch );
696
//////////////////////////////////////////////////////////////////////////
700
//! removes the code point pointed to by \a loc, returning an iterator to the next character
701
iterator erase( iterator loc );
702
//! removes the code points between \a start and \a end (including the one at \a start but not the one at \a end), returning an iterator to the code point after the last code point removed
703
iterator erase( iterator start, iterator end );
704
//! removes \a num code points from the current string, starting at \a index
705
UString& erase( size_type index = 0, size_type num = npos );
708
//////////////////////////////////////////////////////////////////////////
712
//! replaces up to \a num1 code points of the current string (starting at \a index1) with \a str
713
UString& replace( size_type index1, size_type num1, const UString& str );
714
//! replaces up to \a num1 code points of the current string (starting at \a index1) with up to \a num2 code points from \a str
715
UString& replace( size_type index1, size_type num1, const UString& str, size_type num2 );
716
//! replaces up to \a num1 code points of the current string (starting at \a index1) with up to \a num2 code points from \a str beginning at \a index2
717
UString& replace( size_type index1, size_type num1, const UString& str, size_type index2, size_type num2 );
718
//! replaces code points in the current string from \a start to \a end with \a num code points from \a str
719
UString& replace( iterator start, iterator end, const UString& str, size_type num = npos );
720
//! replaces up to \a num1 code points in the current string (beginning at \a index) with \c num2 copies of \c ch
721
UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
722
//! replaces the code points in the current string from \a start to \a end with \a num copies of \a ch
723
UString& replace( iterator start, iterator end, size_type num, code_point ch );
726
//////////////////////////////////////////////////////////////////////////
730
//! compare \a str to the current string
731
int compare( const UString& str ) const;
732
//! compare \a str to the current string
733
int compare( const code_point* str ) const;
734
//! compare \a str to a substring of the current string, starting at \a index for \a length characters
735
int compare( size_type index, size_type length, const UString& str ) const;
736
//! compare a substring of \a str to a substring of the current string, where \a index2 and \a length2 refer to \a str and \a index and \a length refer to the current string
737
int compare( size_type index, size_type length, const UString& str, size_type index2, size_type length2 ) const;
738
//! compare a substring of \a str to a substring of the current string, where the substring of \a str begins at zero and is \a length2 characters long, and the substring of the current string begins at \a index and is \a length characters long
739
int compare( size_type index, size_type length, const code_point* str, size_type length2 ) const;
740
#if MYGUI_IS_NATIVE_WCHAR_T
741
//! compare a substring of \a str to a substring of the current string, where the substring of \a str begins at zero and is \a length2 elements long, and the substring of the current string begins at \a index and is \a length characters long
742
int compare( size_type index, size_type length, const wchar_t* w_str, size_type length2 ) const;
744
//! compare a substring of \a str to a substring of the current string, where the substring of \a str begins at zero and is \a length2 <b>UTF-8 code points</b> long, and the substring of the current string begins at \a index and is \a length characters long
745
int compare( size_type index, size_type length, const char* c_str, size_type length2 ) const;
748
//////////////////////////////////////////////////////////////////////////
750
//!\name find & rfind
752
//! returns the index of the first occurrence of \a str within the current string, starting at \a index; returns \c UString::npos if nothing is found
753
/*! \a str is a UTF-16 encoded string, but through implicit casting can also be a UTF-8 encoded string (const char* or std::string) */
754
size_type find( const UString& str, size_type index = 0 ) const;
755
//! returns the index of the first occurrence of \a str within the current string and within \a length code points, starting at \a index; returns \c UString::npos if nothing is found
756
/*! \a cp_str is a UTF-16 encoded string */
757
size_type find( const code_point* cp_str, size_type index, size_type length ) const;
758
//! returns the index of the first occurrence of \a str within the current string and within \a length code points, starting at \a index; returns \c UString::npos if nothing is found
759
/*! \a cp_str is a UTF-8 encoded string */
760
size_type find( const char* c_str, size_type index, size_type length ) const;
761
#if MYGUI_IS_NATIVE_WCHAR_T
762
//! returns the index of the first occurrence of \a str within the current string and within \a length code points, starting at \a index; returns \c UString::npos if nothing is found
763
/*! \a cp_str is a UTF-16 encoded string */
764
size_type find( const wchar_t* w_str, size_type index, size_type length ) const;
766
//! returns the index of the first occurrence \a ch within the current string, starting at \a index; returns \c UString::npos if nothing is found
767
/*! \a ch is only capable of representing Unicode values up to U+007F (127) */
768
size_type find( char ch, size_type index = 0 ) const;
769
//! returns the index of the first occurrence \a ch within the current string, starting at \a index; returns \c UString::npos if nothing is found
770
/*! \a ch is only capable of representing Unicode values up to U+FFFF (65535) */
771
size_type find( code_point ch, size_type index = 0 ) const;
772
#if MYGUI_IS_NATIVE_WCHAR_T
773
//! returns the index of the first occurrence \a ch within the current string, starting at \a index; returns \c UString::npos if nothing is found
774
/*! \a ch is only capable of representing Unicode values up to U+FFFF (65535) */
775
size_type find( wchar_t ch, size_type index = 0 ) const;
777
//! returns the index of the first occurrence \a ch within the current string, starting at \a index; returns \c UString::npos if nothing is found
778
/*! \a ch can fully represent any Unicode character */
779
size_type find( unicode_char ch, size_type index = 0 ) const;
781
//! returns the location of the first occurrence of \a str in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
782
size_type rfind( const UString& str, size_type index = 0 ) const;
783
//! returns the location of the first occurrence of \a str in the current string, doing a reverse search from \a index, searching at most \a num characters; returns \c UString::npos if nothing is found
784
size_type rfind( const code_point* cp_str, size_type index, size_type num ) const;
785
//! returns the location of the first occurrence of \a str in the current string, doing a reverse search from \a index, searching at most \a num characters; returns \c UString::npos if nothing is found
786
size_type rfind( const char* c_str, size_type index, size_type num ) const;
787
#if MYGUI_IS_NATIVE_WCHAR_T
788
//! returns the location of the first occurrence of \a str in the current string, doing a reverse search from \a index, searching at most \a num characters; returns \c UString::npos if nothing is found
789
size_type rfind( const wchar_t* w_str, size_type index, size_type num ) const;
791
//! returns the location of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
792
size_type rfind( char ch, size_type index = 0 ) const;
793
//! returns the location of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
794
size_type rfind( code_point ch, size_type index ) const;
795
#if MYGUI_IS_NATIVE_WCHAR_T
796
//! returns the location of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
797
size_type rfind( wchar_t ch, size_type index = 0 ) const;
799
//! returns the location of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
800
size_type rfind( unicode_char ch, size_type index = 0 ) const;
803
//////////////////////////////////////////////////////////////////////////
805
//!\name find_first/last_(not)_of
807
//! Returns the index of the first character within the current string that matches \b any character in \a str, beginning the search at \a index and searching at most \a num characters; returns \c UString::npos if nothing is found
808
size_type find_first_of( const UString &str, size_type index = 0, size_type num = npos ) const;
809
//! returns the index of the first occurrence of \a ch in the current string, starting the search at \a index; returns \c UString::npos if nothing is found
810
size_type find_first_of( code_point ch, size_type index = 0 ) const;
811
//! returns the index of the first occurrence of \a ch in the current string, starting the search at \a index; returns \c UString::npos if nothing is found
812
size_type find_first_of( char ch, size_type index = 0 ) const;
813
#if MYGUI_IS_NATIVE_WCHAR_T
814
//! returns the index of the first occurrence of \a ch in the current string, starting the search at \a index; returns \c UString::npos if nothing is found
815
size_type find_first_of( wchar_t ch, size_type index = 0 ) const;
817
//! returns the index of the first occurrence of \a ch in the current string, starting the search at \a index; returns \c UString::npos if nothing is found
818
size_type find_first_of( unicode_char ch, size_type index = 0 ) const;
820
//! returns the index of the first character within the current string that does not match any character in \a str, beginning the search at \a index and searching at most \a num characters; returns \c UString::npos if nothing is found
821
size_type find_first_not_of( const UString& str, size_type index = 0, size_type num = npos ) const;
822
//! returns the index of the first character within the current string that does not match \a ch, starting the search at \a index; returns \c UString::npos if nothing is found
823
size_type find_first_not_of( code_point ch, size_type index = 0 ) const;
824
//! returns the index of the first character within the current string that does not match \a ch, starting the search at \a index; returns \c UString::npos if nothing is found
825
size_type find_first_not_of( char ch, size_type index = 0 ) const;
826
#if MYGUI_IS_NATIVE_WCHAR_T
827
//! returns the index of the first character within the current string that does not match \a ch, starting the search at \a index; returns \c UString::npos if nothing is found
828
size_type find_first_not_of( wchar_t ch, size_type index = 0 ) const;
830
//! returns the index of the first character within the current string that does not match \a ch, starting the search at \a index; returns \c UString::npos if nothing is found
831
size_type find_first_not_of( unicode_char ch, size_type index = 0 ) const;
833
//! returns the index of the first character within the current string that matches any character in \a str, doing a reverse search from \a index and searching at most \a num characters; returns \c UString::npos if nothing is found
834
size_type find_last_of( const UString& str, size_type index = npos, size_type num = npos ) const;
835
//! returns the index of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
836
size_type find_last_of( code_point ch, size_type index = npos ) const;
837
//! returns the index of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
838
size_type find_last_of( char ch, size_type index = npos ) const {
839
return find_last_of( static_cast<code_point>( ch ), index );
841
#if MYGUI_IS_NATIVE_WCHAR_T
842
//! returns the index of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
843
size_type find_last_of( wchar_t ch, size_type index = npos ) const;
845
//! returns the index of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
846
size_type find_last_of( unicode_char ch, size_type index = npos ) const;
848
//! returns the index of the last character within the current string that does not match any character in \a str, doing a reverse search from \a index; returns \c UString::npos if nothing is found
849
size_type find_last_not_of( const UString& str, size_type index = npos, size_type num = npos ) const;
850
//! returns the index of the last occurrence of a character that does not match \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
851
size_type find_last_not_of( code_point ch, size_type index = npos ) const;
852
//! returns the index of the last occurrence of a character that does not match \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
853
size_type find_last_not_of( char ch, size_type index = npos ) const;
854
#if MYGUI_IS_NATIVE_WCHAR_T
855
//! returns the index of the last occurrence of a character that does not match \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
856
size_type find_last_not_of( wchar_t ch, size_type index = npos ) const;
858
//! returns the index of the last occurrence of a character that does not match \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
859
size_type find_last_not_of( unicode_char ch, size_type index = npos ) const;
862
//////////////////////////////////////////////////////////////////////////
866
//! less than operator
867
bool operator<( const UString& right ) const;
868
//! less than or equal operator
869
bool operator<=( const UString& right ) const;
870
//! greater than operator
871
bool operator>( const UString& right ) const;
872
//! greater than or equal operator
873
bool operator>=( const UString& right ) const;
874
//! equality operator
875
bool operator==( const UString& right ) const;
876
//! inequality operator
877
bool operator!=( const UString& right ) const;
878
//! assignment operator, implicitly casts all compatible types
879
UString& operator=( const UString& s );
880
//! assignment operator
881
UString& operator=( code_point ch );
882
//! assignment operator
883
UString& operator=( char ch );
884
#if MYGUI_IS_NATIVE_WCHAR_T
885
//! assignment operator
886
UString& operator=( wchar_t ch );
888
//! assignment operator
889
UString& operator=( unicode_char ch );
890
//! code point dereference operator
891
code_point& operator[]( size_type index );
892
//! code point dereference operator
893
const code_point& operator[]( size_type index ) const;
896
//////////////////////////////////////////////////////////////////////////
898
//!\name Implicit Cast Operators
900
//! implicit cast to std::string
901
operator std::string() const;
902
//! implicit cast to std::wstring
903
operator std::wstring() const;
906
//////////////////////////////////////////////////////////////////////////
908
//!\name UTF-16 character encoding/decoding
910
//! returns \c true if \a cp does not match the signature for the lead of follow code point of a surrogate pair in a UTF-16 sequence
911
static bool _utf16_independent_char( code_point cp );
912
//! returns \c true if \a cp matches the signature of a surrogate pair lead character
913
static bool _utf16_surrogate_lead( code_point cp );
914
//! returns \c true if \a cp matches the signature of a surrogate pair following character
915
static bool _utf16_surrogate_follow( code_point cp );
916
//! estimates the number of UTF-16 code points in the sequence starting with \a cp
917
static size_t _utf16_char_length( code_point cp );
918
//! returns the number of UTF-16 code points needed to represent the given UTF-32 character \a cp
919
static size_t _utf16_char_length( unicode_char uc );
920
//! converts the given UTF-16 character buffer \a in_cp to a single UTF-32 Unicode character \a out_uc, returns the number of code points used to create the output character (2 for surrogate pairs, otherwise 1)
921
/*! This function does it's best to prevent error conditions, verifying complete
922
surrogate pairs before applying the algorithm. In the event that half of a pair
923
is found it will happily generate a value in the 0xD800 - 0xDFFF range, which is
924
normally an invalid Unicode value but we preserve them for use as sentinel values. */
925
static size_t _utf16_to_utf32( const code_point in_cp[2], unicode_char& out_uc );
926
//! writes the given UTF-32 \a uc_in to the buffer location \a out_cp using UTF-16 encoding, returns the number of code points used to encode the input (always 1 or 2)
927
/*! This function, like its counterpart, will happily create invalid UTF-16 surrogate pairs. These
928
invalid entries will be created for any value of \c in_uc that falls in the range U+D800 - U+DFFF.
929
These are generally useful as sentinel values to represent various program specific conditions.
930
\note This function will also pass through any single UTF-16 code point without modification,
931
making it a safe method of ensuring a stream that is unknown UTF-32 or UTF-16 is truly UTF-16.*/
932
static size_t _utf32_to_utf16( const unicode_char& in_uc, code_point out_cp[2] );
935
//////////////////////////////////////////////////////////////////////////
937
//!\name UTF-8 character encoding/decoding
939
//! returns \c true if \a cp is the beginning of a UTF-8 sequence
940
static bool _utf8_start_char( unsigned char cp );
941
//! estimates the number of UTF-8 code points in the sequence starting with \a cp
942
static size_t _utf8_char_length( unsigned char cp );
943
//! returns the number of UTF-8 code points needed to represent the given UTF-32 character \a cp
944
static size_t _utf8_char_length( unicode_char uc );
946
//! converts the given UTF-8 character buffer to a single UTF-32 Unicode character, returns the number of bytes used to create the output character (maximum of 6)
947
static size_t _utf8_to_utf32( const unsigned char in_cp[6], unicode_char& out_uc );
948
//! writes the given UTF-32 \a uc_in to the buffer location \a out_cp using UTF-8 encoding, returns the number of bytes used to encode the input
949
static size_t _utf32_to_utf8( const unicode_char& in_uc, unsigned char out_cp[6] );
951
//! verifies a UTF-8 stream, returning the total number of Unicode characters found
952
static size_type _verifyUTF8( const unsigned char* c_str );
953
//! verifies a UTF-8 stream, returning the total number of Unicode characters found
954
static size_type _verifyUTF8( const std::string& str );
958
//template<class ITER_TYPE> friend class _iterator;
961
//! buffer data type identifier
969
//! common constructor operations
972
///////////////////////////////////////////////////////////////////////
974
//! auto cleans the scratch buffer using the proper delete for the stored type
975
void _cleanBuffer() const;
977
//! create a std::string in the scratch buffer area
978
void _getBufferStr() const;
979
//! create a std::wstring in the scratch buffer area
980
void _getBufferWStr() const;
981
//! create a utf32string in the scratch buffer area
982
void _getBufferUTF32Str() const;
984
void _load_buffer_UTF8() const;
985
void _load_buffer_WStr() const;
986
void _load_buffer_UTF32() const;
988
mutable BufferType m_bufferType; // identifies the data type held in m_buffer
989
mutable size_t m_bufferSize; // size of the CString buffer
991
// multi-purpose buffer used everywhere we need a throw-away buffer
993
mutable void* mVoidBuffer;
994
mutable std::string* mStrBuffer;
995
mutable std::wstring* mWStrBuffer;
996
mutable utf32string* mUTF32StrBuffer;
1001
//! string addition operator \relates UString
1002
inline UString operator+( const UString& s1, const UString& s2 ) {
1003
return UString( s1 ).append( s2 );
1005
//! string addition operator \relates UString
1006
inline UString operator+( const UString& s1, UString::code_point c ) {
1007
return UString( s1 ).append( 1, c );
1009
//! string addition operator \relates UString
1010
inline UString operator+( const UString& s1, UString::unicode_char c ) {
1011
return UString( s1 ).append( 1, c );
1013
//! string addition operator \relates UString
1014
inline UString operator+( const UString& s1, char c ) {
1015
return UString( s1 ).append( 1, c );
1017
#if MYGUI_IS_NATIVE_WCHAR_T
1018
//! string addition operator \relates UString
1019
inline UString operator+( const UString& s1, wchar_t c ) {
1020
return UString( s1 ).append( 1, c );
1023
//! string addition operator \relates UString
1024
inline UString operator+( UString::code_point c, const UString& s2 ) {
1025
return UString().append( 1, c ).append( s2 );
1027
//! string addition operator \relates UString
1028
inline UString operator+( UString::unicode_char c, const UString& s2 ) {
1029
return UString().append( 1, c ).append( s2 );
1031
//! string addition operator \relates UString
1032
inline UString operator+( char c, const UString& s2 ) {
1033
return UString().append( 1, c ).append( s2 );
1035
#if MYGUI_IS_NATIVE_WCHAR_T
1036
//! string addition operator \relates UString
1037
inline UString operator+( wchar_t c, const UString& s2 ) {
1038
return UString().append( 1, c ).append( s2 );
1042
// (const) forward iterator common operators
1043
inline UString::size_type operator-( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1044
return ( left.mIter - right.mIter );
1046
inline bool operator==( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1047
return left.mIter == right.mIter;
1049
inline bool operator!=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1050
return left.mIter != right.mIter;
1052
inline bool operator<( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1053
return left.mIter < right.mIter;
1055
inline bool operator<=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1056
return left.mIter <= right.mIter;
1058
inline bool operator>( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1059
return left.mIter > right.mIter;
1061
inline bool operator>=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1062
return left.mIter >= right.mIter;
1065
// (const) reverse iterator common operators
1066
// NB: many of these operations are evaluated in reverse because this is a reverse iterator wrapping a forward iterator
1067
inline UString::size_type operator-( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1068
return ( right.mIter - left.mIter );
1070
inline bool operator==( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1071
return left.mIter == right.mIter;
1073
inline bool operator!=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1074
return left.mIter != right.mIter;
1076
inline bool operator<( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1077
return right.mIter < left.mIter;
1079
inline bool operator<=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1080
return right.mIter <= left.mIter;
1082
inline bool operator>( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1083
return right.mIter > left.mIter;
1085
inline bool operator>=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1086
return right.mIter >= left.mIter;
1089
//! std::ostream write operator \relates UString
1090
inline std::ostream& operator << ( std::ostream& os, const UString& s ) {
1091
return os << s.asUTF8();
1094
//! std::wostream write operator \relates UString
1095
inline std::wostream& operator << ( std::wostream& os, const UString& s ) {
1096
return os << s.asWStr();
1099
} // namespace MyGUI
1101
#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1102
# pragma warning (default : 4275)
1105
#endif // __MYGUI_U_STRING_H__
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
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.
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.
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.
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
25
// - Eric Shorkey (zero/zeroskill) <opengui@rightbracket.com> [January 20th, 2007]
27
#ifndef __MYGUI_U_STRING_H__
28
#define __MYGUI_U_STRING_H__
31
#include "MyGUI_Prerequest.h"
32
#include "MyGUI_Types.h"
34
// these are explained later
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)
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.
52
#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && (1300 <= MYGUI_COMP_VER && MYGUI_COMP_VER <= 1310)
54
# if defined(_DLL_CPPLIB)
58
template class _CRTIMP2 basic_string<unsigned short, char_traits<unsigned short>,
59
allocator<unsigned short> >;
61
template class _CRTIMP2 basic_string<__wchar_t, char_traits<__wchar_t>,
62
allocator<__wchar_t> >;
65
# endif // defined(_DLL_CPPLIB)
67
#endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER == 1300
73
/* READ THIS NOTICE BEFORE USING IN YOUR OWN APPLICATIONS
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/).
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.
93
=REQUIRED PREPROCESSOR MACROS=
94
This class requires two preprocessor macros to be defined in order to
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)
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.
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
118
#endif // #if defined( __WIN32__ ) || defined( _WIN32 )
119
#endif // #ifdef __STDC_ISO_10646__
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
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
133
# define MYGUI_IS_NATIVE_WCHAR_T 0
135
#elif MYGUI_PLATFORM == MYGUI_PLATFORM_SYMBIAN
136
# define MYGUI_IS_NATIVE_WCHAR_T 0
137
#else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
139
// Assumed wchar_t is natively for other compilers
140
# define MYGUI_IS_NATIVE_WCHAR_T 1
142
#endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
144
//! A UTF-16 string with implicit conversion to/from std::string and std::wstring
145
/*! This class provides a complete 1 to 1 map of most std::string functions (at least to my
146
knowledge). Implicit conversions allow this string class to work with all common C++ string
147
formats, with specialty functions defined where implicit conversion would cause potential
148
problems or is otherwise unavailable.
150
Some additional functionality is present to assist in working with characters using the
151
32-bit UTF-32 encoding. (Which is guaranteed to fit any Unicode character into a single
152
code point.) \b Note: Reverse iterators do not have this functionality due to the
153
ambiguity that surrounds working with UTF-16 in reverse. (Such as, where should an
154
iterator point to represent the beginning of a surrogate pair?)
157
\par Supported Input Types
158
The supported string types for input, and their assumed encoding schemes, are:
159
- std::string (UTF-8)
161
- std::wstring (autodetected UTF-16 / UTF-32 based on compiler)
162
- wchar_t* (autodetected UTF-16 / UTF-32 based on compiler)
166
- For additional information on UTF-16 encoding: http://en.wikipedia.org/wiki/UTF-16
167
- For additional information on UTF-8 encoding: http://en.wikipedia.org/wiki/UTF-8
168
- For additional information on UTF-32 encoding: http://en.wikipedia.org/wiki/UTF-32
170
class MYGUI_EXPORT UString {
171
// constants used in UTF-8 conversions
172
static const unsigned char _lead1 = 0xC0; //110xxxxx
173
static const unsigned char _lead1_mask = 0x1F; //00011111
174
static const unsigned char _lead2 = 0xE0; //1110xxxx
175
static const unsigned char _lead2_mask = 0x0F; //00001111
176
static const unsigned char _lead3 = 0xF0; //11110xxx
177
static const unsigned char _lead3_mask = 0x07; //00000111
178
static const unsigned char _lead4 = 0xF8; //111110xx
179
static const unsigned char _lead4_mask = 0x03; //00000011
180
static const unsigned char _lead5 = 0xFC; //1111110x
181
static const unsigned char _lead5_mask = 0x01; //00000001
182
static const unsigned char _cont = 0x80; //10xxxxxx
183
static const unsigned char _cont_mask = 0x3F; //00111111
186
//! size type used to indicate string size and character positions within the string
187
typedef size_t size_type;
188
//! the usual constant representing: not found, no limit, etc
189
static const size_type npos = static_cast<size_type>(~0);
191
//! a single 32-bit Unicode character
192
typedef uint32 unicode_char;
194
//! a single UTF-16 code point
195
typedef uint16 code_point;
197
//! value type typedef for use in iterators
198
typedef code_point value_type;
200
typedef std::basic_string<code_point> dstring; // data string
202
//! string type used for returning UTF-32 formatted data
203
typedef std::basic_string<unicode_char> utf32string;
205
//! This exception is used when invalid data streams are encountered
206
class MYGUI_EXPORT invalid_data: public std::runtime_error { /* i don't know why the beautifier is freaking out on this line */
208
//! constructor takes a string message that can be later retrieved by the what() function
209
explicit invalid_data( const std::string& _Message ): std::runtime_error( _Message ) {
210
/* The thing is, Bob, it's not that I'm lazy, it's that I just don't care. */
214
//#########################################################################
215
//! base iterator class for UString
216
class MYGUI_EXPORT _base_iterator: public std::iterator<std::random_access_iterator_tag, value_type> { /* i don't know why the beautifier is freaking out on this line */
217
friend class UString;
221
void _seekFwd( size_type c );
222
void _seekRev( size_type c );
223
void _become( const _base_iterator& i );
224
bool _test_begin() const;
225
bool _test_end() const;
226
size_type _get_index() const;
227
void _jump_to( size_type index );
229
unicode_char _getCharacter() const;
230
int _setCharacter( unicode_char uc );
235
dstring::iterator mIter;
239
//#########################################################################
241
//#########################################################################
242
class _const_fwd_iterator; // forward declaration
244
//! forward iterator for UString
245
class MYGUI_EXPORT _fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
246
friend class _const_fwd_iterator;
249
_fwd_iterator( const _fwd_iterator& i );
252
_fwd_iterator& operator++();
254
_fwd_iterator operator++( int );
257
_fwd_iterator& operator--();
259
_fwd_iterator operator--( int );
261
//! addition operator
262
_fwd_iterator operator+( difference_type n );
263
//! subtraction operator
264
_fwd_iterator operator-( difference_type n );
266
//! addition assignment operator
267
_fwd_iterator& operator+=( difference_type n );
268
//! subtraction assignment operator
269
_fwd_iterator& operator-=( difference_type n );
271
//! dereference operator
272
value_type& operator*() const;
274
//! dereference at offset operator
275
value_type& operator[]( difference_type n ) const;
277
//! advances to the next Unicode character, honoring surrogate pairs in the UTF-16 stream
278
_fwd_iterator& moveNext();
279
//! rewinds to the previous Unicode character, honoring surrogate pairs in the UTF-16 stream
280
_fwd_iterator& movePrev();
281
//! Returns the Unicode value of the character at the current position (decodes surrogate pairs if needed)
282
unicode_char getCharacter() const;
283
//! Sets the Unicode value of the character at the current position (adding a surrogate pair if needed); returns the amount of string length change caused by the operation
284
int setCharacter( unicode_char uc );
289
//#########################################################################
290
//! const forward iterator for UString
291
class MYGUI_EXPORT _const_fwd_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
293
_const_fwd_iterator();
294
_const_fwd_iterator( const _const_fwd_iterator& i );
295
_const_fwd_iterator( const _fwd_iterator& i );
298
_const_fwd_iterator& operator++();
300
_const_fwd_iterator operator++( int );
303
_const_fwd_iterator& operator--();
305
_const_fwd_iterator operator--( int );
307
//! addition operator
308
_const_fwd_iterator operator+( difference_type n );
309
//! subtraction operator
310
_const_fwd_iterator operator-( difference_type n );
312
//! addition assignment operator
313
_const_fwd_iterator& operator+=( difference_type n );
314
//! subtraction assignment operator
315
_const_fwd_iterator& operator-=( difference_type n );
317
//! dereference operator
318
const value_type& operator*() const;
320
//! dereference at offset operator
321
const value_type& operator[]( difference_type n ) const;
323
//! advances to the next Unicode character, honoring surrogate pairs in the UTF-16 stream
324
_const_fwd_iterator& moveNext();
325
//! rewinds to the previous Unicode character, honoring surrogate pairs in the UTF-16 stream
326
_const_fwd_iterator& movePrev();
327
//! Returns the Unicode value of the character at the current position (decodes surrogate pairs if needed)
328
unicode_char getCharacter() const;
330
//! difference operator
331
friend size_type operator-( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
332
//! equality operator
333
friend bool operator==( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
334
//! inequality operator
335
friend bool operator!=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
337
friend bool operator<( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
338
//! less than or equal
339
friend bool operator<=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
341
friend bool operator>( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
342
//! greater than or equal
343
friend bool operator>=( const _const_fwd_iterator& left, const _const_fwd_iterator& right );
347
//#########################################################################
349
//#########################################################################
350
class _const_rev_iterator; // forward declaration
351
//! forward iterator for UString
352
class MYGUI_EXPORT _rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
353
friend class _const_rev_iterator;
356
_rev_iterator( const _rev_iterator& i );
359
_rev_iterator& operator++();
361
_rev_iterator operator++( int );
364
_rev_iterator& operator--();
366
_rev_iterator operator--( int );
368
//! addition operator
369
_rev_iterator operator+( difference_type n );
370
//! subtraction operator
371
_rev_iterator operator-( difference_type n );
373
//! addition assignment operator
374
_rev_iterator& operator+=( difference_type n );
375
//! subtraction assignment operator
376
_rev_iterator& operator-=( difference_type n );
378
//! dereference operator
379
value_type& operator*() const;
381
//! dereference at offset operator
382
value_type& operator[]( difference_type n ) const;
384
//#########################################################################
385
//! const reverse iterator for UString
386
class MYGUI_EXPORT _const_rev_iterator: public _base_iterator { /* i don't know why the beautifier is freaking out on this line */
388
_const_rev_iterator();
389
_const_rev_iterator( const _const_rev_iterator& i );
390
_const_rev_iterator( const _rev_iterator& i );
392
_const_rev_iterator& operator++();
394
_const_rev_iterator operator++( int );
397
_const_rev_iterator& operator--();
399
_const_rev_iterator operator--( int );
401
//! addition operator
402
_const_rev_iterator operator+( difference_type n );
403
//! subtraction operator
404
_const_rev_iterator operator-( difference_type n );
406
//! addition assignment operator
407
_const_rev_iterator& operator+=( difference_type n );
408
//! subtraction assignment operator
409
_const_rev_iterator& operator-=( difference_type n );
411
//! dereference operator
412
const value_type& operator*() const;
414
//! dereference at offset operator
415
const value_type& operator[]( difference_type n ) const;
417
//! difference operator
418
friend size_type operator-( const _const_rev_iterator& left, const _const_rev_iterator& right );
419
//! equality operator
420
friend bool operator==( const _const_rev_iterator& left, const _const_rev_iterator& right );
421
//! inequality operator
422
friend bool operator!=( const _const_rev_iterator& left, const _const_rev_iterator& right );
424
friend bool operator<( const _const_rev_iterator& left, const _const_rev_iterator& right );
425
//! less than or equal
426
friend bool operator<=( const _const_rev_iterator& left, const _const_rev_iterator& right );
428
friend bool operator>( const _const_rev_iterator& left, const _const_rev_iterator& right );
429
//! greater than or equal
430
friend bool operator>=( const _const_rev_iterator& left, const _const_rev_iterator& right );
432
//#########################################################################
434
typedef _fwd_iterator iterator; //!< iterator
435
typedef _rev_iterator reverse_iterator; //!< reverse iterator
436
typedef _const_fwd_iterator const_iterator; //!< const iterator
437
typedef _const_rev_iterator const_reverse_iterator; //!< const reverse iterator
440
//!\name Constructors/Destructor
442
//! default constructor, creates an empty string
445
UString( const UString& copy );
446
//! \a length copies of \a ch
447
UString( size_type length, const code_point& ch );
448
//! duplicate of nul-terminated sequence \a str
449
UString( const code_point* str );
450
//! duplicate of \a str, \a length code points long
451
UString( const code_point* str, size_type length );
452
//! substring of \a str starting at \a index and \a length code points long
453
UString( const UString& str, size_type index, size_type length );
454
#if MYGUI_IS_NATIVE_WCHAR_T
455
//! duplicate of nul-terminated \c wchar_t array
456
UString( const wchar_t* w_str );
457
//! duplicate of \a w_str, \a length characters long
458
UString( const wchar_t* w_str, size_type length );
460
//! duplicate of \a wstr
461
UString( const std::wstring& wstr );
462
//! duplicate of nul-terminated C-string \a c_str (UTF-8 encoding)
463
UString( const char* c_str );
464
//! duplicate of \a c_str, \a length characters long (UTF-8 encoding)
465
UString( const char* c_str, size_type length );
466
//! duplicate of \a str (UTF-8 encoding)
467
UString( const std::string& str );
473
//////////////////////////////////////////////////////////////////////////
475
//!\name Utility functions
477
//! Returns the number of code points in the current string
478
size_type size() const;
479
//! Returns the number of code points in the current string
480
size_type length() const;
481
//! Returns the number of Unicode characters in the string
482
/*! Executes in linear time. */
483
size_type length_Characters() const;
484
//! returns the maximum number of UTF-16 code points that the string can hold
485
size_type max_size() const;
486
//! sets the capacity of the string to at least \a size code points
487
void reserve( size_type size );
488
//! changes the size of the string to \a size, filling in any new area with \a val
489
void resize( size_type num, const code_point& val = 0 );
490
//! exchanges the elements of the current string with those of \a from
491
void swap( UString& from );
492
//! returns \c true if the string has no elements, \c false otherwise
494
//! returns a pointer to the first character in the current string
495
const code_point* c_str() const;
496
//! returns a pointer to the first character in the current string
497
const code_point* data() const;
498
//! returns the number of elements that the string can hold before it will need to allocate more space
499
size_type capacity() const;
500
//! deletes all of the elements in the string
502
//! returns a substring of the current string, starting at \a index, and \a num characters long.
503
/*! If \a num is omitted, it will default to \c UString::npos, and the substr() function will simply return the remainder of the string starting at \a index. */
504
UString substr( size_type index, size_type num = npos ) const;
505
//! appends \a val to the end of the string
506
void push_back( unicode_char val );
507
#if MYGUI_IS_NATIVE_WCHAR_T
508
//! appends \a val to the end of the string
509
void push_back( wchar_t val );
511
//! appends \a val to the end of the string
512
/*! This can be used to push surrogate pair code points, you'll just need to push them
513
one after the other. */
514
void push_back( code_point val );
515
//! appends \a val to the end of the string
516
/*! Limited to characters under the 127 value barrier. */
517
void push_back( char val );
518
//! returns \c true if the given Unicode character \a ch is in this string
519
bool inString( unicode_char ch ) const;
522
//////////////////////////////////////////////////////////////////////////
524
//!\name Stream variations
526
//! returns the current string in UTF-8 form within a std::string
527
const std::string& asUTF8() const;
528
//! returns the current string in UTF-8 form as a nul-terminated char array
529
const char* asUTF8_c_str() const;
530
//! returns the current string in UTF-32 form within a utf32string
531
const utf32string& asUTF32() const;
532
//! returns the current string in UTF-32 form as a nul-terminated unicode_char array
533
const unicode_char* asUTF32_c_str() const;
534
//! returns the current string in the native form of std::wstring
535
const std::wstring& asWStr() const;
536
//! returns the current string in the native form of a nul-terminated wchar_t array
537
const wchar_t* asWStr_c_str() const;
540
//////////////////////////////////////////////////////////////////////////
542
//!\name Single Character Access
544
//! returns a reference to the element in the string at index \c loc
545
code_point& at( size_type loc );
546
//! returns a reference to the element in the string at index \c loc
547
const code_point& at( size_type loc ) const;
548
//! returns the data point \a loc evaluated as a UTF-32 value
549
/*! This function will will only properly decode surrogate pairs when \a loc points to the index
550
of a lead code point that is followed by a trailing code point. Evaluating the trailing code point
551
itself, or pointing to a code point that is a sentinel value (part of a broken pair) will return
552
the value of just that code point (not a valid Unicode value, but useful as a sentinel value). */
553
unicode_char getChar( size_type loc ) const;
554
//! sets the value of the character at \a loc to the Unicode value \a ch (UTF-32)
555
/*! Providing sentinel values (values between U+D800-U+DFFF) are accepted, but you should be aware
556
that you can also unwittingly create a valid surrogate pair if you don't pay attention to what you
557
are doing. \note This operation may also lengthen the string if a surrogate pair is needed to
558
represent the value given, but one is not available to replace; or alternatively shorten the string
559
if an existing surrogate pair is replaced with a character that is representable without a surrogate
560
pair. The return value will signify any lengthening or shortening performed, returning 0 if no change
561
was made, -1 if the string was shortened, or 1 if the string was lengthened. Any single call can
562
only change the string length by + or - 1. */
563
int setChar( size_type loc, unicode_char ch );
566
//////////////////////////////////////////////////////////////////////////
568
//!\name iterator acquisition
570
//! returns an iterator to the first element of the string
572
//! returns an iterator to the first element of the string
573
const_iterator begin() const;
574
//! returns an iterator just past the end of the string
576
//! returns an iterator just past the end of the string
577
const_iterator end() const;
578
//! returns a reverse iterator to the last element of the string
579
reverse_iterator rbegin();
580
//! returns a reverse iterator to the last element of the string
581
const_reverse_iterator rbegin() const;
582
//! returns a reverse iterator just past the beginning of the string
583
reverse_iterator rend();
584
//! returns a reverse iterator just past the beginning of the string
585
const_reverse_iterator rend() const;
588
//////////////////////////////////////////////////////////////////////////
592
//! gives the current string the values from \a start to \a end
593
UString& assign( iterator start, iterator end );
594
//! assign \a str to the current string
595
UString& assign( const UString& str );
596
//! assign the nul-terminated \a str to the current string
597
UString& assign( const code_point* str );
598
//! assign the first \a num characters of \a str to the current string
599
UString& assign( const code_point* str, size_type num );
600
//! assign \a len entries from \a str to the current string, starting at \a index
601
UString& assign( const UString& str, size_type index, size_type len );
602
//! assign \a num copies of \a ch to the current string
603
UString& assign( size_type num, const code_point& ch );
604
//! assign \a wstr to the current string (\a wstr is treated as a UTF-16 stream)
605
UString& assign( const std::wstring& wstr );
606
#if MYGUI_IS_NATIVE_WCHAR_T
607
//! assign \a w_str to the current string
608
UString& assign( const wchar_t* w_str );
609
//! assign the first \a num characters of \a w_str to the current string
610
UString& assign( const wchar_t* w_str, size_type num );
612
//! assign \a str to the current string (\a str is treated as a UTF-8 stream)
613
UString& assign( const std::string& str );
614
//! assign \a c_str to the current string (\a c_str is treated as a UTF-8 stream)
615
UString& assign( const char* c_str );
616
//! assign the first \a num characters of \a c_str to the current string (\a c_str is treated as a UTF-8 stream)
617
UString& assign( const char* c_str, size_type num );
620
//////////////////////////////////////////////////////////////////////////
624
//! appends \a str on to the end of the current string
625
UString& append( const UString& str );
626
//! appends \a str on to the end of the current string
627
UString& append( const code_point* str );
628
//! appends a substring of \a str starting at \a index that is \a len characters long on to the end of the current string
629
UString& append( const UString& str, size_type index, size_type len );
630
//! appends \a num characters of \a str on to the end of the current string
631
UString& append( const code_point* str, size_type num );
632
//! appends \a num repetitions of \a ch on to the end of the current string
633
UString& append( size_type num, code_point ch );
634
//! appends the sequence denoted by \a start and \a end on to the end of the current string
635
UString& append( iterator start, iterator end );
636
#if MYGUI_IS_NATIVE_WCHAR_T
637
//! appends \a num characters of \a str on to the end of the current string
638
UString& append( const wchar_t* w_str, size_type num );
639
//! appends \a num repetitions of \a ch on to the end of the current string
640
UString& append( size_type num, wchar_t ch );
642
//! appends \a num characters of \a str on to the end of the current string (UTF-8 encoding)
643
UString& append( const char* c_str, size_type num );
644
//! appends \a num repetitions of \a ch on to the end of the current string (Unicode values less than 128)
645
UString& append( size_type num, char ch );
646
//! appends \a num repetitions of \a ch on to the end of the current string (Full Unicode spectrum)
647
UString& append( size_type num, unicode_char ch );
650
//////////////////////////////////////////////////////////////////////////
654
//! inserts \a ch before the code point denoted by \a i
655
iterator insert( iterator i, const code_point& ch );
656
//! inserts \a str into the current string, at location \a index
657
UString& insert( size_type index, const UString& str );
658
//! inserts \a str into the current string, at location \a index
659
UString& insert( size_type index, const code_point* str ) {
660
mData.insert( index, str );
663
//! inserts a substring of \a str (starting at \a index2 and \a num code points long) into the current string, at location \a index1
664
UString& insert( size_type index1, const UString& str, size_type index2, size_type num );
665
//! inserts the code points denoted by \a start and \a end into the current string, before the code point specified by \a i
666
void insert( iterator i, iterator start, iterator end );
667
//! inserts \a num code points of \a str into the current string, at location \a index
668
UString& insert( size_type index, const code_point* str, size_type num );
669
#if MYGUI_IS_NATIVE_WCHAR_T
670
//! inserts \a num code points of \a str into the current string, at location \a index
671
UString& insert( size_type index, const wchar_t* w_str, size_type num );
673
//! inserts \a num code points of \a str into the current string, at location \a index
674
UString& insert( size_type index, const char* c_str, size_type num );
675
//! inserts \a num copies of \a ch into the current string, at location \a index
676
UString& insert( size_type index, size_type num, code_point ch );
677
#if MYGUI_IS_NATIVE_WCHAR_T
678
//! inserts \a num copies of \a ch into the current string, at location \a index
679
UString& insert( size_type index, size_type num, wchar_t ch );
681
//! inserts \a num copies of \a ch into the current string, at location \a index
682
UString& insert( size_type index, size_type num, char ch );
683
//! inserts \a num copies of \a ch into the current string, at location \a index
684
UString& insert( size_type index, size_type num, unicode_char ch );
685
//! inserts \a num copies of \a ch into the current string, before the code point denoted by \a i
686
void insert( iterator i, size_type num, const code_point& ch );
687
#if MYGUI_IS_NATIVE_WCHAR_T
688
//! inserts \a num copies of \a ch into the current string, before the code point denoted by \a i
689
void insert( iterator i, size_type num, const wchar_t& ch );
691
//! inserts \a num copies of \a ch into the current string, before the code point denoted by \a i
692
void insert( iterator i, size_type num, const char& ch );
693
//! inserts \a num copies of \a ch into the current string, before the code point denoted by \a i
694
void insert( iterator i, size_type num, const unicode_char& ch );
697
//////////////////////////////////////////////////////////////////////////
701
//! removes the code point pointed to by \a loc, returning an iterator to the next character
702
iterator erase( iterator loc );
703
//! removes the code points between \a start and \a end (including the one at \a start but not the one at \a end), returning an iterator to the code point after the last code point removed
704
iterator erase( iterator start, iterator end );
705
//! removes \a num code points from the current string, starting at \a index
706
UString& erase( size_type index = 0, size_type num = npos );
709
//////////////////////////////////////////////////////////////////////////
713
//! replaces up to \a num1 code points of the current string (starting at \a index1) with \a str
714
UString& replace( size_type index1, size_type num1, const UString& str );
715
//! replaces up to \a num1 code points of the current string (starting at \a index1) with up to \a num2 code points from \a str
716
UString& replace( size_type index1, size_type num1, const UString& str, size_type num2 );
717
//! replaces up to \a num1 code points of the current string (starting at \a index1) with up to \a num2 code points from \a str beginning at \a index2
718
UString& replace( size_type index1, size_type num1, const UString& str, size_type index2, size_type num2 );
719
//! replaces code points in the current string from \a start to \a end with \a num code points from \a str
720
UString& replace( iterator start, iterator end, const UString& str, size_type num = npos );
721
//! replaces up to \a num1 code points in the current string (beginning at \a index) with \c num2 copies of \c ch
722
UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
723
//! replaces the code points in the current string from \a start to \a end with \a num copies of \a ch
724
UString& replace( iterator start, iterator end, size_type num, code_point ch );
727
//////////////////////////////////////////////////////////////////////////
731
//! compare \a str to the current string
732
int compare( const UString& str ) const;
733
//! compare \a str to the current string
734
int compare( const code_point* str ) const;
735
//! compare \a str to a substring of the current string, starting at \a index for \a length characters
736
int compare( size_type index, size_type length, const UString& str ) const;
737
//! compare a substring of \a str to a substring of the current string, where \a index2 and \a length2 refer to \a str and \a index and \a length refer to the current string
738
int compare( size_type index, size_type length, const UString& str, size_type index2, size_type length2 ) const;
739
//! compare a substring of \a str to a substring of the current string, where the substring of \a str begins at zero and is \a length2 characters long, and the substring of the current string begins at \a index and is \a length characters long
740
int compare( size_type index, size_type length, const code_point* str, size_type length2 ) const;
741
#if MYGUI_IS_NATIVE_WCHAR_T
742
//! compare a substring of \a str to a substring of the current string, where the substring of \a str begins at zero and is \a length2 elements long, and the substring of the current string begins at \a index and is \a length characters long
743
int compare( size_type index, size_type length, const wchar_t* w_str, size_type length2 ) const;
745
//! compare a substring of \a str to a substring of the current string, where the substring of \a str begins at zero and is \a length2 <b>UTF-8 code points</b> long, and the substring of the current string begins at \a index and is \a length characters long
746
int compare( size_type index, size_type length, const char* c_str, size_type length2 ) const;
749
//////////////////////////////////////////////////////////////////////////
751
//!\name find & rfind
753
//! returns the index of the first occurrence of \a str within the current string, starting at \a index; returns \c UString::npos if nothing is found
754
/*! \a str is a UTF-16 encoded string, but through implicit casting can also be a UTF-8 encoded string (const char* or std::string) */
755
size_type find( const UString& str, size_type index = 0 ) const;
756
//! returns the index of the first occurrence of \a str within the current string and within \a length code points, starting at \a index; returns \c UString::npos if nothing is found
757
/*! \a cp_str is a UTF-16 encoded string */
758
size_type find( const code_point* cp_str, size_type index, size_type length ) const;
759
//! returns the index of the first occurrence of \a str within the current string and within \a length code points, starting at \a index; returns \c UString::npos if nothing is found
760
/*! \a cp_str is a UTF-8 encoded string */
761
size_type find( const char* c_str, size_type index, size_type length ) const;
762
#if MYGUI_IS_NATIVE_WCHAR_T
763
//! returns the index of the first occurrence of \a str within the current string and within \a length code points, starting at \a index; returns \c UString::npos if nothing is found
764
/*! \a cp_str is a UTF-16 encoded string */
765
size_type find( const wchar_t* w_str, size_type index, size_type length ) const;
767
//! returns the index of the first occurrence \a ch within the current string, starting at \a index; returns \c UString::npos if nothing is found
768
/*! \a ch is only capable of representing Unicode values up to U+007F (127) */
769
size_type find( char ch, size_type index = 0 ) const;
770
//! returns the index of the first occurrence \a ch within the current string, starting at \a index; returns \c UString::npos if nothing is found
771
/*! \a ch is only capable of representing Unicode values up to U+FFFF (65535) */
772
size_type find( code_point ch, size_type index = 0 ) const;
773
#if MYGUI_IS_NATIVE_WCHAR_T
774
//! returns the index of the first occurrence \a ch within the current string, starting at \a index; returns \c UString::npos if nothing is found
775
/*! \a ch is only capable of representing Unicode values up to U+FFFF (65535) */
776
size_type find( wchar_t ch, size_type index = 0 ) const;
778
//! returns the index of the first occurrence \a ch within the current string, starting at \a index; returns \c UString::npos if nothing is found
779
/*! \a ch can fully represent any Unicode character */
780
size_type find( unicode_char ch, size_type index = 0 ) const;
782
//! returns the location of the first occurrence of \a str in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
783
size_type rfind( const UString& str, size_type index = 0 ) const;
784
//! returns the location of the first occurrence of \a str in the current string, doing a reverse search from \a index, searching at most \a num characters; returns \c UString::npos if nothing is found
785
size_type rfind( const code_point* cp_str, size_type index, size_type num ) const;
786
//! returns the location of the first occurrence of \a str in the current string, doing a reverse search from \a index, searching at most \a num characters; returns \c UString::npos if nothing is found
787
size_type rfind( const char* c_str, size_type index, size_type num ) const;
788
#if MYGUI_IS_NATIVE_WCHAR_T
789
//! returns the location of the first occurrence of \a str in the current string, doing a reverse search from \a index, searching at most \a num characters; returns \c UString::npos if nothing is found
790
size_type rfind( const wchar_t* w_str, size_type index, size_type num ) const;
792
//! returns the location of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
793
size_type rfind( char ch, size_type index = 0 ) const;
794
//! returns the location of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
795
size_type rfind( code_point ch, size_type index ) const;
796
#if MYGUI_IS_NATIVE_WCHAR_T
797
//! returns the location of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
798
size_type rfind( wchar_t ch, size_type index = 0 ) const;
800
//! returns the location of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
801
size_type rfind( unicode_char ch, size_type index = 0 ) const;
804
//////////////////////////////////////////////////////////////////////////
806
//!\name find_first/last_(not)_of
808
//! Returns the index of the first character within the current string that matches \b any character in \a str, beginning the search at \a index and searching at most \a num characters; returns \c UString::npos if nothing is found
809
size_type find_first_of( const UString &str, size_type index = 0, size_type num = npos ) const;
810
//! returns the index of the first occurrence of \a ch in the current string, starting the search at \a index; returns \c UString::npos if nothing is found
811
size_type find_first_of( code_point ch, size_type index = 0 ) const;
812
//! returns the index of the first occurrence of \a ch in the current string, starting the search at \a index; returns \c UString::npos if nothing is found
813
size_type find_first_of( char ch, size_type index = 0 ) const;
814
#if MYGUI_IS_NATIVE_WCHAR_T
815
//! returns the index of the first occurrence of \a ch in the current string, starting the search at \a index; returns \c UString::npos if nothing is found
816
size_type find_first_of( wchar_t ch, size_type index = 0 ) const;
818
//! returns the index of the first occurrence of \a ch in the current string, starting the search at \a index; returns \c UString::npos if nothing is found
819
size_type find_first_of( unicode_char ch, size_type index = 0 ) const;
821
//! returns the index of the first character within the current string that does not match any character in \a str, beginning the search at \a index and searching at most \a num characters; returns \c UString::npos if nothing is found
822
size_type find_first_not_of( const UString& str, size_type index = 0, size_type num = npos ) const;
823
//! returns the index of the first character within the current string that does not match \a ch, starting the search at \a index; returns \c UString::npos if nothing is found
824
size_type find_first_not_of( code_point ch, size_type index = 0 ) const;
825
//! returns the index of the first character within the current string that does not match \a ch, starting the search at \a index; returns \c UString::npos if nothing is found
826
size_type find_first_not_of( char ch, size_type index = 0 ) const;
827
#if MYGUI_IS_NATIVE_WCHAR_T
828
//! returns the index of the first character within the current string that does not match \a ch, starting the search at \a index; returns \c UString::npos if nothing is found
829
size_type find_first_not_of( wchar_t ch, size_type index = 0 ) const;
831
//! returns the index of the first character within the current string that does not match \a ch, starting the search at \a index; returns \c UString::npos if nothing is found
832
size_type find_first_not_of( unicode_char ch, size_type index = 0 ) const;
834
//! returns the index of the first character within the current string that matches any character in \a str, doing a reverse search from \a index and searching at most \a num characters; returns \c UString::npos if nothing is found
835
size_type find_last_of( const UString& str, size_type index = npos, size_type num = npos ) const;
836
//! returns the index of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
837
size_type find_last_of( code_point ch, size_type index = npos ) const;
838
//! returns the index of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
839
size_type find_last_of( char ch, size_type index = npos ) const {
840
return find_last_of( static_cast<code_point>( ch ), index );
842
#if MYGUI_IS_NATIVE_WCHAR_T
843
//! returns the index of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
844
size_type find_last_of( wchar_t ch, size_type index = npos ) const;
846
//! returns the index of the first occurrence of \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
847
size_type find_last_of( unicode_char ch, size_type index = npos ) const;
849
//! returns the index of the last character within the current string that does not match any character in \a str, doing a reverse search from \a index; returns \c UString::npos if nothing is found
850
size_type find_last_not_of( const UString& str, size_type index = npos, size_type num = npos ) const;
851
//! returns the index of the last occurrence of a character that does not match \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
852
size_type find_last_not_of( code_point ch, size_type index = npos ) const;
853
//! returns the index of the last occurrence of a character that does not match \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
854
size_type find_last_not_of( char ch, size_type index = npos ) const;
855
#if MYGUI_IS_NATIVE_WCHAR_T
856
//! returns the index of the last occurrence of a character that does not match \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
857
size_type find_last_not_of( wchar_t ch, size_type index = npos ) const;
859
//! returns the index of the last occurrence of a character that does not match \a ch in the current string, doing a reverse search from \a index; returns \c UString::npos if nothing is found
860
size_type find_last_not_of( unicode_char ch, size_type index = npos ) const;
863
//////////////////////////////////////////////////////////////////////////
867
//! less than operator
868
bool operator<( const UString& right ) const;
869
//! less than or equal operator
870
bool operator<=( const UString& right ) const;
871
//! greater than operator
872
bool operator>( const UString& right ) const;
873
//! greater than or equal operator
874
bool operator>=( const UString& right ) const;
875
//! equality operator
876
bool operator==( const UString& right ) const;
877
//! inequality operator
878
bool operator!=( const UString& right ) const;
879
//! assignment operator, implicitly casts all compatible types
880
UString& operator=( const UString& s );
881
//! assignment operator
882
UString& operator=( code_point ch );
883
//! assignment operator
884
UString& operator=( char ch );
885
#if MYGUI_IS_NATIVE_WCHAR_T
886
//! assignment operator
887
UString& operator=( wchar_t ch );
889
//! assignment operator
890
UString& operator=( unicode_char ch );
891
//! code point dereference operator
892
code_point& operator[]( size_type index );
893
//! code point dereference operator
894
const code_point& operator[]( size_type index ) const;
897
//////////////////////////////////////////////////////////////////////////
899
//!\name Implicit Cast Operators
901
//! implicit cast to std::string
902
operator std::string() const;
903
//! implicit cast to std::wstring
904
operator std::wstring() const;
907
//////////////////////////////////////////////////////////////////////////
909
//!\name UTF-16 character encoding/decoding
911
//! returns \c true if \a cp does not match the signature for the lead of follow code point of a surrogate pair in a UTF-16 sequence
912
static bool _utf16_independent_char( code_point cp );
913
//! returns \c true if \a cp matches the signature of a surrogate pair lead character
914
static bool _utf16_surrogate_lead( code_point cp );
915
//! returns \c true if \a cp matches the signature of a surrogate pair following character
916
static bool _utf16_surrogate_follow( code_point cp );
917
//! estimates the number of UTF-16 code points in the sequence starting with \a cp
918
static size_t _utf16_char_length( code_point cp );
919
//! returns the number of UTF-16 code points needed to represent the given UTF-32 character \a cp
920
static size_t _utf16_char_length( unicode_char uc );
921
//! converts the given UTF-16 character buffer \a in_cp to a single UTF-32 Unicode character \a out_uc, returns the number of code points used to create the output character (2 for surrogate pairs, otherwise 1)
922
/*! This function does it's best to prevent error conditions, verifying complete
923
surrogate pairs before applying the algorithm. In the event that half of a pair
924
is found it will happily generate a value in the 0xD800 - 0xDFFF range, which is
925
normally an invalid Unicode value but we preserve them for use as sentinel values. */
926
static size_t _utf16_to_utf32( const code_point in_cp[2], unicode_char& out_uc );
927
//! writes the given UTF-32 \a uc_in to the buffer location \a out_cp using UTF-16 encoding, returns the number of code points used to encode the input (always 1 or 2)
928
/*! This function, like its counterpart, will happily create invalid UTF-16 surrogate pairs. These
929
invalid entries will be created for any value of \c in_uc that falls in the range U+D800 - U+DFFF.
930
These are generally useful as sentinel values to represent various program specific conditions.
931
\note This function will also pass through any single UTF-16 code point without modification,
932
making it a safe method of ensuring a stream that is unknown UTF-32 or UTF-16 is truly UTF-16.*/
933
static size_t _utf32_to_utf16( const unicode_char& in_uc, code_point out_cp[2] );
936
//////////////////////////////////////////////////////////////////////////
938
//!\name UTF-8 character encoding/decoding
940
//! returns \c true if \a cp is the beginning of a UTF-8 sequence
941
static bool _utf8_start_char( unsigned char cp );
942
//! estimates the number of UTF-8 code points in the sequence starting with \a cp
943
static size_t _utf8_char_length( unsigned char cp );
944
//! returns the number of UTF-8 code points needed to represent the given UTF-32 character \a cp
945
static size_t _utf8_char_length( unicode_char uc );
947
//! converts the given UTF-8 character buffer to a single UTF-32 Unicode character, returns the number of bytes used to create the output character (maximum of 6)
948
static size_t _utf8_to_utf32( const unsigned char in_cp[6], unicode_char& out_uc );
949
//! writes the given UTF-32 \a uc_in to the buffer location \a out_cp using UTF-8 encoding, returns the number of bytes used to encode the input
950
static size_t _utf32_to_utf8( const unicode_char& in_uc, unsigned char out_cp[6] );
952
//! verifies a UTF-8 stream, returning the total number of Unicode characters found
953
static size_type _verifyUTF8( const unsigned char* c_str );
954
//! verifies a UTF-8 stream, returning the total number of Unicode characters found
955
static size_type _verifyUTF8( const std::string& str );
959
//template<class ITER_TYPE> friend class _iterator;
962
//! buffer data type identifier
970
//! common constructor operations
973
///////////////////////////////////////////////////////////////////////
975
//! auto cleans the scratch buffer using the proper delete for the stored type
976
void _cleanBuffer() const;
978
//! create a std::string in the scratch buffer area
979
void _getBufferStr() const;
980
//! create a std::wstring in the scratch buffer area
981
void _getBufferWStr() const;
982
//! create a utf32string in the scratch buffer area
983
void _getBufferUTF32Str() const;
985
void _load_buffer_UTF8() const;
986
void _load_buffer_WStr() const;
987
void _load_buffer_UTF32() const;
989
mutable BufferType m_bufferType; // identifies the data type held in m_buffer
990
mutable size_t m_bufferSize; // size of the CString buffer
992
// multi-purpose buffer used everywhere we need a throw-away buffer
994
mutable void* mVoidBuffer;
995
mutable std::string* mStrBuffer;
996
mutable std::wstring* mWStrBuffer;
997
mutable utf32string* mUTF32StrBuffer;
1002
//! string addition operator \relates UString
1003
inline UString operator+( const UString& s1, const UString& s2 ) {
1004
return UString( s1 ).append( s2 );
1006
//! string addition operator \relates UString
1007
inline UString operator+( const UString& s1, UString::code_point c ) {
1008
return UString( s1 ).append( 1, c );
1010
//! string addition operator \relates UString
1011
inline UString operator+( const UString& s1, UString::unicode_char c ) {
1012
return UString( s1 ).append( 1, c );
1014
//! string addition operator \relates UString
1015
inline UString operator+( const UString& s1, char c ) {
1016
return UString( s1 ).append( 1, c );
1018
#if MYGUI_IS_NATIVE_WCHAR_T
1019
//! string addition operator \relates UString
1020
inline UString operator+( const UString& s1, wchar_t c ) {
1021
return UString( s1 ).append( 1, c );
1024
//! string addition operator \relates UString
1025
inline UString operator+( UString::code_point c, const UString& s2 ) {
1026
return UString().append( 1, c ).append( s2 );
1028
//! string addition operator \relates UString
1029
inline UString operator+( UString::unicode_char c, const UString& s2 ) {
1030
return UString().append( 1, c ).append( s2 );
1032
//! string addition operator \relates UString
1033
inline UString operator+( char c, const UString& s2 ) {
1034
return UString().append( 1, c ).append( s2 );
1036
#if MYGUI_IS_NATIVE_WCHAR_T
1037
//! string addition operator \relates UString
1038
inline UString operator+( wchar_t c, const UString& s2 ) {
1039
return UString().append( 1, c ).append( s2 );
1043
// (const) forward iterator common operators
1044
inline UString::size_type operator-( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1045
return ( left.mIter - right.mIter );
1047
inline bool operator==( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1048
return left.mIter == right.mIter;
1050
inline bool operator!=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1051
return left.mIter != right.mIter;
1053
inline bool operator<( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1054
return left.mIter < right.mIter;
1056
inline bool operator<=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1057
return left.mIter <= right.mIter;
1059
inline bool operator>( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1060
return left.mIter > right.mIter;
1062
inline bool operator>=( const UString::_const_fwd_iterator& left, const UString::_const_fwd_iterator& right ) {
1063
return left.mIter >= right.mIter;
1066
// (const) reverse iterator common operators
1067
// NB: many of these operations are evaluated in reverse because this is a reverse iterator wrapping a forward iterator
1068
inline UString::size_type operator-( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1069
return ( right.mIter - left.mIter );
1071
inline bool operator==( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1072
return left.mIter == right.mIter;
1074
inline bool operator!=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1075
return left.mIter != right.mIter;
1077
inline bool operator<( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1078
return right.mIter < left.mIter;
1080
inline bool operator<=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1081
return right.mIter <= left.mIter;
1083
inline bool operator>( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1084
return right.mIter > left.mIter;
1086
inline bool operator>=( const UString::_const_rev_iterator& left, const UString::_const_rev_iterator& right ) {
1087
return right.mIter >= left.mIter;
1090
//! std::ostream write operator \relates UString
1091
inline std::ostream& operator << ( std::ostream& os, const UString& s ) {
1092
return os << s.asUTF8();
1095
//! std::wostream write operator \relates UString
1096
inline std::wostream& operator << ( std::wostream& os, const UString& s ) {
1097
return os << s.asWStr();
1100
} // namespace MyGUI
1102
#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1103
# pragma warning (pop)
1106
#endif // __MYGUI_U_STRING_H__