]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ustring.h
Added separate SetFocusOnCanvas() function so that m_editorFocused will be more relia...
[wxWidgets.git] / include / wx / ustring.h
1
2 // Name: wx/ustring.h
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 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_USTRING_H_BASE_
11 #define _WX_USTRING_H_BASE_
12
13 #include "wx/defs.h"
14 #include "wx/string.h"
15
16 #include <string>
17
18 #if SIZEOF_WCHAR_T == 2
19 typedef wxWCharBuffer wxU16CharBuffer;
20 #else
21 typedef wxCharTypeBuffer<wxChar16> wxU16CharBuffer;
22 #endif
23
24 #if SIZEOF_WCHAR_T == 4
25 typedef wxWCharBuffer wxU32CharBuffer;
26 #else
27 typedef wxCharTypeBuffer<wxChar32> wxU32CharBuffer;
28 #endif
29
30
31 class WXDLLIMPEXP_BASE wxUString: public std::basic_string<wxChar32>
32 {
33 public:
34 wxUString() { }
35
36 wxUString( const wxChar32 *str ) { assign(str); }
37 wxUString( const wxUString &str ) { assign(str); }
38 wxUString( const wxU32CharBuffer &buf ) { assign(buf); }
39
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); }
44
45 wxUString( const wxChar16 *str ) { assign(str); }
46 wxUString( const wxU16CharBuffer &buf ) { assign(buf); }
47
48 wxUString( const wxCStrData *cstr ) { assign(cstr); }
49 wxUString( const wxString &str ) { assign(str); }
50
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); }
61
62 // static construction
63
64 static wxUString FromAscii( const char *str, size_type n )
65 {
66 wxUString ret;
67 ret.assignFromAscii( str, n );
68 return ret;
69 }
70
71 static wxUString FromAscii( const char *str )
72 {
73 wxUString ret;
74 ret.assignFromAscii( str );
75 return ret;
76 }
77
78 static wxUString FromUTF8( const char *str, size_type n )
79 {
80 wxUString ret;
81 ret.assignFromUTF8( str, n );
82 return ret;
83 }
84
85 static wxUString FromUTF8( const char *str )
86 {
87 wxUString ret;
88 ret.assignFromUTF8( str );
89 return ret;
90 }
91
92 static wxUString FromUTF16( const wxChar16 *str, size_type n )
93 {
94 wxUString ret;
95 ret.assignFromUTF16( str, n );
96 return ret;
97 }
98
99 static wxUString FromUTF16( const wxChar16 *str )
100 {
101 wxUString ret;
102 ret.assignFromUTF16( str );
103 return ret;
104 }
105
106 // assign from encoding
107
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 );
116
117 // conversions
118
119 wxCharBuffer utf8_str() const;
120 wxU16CharBuffer utf16_str() const;
121
122 #if SIZEOF_WCHAR_T == 2
123 wxWCharBuffer wc_str() const
124 {
125 return utf16_str();
126 }
127 #else
128 wchar_t *wc_str() const
129 {
130 return (wchar_t*) c_str();
131 }
132 #endif
133
134 operator wxString() const
135 {
136 #if wxUSE_UNICODE_UTF8
137 return wxString::FromUTF8( utf8_str() );
138 #else
139 #if SIZEOF_WCHAR_T == 2
140 return wxString( utf16_str() );
141 #else
142 return wxString( c_str() );
143 #endif
144 #endif
145 }
146
147 #if wxUSE_UNICODE_UTF8
148 wxCharBuffer wx_str()
149 {
150 return utf8_str();
151 }
152 #else
153 #if SIZEOF_WCHAR_T == 2
154 wxWCharBuffer wx_str()
155 {
156 return utf16_str();
157 }
158 #else
159 const wchar_t* wx_str()
160 {
161 return c_str();
162 }
163 #endif
164 #endif
165
166 // assign
167
168 inline wxUString &assign( const wxChar32* str )
169 {
170 std::basic_string<wxChar32> *base = this;
171 return (wxUString &) base->assign( str );
172 }
173
174 inline wxUString &assign( const wxChar32* str, size_type n )
175 {
176 std::basic_string<wxChar32> *base = this;
177 return (wxUString &) base->assign( str, n );
178 }
179
180 inline wxUString &assign( const wxUString &str )
181 {
182 std::basic_string<wxChar32> *base = this;
183 return (wxUString &) base->assign( str );
184 }
185
186 inline wxUString &assign( const wxUString &str, size_type pos, size_type n )
187 {
188 std::basic_string<wxChar32> *base = this;
189 return (wxUString &) base->assign( str, pos, n );
190 }
191
192 inline wxUString &assign( wxChar32 ch )
193 {
194 std::basic_string<wxChar32> *base = this;
195 return (wxUString &) base->assign( (size_type) 1, ch );
196 }
197
198 inline wxUString &assign( size_type n, wxChar32 ch )
199 {
200 std::basic_string<wxChar32> *base = this;
201 return (wxUString &) base->assign( n, ch );
202 }
203
204 wxUString &assign( const wxU32CharBuffer &buf )
205 {
206 return assign( buf.data() );
207 }
208
209 wxUString &assign( const char *str )
210 {
211 return assignFromCString( str );
212 }
213
214 wxUString &assign( const wxCharBuffer &buf )
215 {
216 return assignFromCString( buf.data() );
217 }
218
219 wxUString &assign( const char *str, const wxMBConv &conv )
220 {
221 return assignFromCString( str, conv );
222 }
223
224 wxUString &assign( const wxCharBuffer &buf, const wxMBConv &conv )
225 {
226 return assignFromCString( buf.data(), conv );
227 }
228
229 wxUString &assign( const wxChar16 *str )
230 {
231 return assignFromUTF16( str );
232 }
233
234 wxUString &assign( const wxU16CharBuffer &buf )
235 {
236 return assignFromUTF16( buf.data() );
237 }
238
239 wxUString &assign( const wxCStrData *cstr )
240 {
241 #if SIZEOF_WCHAR_T == 2
242 return assignFromUTF16( cstr->AsWChar() );
243 #else
244 return assign( cstr->AsWChar() );
245 #endif
246 }
247
248 wxUString &assign( const wxString &str )
249 {
250 #if wxUSE_UNICODE_UTF8
251 return assignFromUTF8( str.wx_str() );
252 #else
253 #if SIZEOF_WCHAR_T == 2
254 return assignFromUTF16( str.wc_str() );
255 #else
256 return assign( str.wc_str() );
257 #endif
258 #endif
259 }
260
261 wxUString &assign( char ch )
262 {
263 char buf[2];
264 buf[0] = ch;
265 buf[1] = 0;
266 return assignFromCString( buf );
267 }
268
269 wxUString &assign( size_type n, char ch )
270 {
271 wxCharBuffer buffer(n);
272 char *p = buffer.data();
273 size_type i;
274 for (i = 0; i < n; i++)
275 {
276 *p = ch;
277 p++;
278 }
279 return assignFromCString( buffer.data() );
280 }
281
282 wxUString &assign( wxChar16 ch )
283 {
284 wxChar16 buf[2];
285 buf[0] = ch;
286 buf[1] = 0;
287 return assignFromUTF16( buf );
288 }
289
290 wxUString &assign( size_type n, wxChar16 ch )
291 {
292 wxU16CharBuffer buffer(n);
293 wxChar16 *p = buffer.data();
294 size_type i;
295 for (i = 0; i < n; i++)
296 {
297 *p = ch;
298 p++;
299 }
300 return assignFromUTF16( buffer.data() );
301 }
302
303 wxUString &assign( wxUniChar ch )
304 {
305 return assign( (const wxChar32) ch.GetValue() );
306 }
307
308 wxUString &assign( size_type n, wxUniChar ch )
309 {
310 return assign( n, (const wxChar32) ch.GetValue() );
311 }
312
313 wxUString &assign( wxUniCharRef ch )
314 {
315 return assign( (const wxChar32) ch.GetValue() );
316 }
317
318 wxUString &assign( size_type n, wxUniCharRef ch )
319 {
320 return assign( n, (const wxChar32) ch.GetValue() );
321 }
322
323 // append [STL overload]
324
325 inline wxUString &append( const wxUString &s )
326 {
327 std::basic_string<wxChar32> *base = this;
328 return (wxUString &) base->append( s );
329 }
330
331 inline wxUString &append( const wxUString &s, size_type pos, size_type n )
332 {
333 std::basic_string<wxChar32> *base = this;
334 return (wxUString &) base->append( s, pos, n );
335 }
336
337 inline wxUString &append( const wxChar32* s )
338 {
339 std::basic_string<wxChar32> *base = this;
340 return (wxUString &) base->append( s );
341 }
342
343 inline wxUString &append( const wxChar32* s, size_type n )
344 {
345 std::basic_string<wxChar32> *base = this;
346 return (wxUString &) base->append( s, n );
347 }
348
349 inline wxUString &append( size_type n, wxChar32 c )
350 {
351 std::basic_string<wxChar32> *base = this;
352 return (wxUString &) base->append( n, c );
353 }
354
355 inline wxUString &append( wxChar32 c )
356 {
357 std::basic_string<wxChar32> *base = this;
358 return (wxUString &) base->append( 1, c );
359 }
360
361 // append [wx overload]
362
363 wxUString &append( const wxU16CharBuffer &buf )
364 {
365 return append( buf.data() );
366 }
367
368 wxUString &append( const wxU32CharBuffer &buf )
369 {
370 return append( buf.data() );
371 }
372
373 wxUString &append( const char *str )
374 {
375 return append( wxUString( str ) );
376 }
377
378 wxUString &append( const wxCharBuffer &buf )
379 {
380 return append( wxUString( buf ) );
381 }
382
383 wxUString &append( const wxChar16 *str )
384 {
385 return append( wxUString( str ) );
386 }
387
388 wxUString &append( const wxString &str )
389 {
390 return append( wxUString( str ) );
391 }
392
393 wxUString &append( const wxCStrData *cstr )
394 {
395 return append( wxUString( cstr ) );
396 }
397
398 wxUString &append( char ch )
399 {
400 char buf[2];
401 buf[0] = ch;
402 buf[1] = 0;
403 return append( buf );
404 }
405
406 wxUString &append( wxChar16 ch )
407 {
408 wxChar16 buf[2];
409 buf[0] = ch;
410 buf[1] = 0;
411 return append( buf );
412 }
413
414 wxUString &append( wxUniChar ch )
415 {
416 return append( (size_type) 1, (wxChar32) ch.GetValue() );
417 }
418
419 wxUString &append( wxUniCharRef ch )
420 {
421 return append( (size_type) 1, (wxChar32) ch.GetValue() );
422 }
423
424
425 // insert [STL overloads]
426
427 inline wxUString &insert( size_type pos, const wxUString &s )
428 {
429 std::basic_string<wxChar32> *base = this;
430 return (wxUString &) base->insert( pos, s );
431 }
432
433 inline wxUString &insert( size_type pos, const wxUString &s, size_type pos1, size_type n )
434 {
435 std::basic_string<wxChar32> *base = this;
436 return (wxUString &) base->insert( pos, s, pos1, n );
437 }
438
439 inline wxUString &insert( size_type pos, const wxChar32 *s )
440 {
441 std::basic_string<wxChar32> *base = this;
442 return (wxUString &) base->insert( pos, s );
443 }
444
445 inline wxUString &insert( size_type pos, const wxChar32 *s, size_type n )
446 {
447 std::basic_string<wxChar32> *base = this;
448 return (wxUString &) base->insert( pos, s, n );
449 }
450
451 inline wxUString &insert( size_type pos, size_type n, wxChar32 c )
452 {
453 std::basic_string<wxChar32> *base = this;
454 return (wxUString &) base->insert( pos, n, c );
455 }
456
457
458 // insert [STL overloads]
459
460 wxUString &insert( size_type n, const char *s )
461 {
462 return insert( n, wxUString( s ) );
463 }
464
465 wxUString &insert( size_type n, const wxChar16 *s )
466 {
467 return insert( n, wxUString( s ) );
468 }
469
470 wxUString &insert( size_type n, const wxCharBuffer &buf )
471 {
472 return insert( n, wxUString( buf ) );
473 }
474
475 wxUString &insert( size_type n, const wxU16CharBuffer &buf )
476 {
477 return insert( n, wxUString( buf ) );
478 }
479
480 wxUString &insert( size_type n, const wxU32CharBuffer &buf )
481 {
482 return insert( n, buf.data() );
483 }
484
485 wxUString &insert( size_type n, const wxString &s )
486 {
487 return insert( n, wxUString( s ) );
488 }
489
490 wxUString &insert( size_type n, const wxCStrData *cstr )
491 {
492 return insert( n, wxUString( cstr ) );
493 }
494
495 wxUString &insert( size_type n, char ch )
496 {
497 char buf[2];
498 buf[0] = ch;
499 buf[1] = 0;
500 return insert( n, buf );
501 }
502
503 wxUString &insert( size_type n, wchar_t ch )
504 {
505 wchar_t buf[2];
506 buf[0] = ch;
507 buf[1] = 0;
508 return insert( n, buf );
509 }
510
511 // insert iterator
512
513 iterator insert( iterator it, wxChar32 ch )
514 {
515 std::basic_string<wxChar32> *base = this;
516 return base->insert( it, ch );
517 }
518
519 void insert(iterator it, const_iterator first, const_iterator last)
520 {
521 std::basic_string<wxChar32> *base = this;
522 base->insert( it, first, last );
523 }
524
525
526 // operator =
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 ); }
555
556 // operator +=
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 ); }
585
586 };
587
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; }
616
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; }
643
644
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; }
657
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; } \
671 \
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; }
684
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 * )
693
694 #endif
695 // _WX_USTRING_H_BASE_