1 /////////////////////////////////////////////////////////////////////////////
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 WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxCharTypeBuffer
<wxChar32
> )
20 #if SIZEOF_WCHAR_T == 2
22 typedef wxWCharBuffer wxU16CharBuffer
;
26 class WXDLLIMPEXP_BASE wxU16CharBuffer
: public wxCharTypeBuffer
<wxChar16
>
29 typedef wxCharTypeBuffer
<wxChar16
> wxCharTypeBufferBase
;
31 wxU16CharBuffer(const wxCharTypeBufferBase
& buf
)
32 : wxCharTypeBufferBase(buf
) {}
34 wxU16CharBuffer(const CharType
*str
= NULL
) : wxCharTypeBufferBase(str
) {}
35 wxU16CharBuffer(size_t len
) : wxCharTypeBufferBase(len
) {}
42 #if SIZEOF_WCHAR_T == 2
44 class WXDLLIMPEXP_BASE wxU32CharBuffer
: public wxCharTypeBuffer
<wxChar32
>
47 typedef wxCharTypeBuffer
<wxChar32
> wxCharTypeBufferBase
;
49 wxU32CharBuffer(const wxCharTypeBufferBase
& buf
)
50 : wxCharTypeBufferBase(buf
) {}
52 wxU32CharBuffer(const CharType
*str
= NULL
) : wxCharTypeBufferBase(str
) {}
53 wxU32CharBuffer(size_t len
) : wxCharTypeBufferBase(len
) {}
58 typedef wxWCharBuffer wxU32CharBuffer
;
62 class WXDLLIMPEXP_BASE wxUString
: public std::basic_string
<wxChar32
>
67 wxUString( const wxChar32
*str
) { assign(str
); }
68 wxUString( const wxUString
&str
) { assign(str
); }
69 wxUString( const wxU32CharBuffer
&buf
) { assign(buf
); }
71 wxUString( const char *str
) { assign(str
); }
72 wxUString( const wxCharBuffer
&buf
) { assign(buf
); }
73 wxUString( const char *str
, const wxMBConv
&conv
) { assign(str
,conv
); }
74 wxUString( const wxCharBuffer
&buf
, const wxMBConv
&conv
) { assign(buf
,conv
); }
76 wxUString( const wxChar16
*str
) { assign(str
); }
77 wxUString( const wxU16CharBuffer
&buf
) { assign(buf
); }
79 wxUString( const wxCStrData
*cstr
) { assign(cstr
); }
80 wxUString( const wxString
&str
) { assign(str
); }
82 wxUString( char ch
) { assign(ch
); }
83 wxUString( wxChar16 ch
) { assign(ch
); }
84 wxUString( wxChar32 ch
) { assign(ch
); }
85 wxUString( wxUniChar ch
) { assign(ch
); }
86 wxUString( wxUniCharRef ch
) { assign(ch
); }
87 wxUString( size_type n
, char ch
) { assign(n
,ch
); }
88 wxUString( size_type n
, wxChar16 ch
) { assign(n
,ch
); }
89 wxUString( size_type n
, wxChar32 ch
) { assign(n
,ch
); }
90 wxUString( size_type n
, wxUniChar ch
) { assign(n
,ch
); }
91 wxUString( size_type n
, wxUniCharRef ch
) { assign(n
,ch
); }
93 // static construction
95 static wxUString
FromAscii( const char *str
, size_type n
)
98 ret
.assignFromAscii( str
, n
);
102 static wxUString
FromAscii( const char *str
)
105 ret
.assignFromAscii( str
);
109 static wxUString
FromUTF8( const char *str
, size_type n
)
112 ret
.assignFromUTF8( str
, n
);
116 static wxUString
FromUTF8( const char *str
)
119 ret
.assignFromUTF8( str
);
123 static wxUString
FromUTF16( const wxChar16
*str
, size_type n
)
126 ret
.assignFromUTF16( str
, n
);
130 static wxUString
FromUTF16( const wxChar16
*str
)
133 ret
.assignFromUTF16( str
);
137 // assign from encoding
139 wxUString
&assignFromAscii( const char *str
);
140 wxUString
&assignFromAscii( const char *str
, size_type n
);
141 wxUString
&assignFromUTF8( const char *str
);
142 wxUString
&assignFromUTF8( const char *str
, size_type n
);
143 wxUString
&assignFromUTF16( const wxChar16
* str
);
144 wxUString
&assignFromUTF16( const wxChar16
* str
, size_type n
);
145 wxUString
&assignFromCString( const char* str
);
146 wxUString
&assignFromCString( const char* str
, const wxMBConv
&conv
);
150 wxCharBuffer
utf8_str() const;
151 wxU16CharBuffer
utf16_str() const;
153 #if SIZEOF_WCHAR_T == 2
154 wxWCharBuffer
wc_str() const
159 wchar_t *wc_str() const
161 return (wchar_t*) c_str();
165 operator wxString() const
167 #if wxUSE_UNICODE_UTF8
168 return wxString::FromUTF8( utf8_str() );
170 #if SIZEOF_WCHAR_T == 2
171 return wxString( utf16_str() );
173 return wxString( c_str() );
178 #if wxUSE_UNICODE_UTF8
179 wxCharBuffer
wx_str()
184 #if SIZEOF_WCHAR_T == 2
185 wxWCharBuffer
wx_str()
190 const wchar_t* wx_str()
199 inline wxUString
&assign( const wxChar32
* str
)
201 std::basic_string
<wxChar32
> *base
= this;
202 return (wxUString
&) base
->assign( str
);
205 inline wxUString
&assign( const wxChar32
* str
, size_type n
)
207 std::basic_string
<wxChar32
> *base
= this;
208 return (wxUString
&) base
->assign( str
, n
);
211 inline wxUString
&assign( const wxUString
&str
)
213 std::basic_string
<wxChar32
> *base
= this;
214 return (wxUString
&) base
->assign( str
);
217 inline wxUString
&assign( const wxUString
&str
, size_type pos
, size_type n
)
219 std::basic_string
<wxChar32
> *base
= this;
220 return (wxUString
&) base
->assign( str
, pos
, n
);
223 inline wxUString
&assign( wxChar32 ch
)
225 std::basic_string
<wxChar32
> *base
= this;
226 return (wxUString
&) base
->assign( (size_type
) 1, ch
);
229 inline wxUString
&assign( size_type n
, wxChar32 ch
)
231 std::basic_string
<wxChar32
> *base
= this;
232 return (wxUString
&) base
->assign( n
, ch
);
235 wxUString
&assign( const wxU32CharBuffer
&buf
)
237 return assign( buf
.data() );
240 wxUString
&assign( const char *str
)
242 return assignFromCString( str
);
245 wxUString
&assign( const wxCharBuffer
&buf
)
247 return assignFromCString( buf
.data() );
250 wxUString
&assign( const char *str
, const wxMBConv
&conv
)
252 return assignFromCString( str
, conv
);
255 wxUString
&assign( const wxCharBuffer
&buf
, const wxMBConv
&conv
)
257 return assignFromCString( buf
.data(), conv
);
260 wxUString
&assign( const wxChar16
*str
)
262 return assignFromUTF16( str
);
265 wxUString
&assign( const wxU16CharBuffer
&buf
)
267 return assignFromUTF16( buf
.data() );
270 wxUString
&assign( const wxCStrData
*cstr
)
272 #if SIZEOF_WCHAR_T == 2
273 return assignFromUTF16( cstr
->AsWChar() );
275 return assign( cstr
->AsWChar() );
279 wxUString
&assign( const wxString
&str
)
281 #if wxUSE_UNICODE_UTF8
282 return assignFromUTF8( str
.wx_str() );
284 #if SIZEOF_WCHAR_T == 2
285 return assignFromUTF16( str
.wc_str() );
287 return assign( wc_str() );
292 wxUString
&assign( char ch
)
297 return assignFromCString( buf
);
300 wxUString
&assign( size_type n
, char ch
)
302 wxCharBuffer
buffer(n
);
303 char *p
= buffer
.data();
305 for (i
= 0; i
< n
; i
++)
310 return assignFromCString( buffer
.data() );
313 wxUString
&assign( wxChar16 ch
)
318 return assignFromUTF16( buf
);
321 wxUString
&assign( size_type n
, wxChar16 ch
)
323 wxU16CharBuffer
buffer(n
);
324 wxChar16
*p
= buffer
.data();
326 for (i
= 0; i
< n
; i
++)
331 return assignFromUTF16( buffer
.data() );
334 wxUString
&assign( wxUniChar ch
)
336 return assign( (const wxChar32
) ch
.GetValue() );
339 wxUString
&assign( size_type n
, wxUniChar ch
)
341 return assign( n
, (const wxChar32
) ch
.GetValue() );
344 wxUString
&assign( wxUniCharRef ch
)
346 return assign( (const wxChar32
) ch
.GetValue() );
349 wxUString
&assign( size_type n
, wxUniCharRef ch
)
351 return assign( n
, (const wxChar32
) ch
.GetValue() );
354 // append [STL overload]
356 inline wxUString
&append( const wxUString
&s
)
358 std::basic_string
<wxChar32
> *base
= this;
359 return (wxUString
&) base
->append( s
);
362 inline wxUString
&append( const wxUString
&s
, size_type pos
, size_type n
)
364 std::basic_string
<wxChar32
> *base
= this;
365 return (wxUString
&) base
->append( s
, pos
, n
);
368 inline wxUString
&append( const wxChar32
* s
)
370 std::basic_string
<wxChar32
> *base
= this;
371 return (wxUString
&) base
->append( s
);
374 inline wxUString
&append( const wxChar32
* s
, size_type n
)
376 std::basic_string
<wxChar32
> *base
= this;
377 return (wxUString
&) base
->append( s
, n
);
380 inline wxUString
&append( size_type n
, wxChar32 c
)
382 std::basic_string
<wxChar32
> *base
= this;
383 return (wxUString
&) base
->append( n
, c
);
386 inline wxUString
&append( wxChar32 c
)
388 std::basic_string
<wxChar32
> *base
= this;
389 return (wxUString
&) base
->append( 1, c
);
392 // append [wx overload]
394 wxUString
&append( const wxU16CharBuffer
&buf
)
396 return append( buf
.data() );
399 wxUString
&append( const wxU32CharBuffer
&buf
)
401 return append( buf
.data() );
404 wxUString
&append( const char *str
)
406 return append( wxUString( str
) );
409 wxUString
&append( const wxCharBuffer
&buf
)
411 return append( wxUString( buf
) );
414 wxUString
&append( const wxChar16
*str
)
416 return append( wxUString( str
) );
419 wxUString
&append( const wxString
&str
)
421 return append( wxUString( str
) );
424 wxUString
&append( const wxCStrData
*cstr
)
426 return append( wxUString( cstr
) );
429 wxUString
&append( char ch
)
434 return append( buf
);
437 wxUString
&append( wxChar16 ch
)
442 return append( buf
);
445 wxUString
&append( wxUniChar ch
)
447 return append( (size_type
) 1, (wxChar32
) ch
.GetValue() );
450 wxUString
&append( wxUniCharRef ch
)
452 return append( (size_type
) 1, (wxChar32
) ch
.GetValue() );
456 // insert [STL overloads]
458 inline wxUString
&insert( size_type pos
, const wxUString
&s
)
460 std::basic_string
<wxChar32
> *base
= this;
461 return (wxUString
&) base
->insert( pos
, s
);
464 inline wxUString
&insert( size_type pos
, const wxUString
&s
, size_type pos1
, size_type n
)
466 std::basic_string
<wxChar32
> *base
= this;
467 return (wxUString
&) base
->insert( pos
, s
, pos1
, n
);
470 inline wxUString
&insert( size_type pos
, const wxChar32
*s
)
472 std::basic_string
<wxChar32
> *base
= this;
473 return (wxUString
&) base
->insert( pos
, s
);
476 inline wxUString
&insert( size_type pos
, const wxChar32
*s
, size_type n
)
478 std::basic_string
<wxChar32
> *base
= this;
479 return (wxUString
&) base
->insert( pos
, s
, n
);
482 inline wxUString
&insert( size_type pos
, size_type n
, wxChar32 c
)
484 std::basic_string
<wxChar32
> *base
= this;
485 return (wxUString
&) base
->insert( pos
, n
, c
);
489 // insert [STL overloads]
491 wxUString
&insert( size_type n
, const char *s
)
493 return insert( n
, wxUString( s
) );
496 wxUString
&insert( size_type n
, const wxChar16
*s
)
498 return insert( n
, wxUString( s
) );
501 wxUString
&insert( size_type n
, const wxCharBuffer
&buf
)
503 return insert( n
, wxUString( buf
) );
506 wxUString
&insert( size_type n
, const wxU16CharBuffer
&buf
)
508 return insert( n
, wxUString( buf
) );
511 wxUString
&insert( size_type n
, const wxU32CharBuffer
&buf
)
513 return insert( n
, buf
.data() );
516 wxUString
&insert( size_type n
, const wxString
&s
)
518 return insert( n
, wxUString( s
) );
521 wxUString
&insert( size_type n
, const wxCStrData
*cstr
)
523 return insert( n
, wxUString( cstr
) );
526 wxUString
&insert( size_type n
, char ch
)
531 return insert( n
, buf
);
534 wxUString
&insert( size_type n
, wchar_t ch
)
539 return insert( n
, buf
);
544 iterator
insert( iterator it
, wxChar32 ch
)
546 std::basic_string
<wxChar32
> *base
= this;
547 return base
->insert( it
, ch
);
550 void insert(iterator it
, const_iterator first
, const_iterator last
)
552 std::basic_string
<wxChar32
> *base
= this;
553 base
->insert( it
, first
, last
);
558 inline wxUString
& operator=(const wxUString
& s
)
559 { return assign( s
); }
560 inline wxUString
& operator=(const wxString
& s
)
561 { return assign( s
); }
562 inline wxUString
& operator=(const wxCStrData
* s
)
563 { return assign( s
); }
564 inline wxUString
& operator=(const char *s
)
565 { return assign( s
); }
566 inline wxUString
& operator=(const wxChar16
*s
)
567 { return assign( s
); }
568 inline wxUString
& operator=(const wxChar32
*s
)
569 { return assign( s
); }
570 inline wxUString
& operator=(const wxCharBuffer
&s
)
571 { return assign( s
); }
572 inline wxUString
& operator=(const wxU16CharBuffer
&s
)
573 { return assign( s
); }
574 inline wxUString
& operator=(const wxU32CharBuffer
&s
)
575 { return assign( s
); }
576 inline wxUString
& operator=(const char ch
)
577 { return assign( ch
); }
578 inline wxUString
& operator=(const wxChar16 ch
)
579 { return assign( ch
); }
580 inline wxUString
& operator=(const wxChar32 ch
)
581 { return assign( ch
); }
582 inline wxUString
& operator=(const wxUniChar ch
)
583 { return assign( ch
); }
584 inline wxUString
& operator=(const wxUniCharRef ch
)
585 { return assign( ch
); }
588 inline wxUString
& operator+=(const wxUString
& s
)
589 { return append( s
); }
590 inline wxUString
& operator+=(const wxString
& s
)
591 { return append( s
); }
592 inline wxUString
& operator+=(const wxCStrData
* s
)
593 { return append( s
); }
594 inline wxUString
& operator+=(const char *s
)
595 { return append( s
); }
596 inline wxUString
& operator+=(const wxChar16
*s
)
597 { return append( s
); }
598 inline wxUString
& operator+=(const wxChar32
*s
)
599 { return append( s
); }
600 inline wxUString
& operator+=(const wxCharBuffer
&s
)
601 { return append( s
); }
602 inline wxUString
& operator+=(const wxU16CharBuffer
&s
)
603 { return append( s
); }
604 inline wxUString
& operator+=(const wxU32CharBuffer
&s
)
605 { return append( s
); }
606 inline wxUString
& operator+=(const char ch
)
607 { return append( ch
); }
608 inline wxUString
& operator+=(const wxChar16 ch
)
609 { return append( ch
); }
610 inline wxUString
& operator+=(const wxChar32 ch
)
611 { return append( ch
); }
612 inline wxUString
& operator+=(const wxUniChar ch
)
613 { return append( ch
); }
614 inline wxUString
& operator+=(const wxUniCharRef ch
)
615 { return append( ch
); }
619 inline wxUString
operator+(const wxUString
&s1
, const wxUString
&s2
)
620 { wxUString
ret( s1
); ret
.append( s2
); return ret
; }
621 inline wxUString
operator+(const wxUString
&s1
, const char *s2
)
622 { return s1
+ wxUString(s2
); }
623 inline wxUString
operator+(const wxUString
&s1
, const wxString
&s2
)
624 { return s1
+ wxUString(s2
); }
625 inline wxUString
operator+(const wxUString
&s1
, const wxCStrData
*s2
)
626 { return s1
+ wxUString(s2
); }
627 inline wxUString
operator+(const wxUString
&s1
, const wxChar16
* s2
)
628 { return s1
+ wxUString(s2
); }
629 inline wxUString
operator+(const wxUString
&s1
, const wxChar32
*s2
)
630 { return s1
+ wxUString(s2
); }
631 inline wxUString
operator+(const wxUString
&s1
, const wxCharBuffer
&s2
)
632 { return s1
+ wxUString(s2
); }
633 inline wxUString
operator+(const wxUString
&s1
, const wxU16CharBuffer
&s2
)
634 { return s1
+ wxUString(s2
); }
635 inline wxUString
operator+(const wxUString
&s1
, const wxU32CharBuffer
&s2
)
636 { return s1
+ wxUString(s2
); }
637 inline wxUString
operator+(const wxUString
&s1
, char s2
)
638 { return s1
+ wxUString(s2
); }
639 inline wxUString
operator+(const wxUString
&s1
, wxChar32 s2
)
640 { wxUString
ret( s1
); ret
.append( s2
); return ret
; }
641 inline wxUString
operator+(const wxUString
&s1
, wxChar16 s2
)
642 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
); return ret
; }
643 inline wxUString
operator+(const wxUString
&s1
, wxUniChar s2
)
644 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
.GetValue() ); return ret
; }
645 inline wxUString
operator+(const wxUString
&s1
, wxUniCharRef s2
)
646 { wxUString
ret( s1
); ret
.append( (wxChar32
) s2
.GetValue() ); return ret
; }
648 inline wxUString
operator+(const char *s1
, const wxUString
&s2
)
649 { return wxUString(s1
) + s2
; }
650 inline wxUString
operator+(const wxString
&s1
, const wxUString
&s2
)
651 { return wxUString(s1
) + s2
; }
652 inline wxUString
operator+(const wxCStrData
*s1
, const wxUString
&s2
)
653 { return wxUString(s1
) + s2
; }
654 inline wxUString
operator+(const wxChar16
* s1
, const wxUString
&s2
)
655 { return wxUString(s1
) + s2
; }
656 inline wxUString
operator+(const wxChar32
*s1
, const wxUString
&s2
)
657 { return wxUString(s1
) + s2
; }
658 inline wxUString
operator+(const wxCharBuffer
&s1
, const wxUString
&s2
)
659 { return wxUString(s1
) + s2
; }
660 inline wxUString
operator+(const wxU16CharBuffer
&s1
, const wxUString
&s2
)
661 { return wxUString(s1
) + s2
; }
662 inline wxUString
operator+(const wxU32CharBuffer
&s1
, const wxUString
&s2
)
663 { return wxUString(s1
) + s2
; }
664 inline wxUString
operator+(char s1
, const wxUString
&s2
)
665 { return wxUString(s1
) + s2
; }
666 inline wxUString
operator+(wxChar32 s1
, const wxUString
&s2
)
667 { return wxUString(s1
) + s2
; }
668 inline wxUString
operator+(wxChar16 s1
, const wxUString
&s2
)
669 { return wxUString(s1
) + s2
; }
670 inline wxUString
operator+(wxUniChar s1
, const wxUString
&s2
)
671 { return wxUString(s1
) + s2
; }
672 inline wxUString
operator+(wxUniCharRef s1
, const wxUString
&s2
)
673 { return wxUString(s1
) + s2
; }
676 inline bool operator==(const wxUString
& s1
, const wxUString
& s2
)
677 { return s1
.compare( s2
) == 0; }
678 inline bool operator!=(const wxUString
& s1
, const wxUString
& s2
)
679 { return s1
.compare( s2
) != 0; }
680 inline bool operator< (const wxUString
& s1
, const wxUString
& s2
)
681 { wxPrintf( "test\n"); return s1
.compare( s2
) < 0; }
682 inline bool operator> (const wxUString
& s1
, const wxUString
& s2
)
683 { return s1
.compare( s2
) > 0; }
684 inline bool operator<=(const wxUString
& s1
, const wxUString
& s2
)
685 { return s1
.compare( s2
) <= 0; }
686 inline bool operator>=(const wxUString
& s1
, const wxUString
& s2
)
687 { return s1
.compare( s2
) >= 0; }
689 #define wxUSTRING_COMP_OPERATORS( T ) \
690 inline bool operator==(const wxUString& s1, T s2) \
691 { return s1.compare( wxUString(s2) ) == 0; } \
692 inline bool operator!=(const wxUString& s1, T s2) \
693 { return s1.compare( wxUString(s2) ) != 0; } \
694 inline bool operator< (const wxUString& s1, T s2) \
695 { return s1.compare( wxUString(s2) ) < 0; } \
696 inline bool operator> (const wxUString& s1, T s2) \
697 { return s1.compare( wxUString(s2) ) > 0; } \
698 inline bool operator<=(const wxUString& s1, T s2) \
699 { return s1.compare( wxUString(s2) ) <= 0; } \
700 inline bool operator>=(const wxUString& s1, T s2) \
701 { return s1.compare( wxUString(s2) ) >= 0; } \
703 inline bool operator==(T s2, const wxUString& s1) \
704 { return s1.compare( wxUString(s2) ) == 0; } \
705 inline bool operator!=(T s2, const wxUString& s1) \
706 { return s1.compare( wxUString(s2) ) != 0; } \
707 inline bool operator< (T s2, const wxUString& s1) \
708 { return s1.compare( wxUString(s2) ) > 0; } \
709 inline bool operator> (T s2, const wxUString& s1) \
710 { return s1.compare( wxUString(s2) ) < 0; } \
711 inline bool operator<=(T s2, const wxUString& s1) \
712 { return s1.compare( wxUString(s2) ) >= 0; } \
713 inline bool operator>=(T s2, const wxUString& s1) \
714 { return s1.compare( wxUString(s2) ) <= 0; }
716 wxUSTRING_COMP_OPERATORS( const wxString
& )
717 wxUSTRING_COMP_OPERATORS( const char * )
718 wxUSTRING_COMP_OPERATORS( const wxChar16
* )
719 wxUSTRING_COMP_OPERATORS( const wxChar32
* )
720 wxUSTRING_COMP_OPERATORS( const wxCharBuffer
& )
721 wxUSTRING_COMP_OPERATORS( const wxU16CharBuffer
& )
722 wxUSTRING_COMP_OPERATORS( const wxU32CharBuffer
& )
723 wxUSTRING_COMP_OPERATORS( const wxCStrData
* )
726 // _WX_USTRING_H_BASE_