3 // Purpose: 32-bit string (UCS-4)
4 // Author: Robert Roebling
5 // Copyright: (c) Robert Roebling
6 // RCS-ID: $Id: tab.h 37400 2006-02-09 00:28:34Z VZ $
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_USTRING_H_BASE_
11 #define _WX_USTRING_H_BASE_
14 #include "wx/string.h"
18 #if SIZEOF_WCHAR_T == 2
19 typedef wxWCharBuffer wxU16CharBuffer
;
21 typedef wxCharTypeBuffer
<wxChar16
> wxU16CharBuffer
;
24 #if SIZEOF_WCHAR_T == 4
25 typedef wxWCharBuffer wxU32CharBuffer
;
27 typedef wxCharTypeBuffer
<wxChar32
> wxU32CharBuffer
;
31 class WXDLLIMPEXP_BASE wxUString
: public std::basic_string
<wxChar32
>
36 wxUString( const wxChar32
*str
) { assign(str
); }
37 wxUString( const wxUString
&str
) { assign(str
); }
38 wxUString( const wxU32CharBuffer
&buf
) { assign(buf
); }
40 wxUString( const char *str
) { assign(str
); }
41 wxUString( const wxCharBuffer
&buf
) { assign(buf
); }
42 wxUString( const char *str
, const wxMBConv
&conv
) { assign(str
,conv
); }
43 wxUString( const wxCharBuffer
&buf
, const wxMBConv
&conv
) { assign(buf
,conv
); }
45 wxUString( const wxChar16
*str
) { assign(str
); }
46 wxUString( const wxU16CharBuffer
&buf
) { assign(buf
); }
48 wxUString( const wxCStrData
*cstr
) { assign(cstr
); }
49 wxUString( const wxString
&str
) { assign(str
); }
51 wxUString( char ch
) { assign(ch
); }
52 wxUString( wxChar16 ch
) { assign(ch
); }
53 wxUString( wxChar32 ch
) { assign(ch
); }
54 wxUString( wxUniChar ch
) { assign(ch
); }
55 wxUString( wxUniCharRef ch
) { assign(ch
); }
56 wxUString( size_type n
, char ch
) { assign(n
,ch
); }
57 wxUString( size_type n
, wxChar16 ch
) { assign(n
,ch
); }
58 wxUString( size_type n
, wxChar32 ch
) { assign(n
,ch
); }
59 wxUString( size_type n
, wxUniChar ch
) { assign(n
,ch
); }
60 wxUString( size_type n
, wxUniCharRef ch
) { assign(n
,ch
); }
62 // static construction
64 static wxUString
FromAscii( const char *str
, size_type n
)
67 ret
.assignFromAscii( str
, n
);
71 static wxUString
FromAscii( const char *str
)
74 ret
.assignFromAscii( str
);
78 static wxUString
FromUTF8( const char *str
, size_type n
)
81 ret
.assignFromUTF8( str
, n
);
85 static wxUString
FromUTF8( const char *str
)
88 ret
.assignFromUTF8( str
);
92 static wxUString
FromUTF16( const wxChar16
*str
, size_type n
)
95 ret
.assignFromUTF16( str
, n
);
99 static wxUString
FromUTF16( const wxChar16
*str
)
102 ret
.assignFromUTF16( str
);
106 // assign from encoding
108 wxUString
&assignFromAscii( const char *str
);
109 wxUString
&assignFromAscii( const char *str
, size_type n
);
110 wxUString
&assignFromUTF8( const char *str
);
111 wxUString
&assignFromUTF8( const char *str
, size_type n
);
112 wxUString
&assignFromUTF16( const wxChar16
* str
);
113 wxUString
&assignFromUTF16( const wxChar16
* str
, size_type n
);
114 wxUString
&assignFromCString( const char* str
);
115 wxUString
&assignFromCString( const char* str
, const wxMBConv
&conv
);
119 wxCharBuffer
utf8_str() const;
120 wxU16CharBuffer
utf16_str() const;
122 #if SIZEOF_WCHAR_T == 2
123 wxWCharBuffer
wc_str() const
128 wchar_t *wc_str() const
130 return (wchar_t*) c_str();
134 operator wxString() const
136 #if wxUSE_UNICODE_UTF8
137 return wxString::FromUTF8( utf8_str() );
139 #if SIZEOF_WCHAR_T == 2
140 return wxString( utf16_str() );
142 return wxString( c_str() );
147 #if wxUSE_UNICODE_UTF8
148 wxCharBuffer
wx_str()
153 #if SIZEOF_WCHAR_T == 2
154 wxWCharBuffer
wx_str()
159 const wchar_t* wx_str()
168 inline wxUString
&assign( const wxChar32
* str
)
170 std::basic_string
<wxChar32
> *base
= this;
171 return (wxUString
&) base
->assign( str
);
174 inline wxUString
&assign( const wxChar32
* str
, size_type n
)
176 std::basic_string
<wxChar32
> *base
= this;
177 return (wxUString
&) base
->assign( str
, n
);
180 inline wxUString
&assign( const wxUString
&str
)
182 std::basic_string
<wxChar32
> *base
= this;
183 return (wxUString
&) base
->assign( str
);
186 inline wxUString
&assign( const wxUString
&str
, size_type pos
, size_type n
)
188 std::basic_string
<wxChar32
> *base
= this;
189 return (wxUString
&) base
->assign( str
, pos
, n
);
192 inline wxUString
&assign( wxChar32 ch
)
194 std::basic_string
<wxChar32
> *base
= this;
195 return (wxUString
&) base
->assign( (size_type
) 1, ch
);
198 inline wxUString
&assign( size_type n
, wxChar32 ch
)
200 std::basic_string
<wxChar32
> *base
= this;
201 return (wxUString
&) base
->assign( n
, ch
);
204 wxUString
&assign( const wxU32CharBuffer
&buf
)
206 return assign( buf
.data() );
209 wxUString
&assign( const char *str
)
211 return assignFromCString( str
);
214 wxUString
&assign( const wxCharBuffer
&buf
)
216 return assignFromCString( buf
.data() );
219 wxUString
&assign( const char *str
, const wxMBConv
&conv
)
221 return assignFromCString( str
, conv
);
224 wxUString
&assign( const wxCharBuffer
&buf
, const wxMBConv
&conv
)
226 return assignFromCString( buf
.data(), conv
);
229 wxUString
&assign( const wxChar16
*str
)
231 return assignFromUTF16( str
);
234 wxUString
&assign( const wxU16CharBuffer
&buf
)
236 return assignFromUTF16( buf
.data() );
239 wxUString
&assign( const wxCStrData
*cstr
)
241 #if SIZEOF_WCHAR_T == 2
242 return assignFromUTF16( cstr
->AsWChar() );
244 return assign( cstr
->AsWChar() );
248 wxUString
&assign( const wxString
&str
)
250 #if wxUSE_UNICODE_UTF8
251 return assignFromUTF8( str
.wx_str() );
253 #if SIZEOF_WCHAR_T == 2
254 return assignFromUTF16( str
.wc_str() );
256 return assign( wc_str() );
261 wxUString
&assign( char ch
)
266 return assignFromCString( buf
);
269 wxUString
&assign( size_type n
, char ch
)
271 wxCharBuffer
buffer(n
);
272 char *p
= buffer
.data();
274 for (i
= 0; i
< n
; i
++)
279 return assignFromCString( buffer
.data() );
282 wxUString
&assign( wxChar16 ch
)
287 return assignFromUTF16( buf
);
290 wxUString
&assign( size_type n
, wxChar16 ch
)
292 wxU16CharBuffer
buffer(n
);
293 wxChar16
*p
= buffer
.data();
295 for (i
= 0; i
< n
; i
++)
300 return assignFromUTF16( buffer
.data() );
303 wxUString
&assign( wxUniChar ch
)
305 return assign( (const wxChar32
) ch
.GetValue() );
308 wxUString
&assign( size_type n
, wxUniChar ch
)
310 return assign( n
, (const wxChar32
) ch
.GetValue() );
313 wxUString
&assign( wxUniCharRef ch
)
315 return assign( (const wxChar32
) ch
.GetValue() );
318 wxUString
&assign( size_type n
, wxUniCharRef ch
)
320 return assign( n
, (const wxChar32
) ch
.GetValue() );
323 // append [STL overload]
325 inline wxUString
&append( const wxUString
&s
)
327 std::basic_string
<wxChar32
> *base
= this;
328 return (wxUString
&) base
->append( s
);
331 inline wxUString
&append( const wxUString
&s
, size_type pos
, size_type n
)
333 std::basic_string
<wxChar32
> *base
= this;
334 return (wxUString
&) base
->append( s
, pos
, n
);
337 inline wxUString
&append( const wxChar32
* s
)
339 std::basic_string
<wxChar32
> *base
= this;
340 return (wxUString
&) base
->append( s
);
343 inline wxUString
&append( const wxChar32
* s
, size_type n
)
345 std::basic_string
<wxChar32
> *base
= this;
346 return (wxUString
&) base
->append( s
, n
);
349 inline wxUString
&append( size_type n
, wxChar32 c
)
351 std::basic_string
<wxChar32
> *base
= this;
352 return (wxUString
&) base
->append( n
, c
);
355 inline wxUString
&append( wxChar32 c
)
357 std::basic_string
<wxChar32
> *base
= this;
358 return (wxUString
&) base
->append( 1, c
);
361 // append [wx overload]
363 wxUString
&append( const wxU16CharBuffer
&buf
)
365 return append( buf
.data() );
368 wxUString
&append( const wxU32CharBuffer
&buf
)
370 return append( buf
.data() );
373 wxUString
&append( const char *str
)
375 return append( wxUString( str
) );
378 wxUString
&append( const wxCharBuffer
&buf
)
380 return append( wxUString( buf
) );
383 wxUString
&append( const wxChar16
*str
)
385 return append( wxUString( str
) );
388 wxUString
&append( const wxString
&str
)
390 return append( wxUString( str
) );
393 wxUString
&append( const wxCStrData
*cstr
)
395 return append( wxUString( cstr
) );
398 wxUString
&append( char ch
)
403 return append( buf
);
406 wxUString
&append( wxChar16 ch
)
411 return append( buf
);
414 wxUString
&append( wxUniChar ch
)
416 return append( (size_type
) 1, (wxChar32
) ch
.GetValue() );
419 wxUString
&append( wxUniCharRef ch
)
421 return append( (size_type
) 1, (wxChar32
) ch
.GetValue() );
425 // insert [STL overloads]
427 inline wxUString
&insert( size_type pos
, const wxUString
&s
)
429 std::basic_string
<wxChar32
> *base
= this;
430 return (wxUString
&) base
->insert( pos
, s
);
433 inline wxUString
&insert( size_type pos
, const wxUString
&s
, size_type pos1
, size_type n
)
435 std::basic_string
<wxChar32
> *base
= this;
436 return (wxUString
&) base
->insert( pos
, s
, pos1
, n
);
439 inline wxUString
&insert( size_type pos
, const wxChar32
*s
)
441 std::basic_string
<wxChar32
> *base
= this;
442 return (wxUString
&) base
->insert( pos
, s
);
445 inline wxUString
&insert( size_type pos
, const wxChar32
*s
, size_type n
)
447 std::basic_string
<wxChar32
> *base
= this;
448 return (wxUString
&) base
->insert( pos
, s
, n
);
451 inline wxUString
&insert( size_type pos
, size_type n
, wxChar32 c
)
453 std::basic_string
<wxChar32
> *base
= this;
454 return (wxUString
&) base
->insert( pos
, n
, c
);
458 // insert [STL overloads]
460 wxUString
&insert( size_type n
, const char *s
)
462 return insert( n
, wxUString( s
) );
465 wxUString
&insert( size_type n
, const wxChar16
*s
)
467 return insert( n
, wxUString( s
) );
470 wxUString
&insert( size_type n
, const wxCharBuffer
&buf
)
472 return insert( n
, wxUString( buf
) );
475 wxUString
&insert( size_type n
, const wxU16CharBuffer
&buf
)
477 return insert( n
, wxUString( buf
) );
480 wxUString
&insert( size_type n
, const wxU32CharBuffer
&buf
)
482 return insert( n
, buf
.data() );
485 wxUString
&insert( size_type n
, const wxString
&s
)
487 return insert( n
, wxUString( s
) );
490 wxUString
&insert( size_type n
, const wxCStrData
*cstr
)
492 return insert( n
, wxUString( cstr
) );
495 wxUString
&insert( size_type n
, char ch
)
500 return insert( n
, buf
);
503 wxUString
&insert( size_type n
, wchar_t ch
)
508 return insert( n
, buf
);
513 iterator
insert( iterator it
, wxChar32 ch
)
515 std::basic_string
<wxChar32
> *base
= this;
516 return base
->insert( it
, ch
);
519 void insert(iterator it
, const_iterator first
, const_iterator last
)
521 std::basic_string
<wxChar32
> *base
= this;
522 base
->insert( it
, first
, last
);
527 inline wxUString
& operator=(const wxUString
& s
)
528 { return assign( s
); }
529 inline wxUString
& operator=(const wxString
& s
)
530 { return assign( s
); }
531 inline wxUString
& operator=(const wxCStrData
* s
)
532 { return assign( s
); }
533 inline wxUString
& operator=(const char *s
)
534 { return assign( s
); }
535 inline wxUString
& operator=(const wxChar16
*s
)
536 { return assign( s
); }
537 inline wxUString
& operator=(const wxChar32
*s
)
538 { return assign( s
); }
539 inline wxUString
& operator=(const wxCharBuffer
&s
)
540 { return assign( s
); }
541 inline wxUString
& operator=(const wxU16CharBuffer
&s
)
542 { return assign( s
); }
543 inline wxUString
& operator=(const wxU32CharBuffer
&s
)
544 { return assign( s
); }
545 inline wxUString
& operator=(const char ch
)
546 { return assign( ch
); }
547 inline wxUString
& operator=(const wxChar16 ch
)
548 { return assign( ch
); }
549 inline wxUString
& operator=(const wxChar32 ch
)
550 { return assign( ch
); }
551 inline wxUString
& operator=(const wxUniChar ch
)
552 { return assign( ch
); }
553 inline wxUString
& operator=(const wxUniCharRef ch
)
554 { return assign( ch
); }
557 inline wxUString
& operator+=(const wxUString
& s
)
558 { return append( s
); }
559 inline wxUString
& operator+=(const wxString
& s
)
560 { return append( s
); }
561 inline wxUString
& operator+=(const wxCStrData
* s
)
562 { return append( s
); }
563 inline wxUString
& operator+=(const char *s
)
564 { return append( s
); }
565 inline wxUString
& operator+=(const wxChar16
*s
)
566 { return append( s
); }
567 inline wxUString
& operator+=(const wxChar32
*s
)
568 { return append( s
); }
569 inline wxUString
& operator+=(const wxCharBuffer
&s
)
570 { return append( s
); }
571 inline wxUString
& operator+=(const wxU16CharBuffer
&s
)
572 { return append( s
); }
573 inline wxUString
& operator+=(const wxU32CharBuffer
&s
)
574 { return append( s
); }
575 inline wxUString
& operator+=(const char ch
)
576 { return append( ch
); }
577 inline wxUString
& operator+=(const wxChar16 ch
)
578 { return append( ch
); }
579 inline wxUString
& operator+=(const wxChar32 ch
)
580 { return append( ch
); }
581 inline wxUString
& operator+=(const wxUniChar ch
)
582 { return append( ch
); }
583 inline wxUString
& operator+=(const wxUniCharRef ch
)
584 { return append( ch
); }
588 inline wxUString
operator+(const wxUString
&s1
, const wxUString
&s2
)
589 { wxUString
ret( s1
); ret
.append( s2
); return ret
; }
590 inline wxUString
operator+(const wxUString
&s1
, const char *s2
)
591 { return s1
+ wxUString(s2
); }
592 inline wxUString
operator+(const wxUString
&s1
, const wxString
&s2
)
593 { return s1
+ wxUString(s2
); }
594 inline wxUString
operator+(const wxUString
&s1
, const wxCStrData
*s2
)
595 { return s1
+ wxUString(s2
); }
596 inline wxUString
operator+(const wxUString
&s1
, const wxChar16
* s2
)
597 { return s1
+ wxUString(s2
); }
598 inline wxUString
operator+(const wxUString
&s1
, const wxChar32
*s2
)
599 { return s1
+ wxUString(s2
); }
600 inline wxUString
operator+(const wxUString
&s1
, const wxCharBuffer
&s2
)
601 { return s1
+ wxUString(s2
); }
602 inline wxUString
operator+(const wxUString
&s1
, const wxU16CharBuffer
&s2
)
603 { return s1
+ wxUString(s2
); }
604 inline wxUString
operator+(const wxUString
&s1
, const wxU32CharBuffer
&s2
)
605 { return s1
+ wxUString(s2
); }
606 inline wxUString
operator+(const wxUString
&s1
, char s2
)
607 { return s1
+ wxUString(s2
); }
608 inline wxUString
operator+(const wxUString
&s1
, wxChar32 s2
)
609 { wxUString
ret( s1
); ret
.append( s2
); return ret
; }
610 inline wxUString
operator+(const wxUString
&s1
, wxChar16 s2
)
611 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
); return ret
; }
612 inline wxUString
operator+(const wxUString
&s1
, wxUniChar s2
)
613 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
.GetValue() ); return ret
; }
614 inline wxUString
operator+(const wxUString
&s1
, wxUniCharRef s2
)
615 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
.GetValue() ); return ret
; }
617 inline wxUString
operator+(const char *s1
, const wxUString
&s2
)
618 { return wxUString(s1
) + s2
; }
619 inline wxUString
operator+(const wxString
&s1
, const wxUString
&s2
)
620 { return wxUString(s1
) + s2
; }
621 inline wxUString
operator+(const wxCStrData
*s1
, const wxUString
&s2
)
622 { return wxUString(s1
) + s2
; }
623 inline wxUString
operator+(const wxChar16
* s1
, const wxUString
&s2
)
624 { return wxUString(s1
) + s2
; }
625 inline wxUString
operator+(const wxChar32
*s1
, const wxUString
&s2
)
626 { return wxUString(s1
) + s2
; }
627 inline wxUString
operator+(const wxCharBuffer
&s1
, const wxUString
&s2
)
628 { return wxUString(s1
) + s2
; }
629 inline wxUString
operator+(const wxU16CharBuffer
&s1
, const wxUString
&s2
)
630 { return wxUString(s1
) + s2
; }
631 inline wxUString
operator+(const wxU32CharBuffer
&s1
, const wxUString
&s2
)
632 { return wxUString(s1
) + s2
; }
633 inline wxUString
operator+(char s1
, const wxUString
&s2
)
634 { return wxUString(s1
) + s2
; }
635 inline wxUString
operator+(wxChar32 s1
, const wxUString
&s2
)
636 { return wxUString(s1
) + s2
; }
637 inline wxUString
operator+(wxChar16 s1
, const wxUString
&s2
)
638 { return wxUString(s1
) + s2
; }
639 inline wxUString
operator+(wxUniChar s1
, const wxUString
&s2
)
640 { return wxUString(s1
) + s2
; }
641 inline wxUString
operator+(wxUniCharRef s1
, const wxUString
&s2
)
642 { return wxUString(s1
) + s2
; }
645 inline bool operator==(const wxUString
& s1
, const wxUString
& s2
)
646 { return s1
.compare( s2
) == 0; }
647 inline bool operator!=(const wxUString
& s1
, const wxUString
& s2
)
648 { return s1
.compare( s2
) != 0; }
649 inline bool operator< (const wxUString
& s1
, const wxUString
& s2
)
650 { return s1
.compare( s2
) < 0; }
651 inline bool operator> (const wxUString
& s1
, const wxUString
& s2
)
652 { return s1
.compare( s2
) > 0; }
653 inline bool operator<=(const wxUString
& s1
, const wxUString
& s2
)
654 { return s1
.compare( s2
) <= 0; }
655 inline bool operator>=(const wxUString
& s1
, const wxUString
& s2
)
656 { return s1
.compare( s2
) >= 0; }
658 #define wxUSTRING_COMP_OPERATORS( T ) \
659 inline bool operator==(const wxUString& s1, T s2) \
660 { return s1.compare( wxUString(s2) ) == 0; } \
661 inline bool operator!=(const wxUString& s1, T s2) \
662 { return s1.compare( wxUString(s2) ) != 0; } \
663 inline bool operator< (const wxUString& s1, T s2) \
664 { return s1.compare( wxUString(s2) ) < 0; } \
665 inline bool operator> (const wxUString& s1, T s2) \
666 { return s1.compare( wxUString(s2) ) > 0; } \
667 inline bool operator<=(const wxUString& s1, T s2) \
668 { return s1.compare( wxUString(s2) ) <= 0; } \
669 inline bool operator>=(const wxUString& s1, T s2) \
670 { return s1.compare( wxUString(s2) ) >= 0; } \
672 inline bool operator==(T s2, const wxUString& s1) \
673 { return s1.compare( wxUString(s2) ) == 0; } \
674 inline bool operator!=(T s2, const wxUString& s1) \
675 { return s1.compare( wxUString(s2) ) != 0; } \
676 inline bool operator< (T s2, const wxUString& s1) \
677 { return s1.compare( wxUString(s2) ) > 0; } \
678 inline bool operator> (T s2, const wxUString& s1) \
679 { return s1.compare( wxUString(s2) ) < 0; } \
680 inline bool operator<=(T s2, const wxUString& s1) \
681 { return s1.compare( wxUString(s2) ) >= 0; } \
682 inline bool operator>=(T s2, const wxUString& s1) \
683 { return s1.compare( wxUString(s2) ) <= 0; }
685 wxUSTRING_COMP_OPERATORS( const wxString
& )
686 wxUSTRING_COMP_OPERATORS( const char * )
687 wxUSTRING_COMP_OPERATORS( const wxChar16
* )
688 wxUSTRING_COMP_OPERATORS( const wxChar32
* )
689 wxUSTRING_COMP_OPERATORS( const wxCharBuffer
& )
690 wxUSTRING_COMP_OPERATORS( const wxU16CharBuffer
& )
691 wxUSTRING_COMP_OPERATORS( const wxU32CharBuffer
& )
692 wxUSTRING_COMP_OPERATORS( const wxCStrData
* )
695 // _WX_USTRING_H_BASE_