3 // Purpose: 32-bit string (UCS-4)
4 // Author: Robert Roebling
5 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_USTRING_H_
11 #define _WX_USTRING_H_
14 #include "wx/string.h"
18 #if SIZEOF_WCHAR_T == 2
19 typedef wxWCharBuffer wxU16CharBuffer
;
20 typedef wxScopedWCharBuffer wxScopedU16CharBuffer
;
22 typedef wxCharTypeBuffer
<wxChar16
> wxU16CharBuffer
;
23 typedef wxScopedCharTypeBuffer
<wxChar16
> wxScopedU16CharBuffer
;
26 #if SIZEOF_WCHAR_T == 4
27 typedef wxWCharBuffer wxU32CharBuffer
;
28 typedef wxScopedWCharBuffer wxScopedU32CharBuffer
;
30 typedef wxCharTypeBuffer
<wxChar32
> wxU32CharBuffer
;
31 typedef wxScopedCharTypeBuffer
<wxChar32
> wxScopedU32CharBuffer
;
35 // "non dll-interface class 'std::basic_string<wxChar32>' used as base
36 // interface for dll-interface class 'wxString'" -- this is OK in our case
37 // (and warning is unavoidable anyhow)
39 #pragma warning(disable:4275)
42 class WXDLLIMPEXP_BASE wxUString
: public std::basic_string
<wxChar32
>
47 wxUString( const wxChar32
*str
) { assign(str
); }
48 wxUString( const wxUString
&str
) { assign(str
); }
49 wxUString( const wxScopedU32CharBuffer
&buf
) { assign(buf
); }
51 wxUString( const char *str
) { assign(str
); }
52 wxUString( const wxScopedCharBuffer
&buf
) { assign(buf
); }
53 wxUString( const char *str
, const wxMBConv
&conv
) { assign(str
,conv
); }
54 wxUString( const wxScopedCharBuffer
&buf
, const wxMBConv
&conv
) { assign(buf
,conv
); }
56 wxUString( const wxChar16
*str
) { assign(str
); }
57 wxUString( const wxScopedU16CharBuffer
&buf
) { assign(buf
); }
59 wxUString( const wxCStrData
*cstr
) { assign(cstr
); }
60 wxUString( const wxString
&str
) { assign(str
); }
62 wxUString( char ch
) { assign(ch
); }
63 wxUString( wxChar16 ch
) { assign(ch
); }
64 wxUString( wxChar32 ch
) { assign(ch
); }
65 wxUString( wxUniChar ch
) { assign(ch
); }
66 wxUString( wxUniCharRef ch
) { assign(ch
); }
67 wxUString( size_type n
, char ch
) { assign(n
,ch
); }
68 wxUString( size_type n
, wxChar16 ch
) { assign(n
,ch
); }
69 wxUString( size_type n
, wxChar32 ch
) { assign(n
,ch
); }
70 wxUString( size_type n
, wxUniChar ch
) { assign(n
,ch
); }
71 wxUString( size_type n
, wxUniCharRef ch
) { assign(n
,ch
); }
73 // static construction
75 static wxUString
FromAscii( const char *str
, size_type n
)
78 ret
.assignFromAscii( str
, n
);
82 static wxUString
FromAscii( const char *str
)
85 ret
.assignFromAscii( str
);
89 static wxUString
FromUTF8( const char *str
, size_type n
)
92 ret
.assignFromUTF8( str
, n
);
96 static wxUString
FromUTF8( const char *str
)
99 ret
.assignFromUTF8( str
);
103 static wxUString
FromUTF16( const wxChar16
*str
, size_type n
)
106 ret
.assignFromUTF16( str
, n
);
110 static wxUString
FromUTF16( const wxChar16
*str
)
113 ret
.assignFromUTF16( str
);
117 // assign from encoding
119 wxUString
&assignFromAscii( const char *str
);
120 wxUString
&assignFromAscii( const char *str
, size_type n
);
121 wxUString
&assignFromUTF8( const char *str
);
122 wxUString
&assignFromUTF8( const char *str
, size_type n
);
123 wxUString
&assignFromUTF16( const wxChar16
* str
);
124 wxUString
&assignFromUTF16( const wxChar16
* str
, size_type n
);
125 wxUString
&assignFromCString( const char* str
);
126 wxUString
&assignFromCString( const char* str
, const wxMBConv
&conv
);
130 wxScopedCharBuffer
utf8_str() const;
131 wxScopedU16CharBuffer
utf16_str() const;
133 #if SIZEOF_WCHAR_T == 2
134 wxScopedWCharBuffer
wc_str() const
139 wchar_t *wc_str() const
141 return (wchar_t*) c_str();
145 operator wxString() const
147 #if wxUSE_UNICODE_UTF8
148 return wxString::FromUTF8( utf8_str() );
150 #if SIZEOF_WCHAR_T == 2
151 return wxString( utf16_str() );
153 return wxString( c_str() );
158 #if wxUSE_UNICODE_UTF8
159 wxScopedCharBuffer
wx_str()
164 #if SIZEOF_WCHAR_T == 2
165 wxScopedWCharBuffer
wx_str()
170 const wchar_t* wx_str()
179 wxUString
&assign( const wxChar32
* str
)
181 std::basic_string
<wxChar32
> *base
= this;
182 return (wxUString
&) base
->assign( str
);
185 wxUString
&assign( const wxChar32
* str
, size_type n
)
187 std::basic_string
<wxChar32
> *base
= this;
188 return (wxUString
&) base
->assign( str
, n
);
191 wxUString
&assign( const wxUString
&str
)
193 std::basic_string
<wxChar32
> *base
= this;
194 return (wxUString
&) base
->assign( str
);
197 wxUString
&assign( const wxUString
&str
, size_type pos
, size_type n
)
199 std::basic_string
<wxChar32
> *base
= this;
200 return (wxUString
&) base
->assign( str
, pos
, n
);
203 wxUString
&assign( wxChar32 ch
)
205 std::basic_string
<wxChar32
> *base
= this;
206 return (wxUString
&) base
->assign( (size_type
) 1, ch
);
209 wxUString
&assign( size_type n
, wxChar32 ch
)
211 std::basic_string
<wxChar32
> *base
= this;
212 return (wxUString
&) base
->assign( n
, ch
);
215 wxUString
&assign( const wxScopedU32CharBuffer
&buf
)
217 return assign( buf
.data() );
220 wxUString
&assign( const char *str
)
222 return assignFromCString( str
);
225 wxUString
&assign( const wxScopedCharBuffer
&buf
)
227 return assignFromCString( buf
.data() );
230 wxUString
&assign( const char *str
, const wxMBConv
&conv
)
232 return assignFromCString( str
, conv
);
235 wxUString
&assign( const wxScopedCharBuffer
&buf
, const wxMBConv
&conv
)
237 return assignFromCString( buf
.data(), conv
);
240 wxUString
&assign( const wxChar16
*str
)
242 return assignFromUTF16( str
);
245 wxUString
&assign( const wxScopedU16CharBuffer
&buf
)
247 return assignFromUTF16( buf
.data() );
250 wxUString
&assign( const wxCStrData
*cstr
)
252 #if SIZEOF_WCHAR_T == 2
253 return assignFromUTF16( cstr
->AsWChar() );
255 return assign( cstr
->AsWChar() );
259 wxUString
&assign( const wxString
&str
)
261 #if wxUSE_UNICODE_UTF8
262 return assignFromUTF8( str
.wx_str() );
264 #if SIZEOF_WCHAR_T == 2
265 return assignFromUTF16( str
.wc_str() );
267 return assign( str
.wc_str() );
272 wxUString
&assign( char ch
)
277 return assignFromCString( buf
);
280 wxUString
&assign( size_type n
, char ch
)
282 wxCharBuffer
buffer(n
);
283 char *p
= buffer
.data();
285 for (i
= 0; i
< n
; i
++)
290 return assignFromCString( buffer
.data() );
293 wxUString
&assign( wxChar16 ch
)
298 return assignFromUTF16( buf
);
301 wxUString
&assign( size_type n
, wxChar16 ch
)
303 wxU16CharBuffer
buffer(n
);
304 wxChar16
*p
= buffer
.data();
306 for (i
= 0; i
< n
; i
++)
311 return assignFromUTF16( buffer
.data() );
314 wxUString
&assign( wxUniChar ch
)
316 return assign( (wxChar32
) ch
.GetValue() );
319 wxUString
&assign( size_type n
, wxUniChar ch
)
321 return assign( n
, (wxChar32
) ch
.GetValue() );
324 wxUString
&assign( wxUniCharRef ch
)
326 return assign( (wxChar32
) ch
.GetValue() );
329 wxUString
&assign( size_type n
, wxUniCharRef ch
)
331 return assign( n
, (wxChar32
) ch
.GetValue() );
334 // append [STL overload]
336 wxUString
&append( const wxUString
&s
)
338 std::basic_string
<wxChar32
> *base
= this;
339 return (wxUString
&) base
->append( s
);
342 wxUString
&append( const wxUString
&s
, size_type pos
, size_type n
)
344 std::basic_string
<wxChar32
> *base
= this;
345 return (wxUString
&) base
->append( s
, pos
, n
);
348 wxUString
&append( const wxChar32
* s
)
350 std::basic_string
<wxChar32
> *base
= this;
351 return (wxUString
&) base
->append( s
);
354 wxUString
&append( const wxChar32
* s
, size_type n
)
356 std::basic_string
<wxChar32
> *base
= this;
357 return (wxUString
&) base
->append( s
, n
);
360 wxUString
&append( size_type n
, wxChar32 c
)
362 std::basic_string
<wxChar32
> *base
= this;
363 return (wxUString
&) base
->append( n
, c
);
366 wxUString
&append( wxChar32 c
)
368 std::basic_string
<wxChar32
> *base
= this;
369 return (wxUString
&) base
->append( 1, c
);
372 // append [wx overload]
374 wxUString
&append( const wxScopedU16CharBuffer
&buf
)
376 return append( buf
.data() );
379 wxUString
&append( const wxScopedU32CharBuffer
&buf
)
381 return append( buf
.data() );
384 wxUString
&append( const char *str
)
386 return append( wxUString( str
) );
389 wxUString
&append( const wxScopedCharBuffer
&buf
)
391 return append( wxUString( buf
) );
394 wxUString
&append( const wxChar16
*str
)
396 return append( wxUString( str
) );
399 wxUString
&append( const wxString
&str
)
401 return append( wxUString( str
) );
404 wxUString
&append( const wxCStrData
*cstr
)
406 return append( wxUString( cstr
) );
409 wxUString
&append( char ch
)
414 return append( buf
);
417 wxUString
&append( wxChar16 ch
)
422 return append( buf
);
425 wxUString
&append( wxUniChar ch
)
427 return append( (size_type
) 1, (wxChar32
) ch
.GetValue() );
430 wxUString
&append( wxUniCharRef ch
)
432 return append( (size_type
) 1, (wxChar32
) ch
.GetValue() );
436 // insert [STL overloads]
438 wxUString
&insert( size_type pos
, const wxUString
&s
)
440 std::basic_string
<wxChar32
> *base
= this;
441 return (wxUString
&) base
->insert( pos
, s
);
444 wxUString
&insert( size_type pos
, const wxUString
&s
, size_type pos1
, size_type n
)
446 std::basic_string
<wxChar32
> *base
= this;
447 return (wxUString
&) base
->insert( pos
, s
, pos1
, n
);
450 wxUString
&insert( size_type pos
, const wxChar32
*s
)
452 std::basic_string
<wxChar32
> *base
= this;
453 return (wxUString
&) base
->insert( pos
, s
);
456 wxUString
&insert( size_type pos
, const wxChar32
*s
, size_type n
)
458 std::basic_string
<wxChar32
> *base
= this;
459 return (wxUString
&) base
->insert( pos
, s
, n
);
462 wxUString
&insert( size_type pos
, size_type n
, wxChar32 c
)
464 std::basic_string
<wxChar32
> *base
= this;
465 return (wxUString
&) base
->insert( pos
, n
, c
);
469 // insert [STL overloads]
471 wxUString
&insert( size_type n
, const char *s
)
473 return insert( n
, wxUString( s
) );
476 wxUString
&insert( size_type n
, const wxChar16
*s
)
478 return insert( n
, wxUString( s
) );
481 wxUString
&insert( size_type n
, const wxScopedCharBuffer
&buf
)
483 return insert( n
, wxUString( buf
) );
486 wxUString
&insert( size_type n
, const wxScopedU16CharBuffer
&buf
)
488 return insert( n
, wxUString( buf
) );
491 wxUString
&insert( size_type n
, const wxScopedU32CharBuffer
&buf
)
493 return insert( n
, buf
.data() );
496 wxUString
&insert( size_type n
, const wxString
&s
)
498 return insert( n
, wxUString( s
) );
501 wxUString
&insert( size_type n
, const wxCStrData
*cstr
)
503 return insert( n
, wxUString( cstr
) );
506 wxUString
&insert( size_type n
, char ch
)
511 return insert( n
, buf
);
514 wxUString
&insert( size_type n
, wchar_t ch
)
519 return insert( n
, buf
);
524 iterator
insert( iterator it
, wxChar32 ch
)
526 std::basic_string
<wxChar32
> *base
= this;
527 return base
->insert( it
, ch
);
530 void insert(iterator it
, const_iterator first
, const_iterator last
)
532 std::basic_string
<wxChar32
> *base
= this;
533 base
->insert( it
, first
, last
);
538 wxUString
& operator=(const wxUString
& s
)
539 { return assign( s
); }
540 wxUString
& operator=(const wxString
& s
)
541 { return assign( s
); }
542 wxUString
& operator=(const wxCStrData
* s
)
543 { return assign( s
); }
544 wxUString
& operator=(const char *s
)
545 { return assign( s
); }
546 wxUString
& operator=(const wxChar16
*s
)
547 { return assign( s
); }
548 wxUString
& operator=(const wxChar32
*s
)
549 { return assign( s
); }
550 wxUString
& operator=(const wxScopedCharBuffer
&s
)
551 { return assign( s
); }
552 wxUString
& operator=(const wxScopedU16CharBuffer
&s
)
553 { return assign( s
); }
554 wxUString
& operator=(const wxScopedU32CharBuffer
&s
)
555 { return assign( s
); }
556 wxUString
& operator=(const char ch
)
557 { return assign( ch
); }
558 wxUString
& operator=(const wxChar16 ch
)
559 { return assign( ch
); }
560 wxUString
& operator=(const wxChar32 ch
)
561 { return assign( ch
); }
562 wxUString
& operator=(const wxUniChar ch
)
563 { return assign( ch
); }
564 wxUString
& operator=(const wxUniCharRef ch
)
565 { return assign( ch
); }
568 wxUString
& operator+=(const wxUString
& s
)
569 { return append( s
); }
570 wxUString
& operator+=(const wxString
& s
)
571 { return append( s
); }
572 wxUString
& operator+=(const wxCStrData
* s
)
573 { return append( s
); }
574 wxUString
& operator+=(const char *s
)
575 { return append( s
); }
576 wxUString
& operator+=(const wxChar16
*s
)
577 { return append( s
); }
578 wxUString
& operator+=(const wxChar32
*s
)
579 { return append( s
); }
580 wxUString
& operator+=(const wxScopedCharBuffer
&s
)
581 { return append( s
); }
582 wxUString
& operator+=(const wxScopedU16CharBuffer
&s
)
583 { return append( s
); }
584 wxUString
& operator+=(const wxScopedU32CharBuffer
&s
)
585 { return append( s
); }
586 wxUString
& operator+=(const char ch
)
587 { return append( ch
); }
588 wxUString
& operator+=(const wxChar16 ch
)
589 { return append( ch
); }
590 wxUString
& operator+=(const wxChar32 ch
)
591 { return append( ch
); }
592 wxUString
& operator+=(const wxUniChar ch
)
593 { return append( ch
); }
594 wxUString
& operator+=(const wxUniCharRef ch
)
595 { return append( ch
); }
603 inline wxUString
operator+(const wxUString
&s1
, const wxUString
&s2
)
604 { wxUString
ret( s1
); ret
.append( s2
); return ret
; }
605 inline wxUString
operator+(const wxUString
&s1
, const char *s2
)
606 { return s1
+ wxUString(s2
); }
607 inline wxUString
operator+(const wxUString
&s1
, const wxString
&s2
)
608 { return s1
+ wxUString(s2
); }
609 inline wxUString
operator+(const wxUString
&s1
, const wxCStrData
*s2
)
610 { return s1
+ wxUString(s2
); }
611 inline wxUString
operator+(const wxUString
&s1
, const wxChar16
* s2
)
612 { return s1
+ wxUString(s2
); }
613 inline wxUString
operator+(const wxUString
&s1
, const wxChar32
*s2
)
614 { return s1
+ wxUString(s2
); }
615 inline wxUString
operator+(const wxUString
&s1
, const wxScopedCharBuffer
&s2
)
616 { return s1
+ wxUString(s2
); }
617 inline wxUString
operator+(const wxUString
&s1
, const wxScopedU16CharBuffer
&s2
)
618 { return s1
+ wxUString(s2
); }
619 inline wxUString
operator+(const wxUString
&s1
, const wxScopedU32CharBuffer
&s2
)
620 { return s1
+ wxUString(s2
); }
621 inline wxUString
operator+(const wxUString
&s1
, char s2
)
622 { return s1
+ wxUString(s2
); }
623 inline wxUString
operator+(const wxUString
&s1
, wxChar32 s2
)
624 { wxUString
ret( s1
); ret
.append( s2
); return ret
; }
625 inline wxUString
operator+(const wxUString
&s1
, wxChar16 s2
)
626 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
); return ret
; }
627 inline wxUString
operator+(const wxUString
&s1
, wxUniChar s2
)
628 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
.GetValue() ); return ret
; }
629 inline wxUString
operator+(const wxUString
&s1
, wxUniCharRef s2
)
630 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
.GetValue() ); return ret
; }
632 inline wxUString
operator+(const char *s1
, const wxUString
&s2
)
633 { return wxUString(s1
) + s2
; }
634 inline wxUString
operator+(const wxString
&s1
, const wxUString
&s2
)
635 { return wxUString(s1
) + s2
; }
636 inline wxUString
operator+(const wxCStrData
*s1
, const wxUString
&s2
)
637 { return wxUString(s1
) + s2
; }
638 inline wxUString
operator+(const wxChar16
* s1
, const wxUString
&s2
)
639 { return wxUString(s1
) + s2
; }
640 inline wxUString
operator+(const wxChar32
*s1
, const wxUString
&s2
)
641 { return wxUString(s1
) + s2
; }
642 inline wxUString
operator+(const wxScopedCharBuffer
&s1
, const wxUString
&s2
)
643 { return wxUString(s1
) + s2
; }
644 inline wxUString
operator+(const wxScopedU16CharBuffer
&s1
, const wxUString
&s2
)
645 { return wxUString(s1
) + s2
; }
646 inline wxUString
operator+(const wxScopedU32CharBuffer
&s1
, const wxUString
&s2
)
647 { return wxUString(s1
) + s2
; }
648 inline wxUString
operator+(char s1
, const wxUString
&s2
)
649 { return wxUString(s1
) + s2
; }
650 inline wxUString
operator+(wxChar32 s1
, const wxUString
&s2
)
651 { return wxUString(s1
) + s2
; }
652 inline wxUString
operator+(wxChar16 s1
, const wxUString
&s2
)
653 { return wxUString(s1
) + s2
; }
654 inline wxUString
operator+(wxUniChar s1
, const wxUString
&s2
)
655 { return wxUString(s1
) + s2
; }
656 inline wxUString
operator+(wxUniCharRef s1
, const wxUString
&s2
)
657 { return wxUString(s1
) + s2
; }
660 inline bool operator==(const wxUString
& s1
, const wxUString
& s2
)
661 { return s1
.compare( s2
) == 0; }
662 inline bool operator!=(const wxUString
& s1
, const wxUString
& s2
)
663 { return s1
.compare( s2
) != 0; }
664 inline bool operator< (const wxUString
& s1
, const wxUString
& s2
)
665 { return s1
.compare( s2
) < 0; }
666 inline bool operator> (const wxUString
& s1
, const wxUString
& s2
)
667 { return s1
.compare( s2
) > 0; }
668 inline bool operator<=(const wxUString
& s1
, const wxUString
& s2
)
669 { return s1
.compare( s2
) <= 0; }
670 inline bool operator>=(const wxUString
& s1
, const wxUString
& s2
)
671 { return s1
.compare( s2
) >= 0; }
673 #define wxUSTRING_COMP_OPERATORS( T ) \
674 inline bool operator==(const wxUString& s1, T s2) \
675 { return s1.compare( wxUString(s2) ) == 0; } \
676 inline bool operator!=(const wxUString& s1, T s2) \
677 { return s1.compare( wxUString(s2) ) != 0; } \
678 inline bool operator< (const wxUString& s1, T s2) \
679 { return s1.compare( wxUString(s2) ) < 0; } \
680 inline bool operator> (const wxUString& s1, T s2) \
681 { return s1.compare( wxUString(s2) ) > 0; } \
682 inline bool operator<=(const wxUString& s1, T s2) \
683 { return s1.compare( wxUString(s2) ) <= 0; } \
684 inline bool operator>=(const wxUString& s1, T s2) \
685 { return s1.compare( wxUString(s2) ) >= 0; } \
687 inline bool operator==(T s2, const wxUString& s1) \
688 { return s1.compare( wxUString(s2) ) == 0; } \
689 inline bool operator!=(T s2, const wxUString& s1) \
690 { return s1.compare( wxUString(s2) ) != 0; } \
691 inline bool operator< (T s2, const wxUString& s1) \
692 { return s1.compare( wxUString(s2) ) > 0; } \
693 inline bool operator> (T s2, const wxUString& s1) \
694 { return s1.compare( wxUString(s2) ) < 0; } \
695 inline bool operator<=(T s2, const wxUString& s1) \
696 { return s1.compare( wxUString(s2) ) >= 0; } \
697 inline bool operator>=(T s2, const wxUString& s1) \
698 { return s1.compare( wxUString(s2) ) <= 0; }
700 wxUSTRING_COMP_OPERATORS( const wxString
& )
701 wxUSTRING_COMP_OPERATORS( const char * )
702 wxUSTRING_COMP_OPERATORS( const wxChar16
* )
703 wxUSTRING_COMP_OPERATORS( const wxChar32
* )
704 wxUSTRING_COMP_OPERATORS( const wxScopedCharBuffer
& )
705 wxUSTRING_COMP_OPERATORS( const wxScopedU16CharBuffer
& )
706 wxUSTRING_COMP_OPERATORS( const wxScopedU32CharBuffer
& )
707 wxUSTRING_COMP_OPERATORS( const wxCStrData
* )
709 #endif // _WX_USTRING_H_