Api-String.h
1/* Copyright (C) 2008 Marc Boris Duerner
2 SPDX-License-Identifier: LGPL-2.1-or-later WITH mif-exception
3*/
4
5#ifndef PT_API_STRING_H
6#define PT_API_STRING_H
7
8#include <Pt/Api.h>
9#include <Pt/Types.h>
10#include <Pt/Locale.h>
11#include <string>
12#include <iterator>
13#include <stdexcept>
14#include <cstring>
15#include <cctype>
16#include <cstddef>
17
18namespace Pt {
19
20//
21// Note copy from Pt/String.h and replace
22// String -> String
23// basic_string<Char> -> String
24// basic_string -> String
25//
26
66class String
67{
68 public:
69 typedef Pt::Char value_type;
70 typedef std::size_t size_type;
71 typedef char_traits< Pt::Char > traits_type;
72 typedef std::allocator<Pt::Char> allocator_type;
73 typedef allocator_type::difference_type difference_type;
74 typedef allocator_type::reference reference;
75 typedef allocator_type::const_reference const_reference;
76 typedef allocator_type::pointer pointer;
77 typedef allocator_type::const_pointer const_pointer;
78 typedef value_type* iterator;
79 typedef const value_type* const_iterator;
80
81#ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC
82 typedef std::reverse_iterator<const_iterator,
83 random_access_iterator_tag, value_type>
84 const_reverse_iterator;
85
86 typedef std::reverse_iterator<iterator,
87 random_access_iterator_tag, value_type>
88 reverse_iterator;
89#else
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef const std::reverse_iterator<const_iterator> const_reverse_iterator;
92#endif
93
94 static const size_type npos = static_cast<size_type>(-1);
95
96 public:
99 explicit String( const allocator_type& a = allocator_type());
100
103 String(const Pt::Char* str, const allocator_type& a = allocator_type());
104
107 String(const Pt::Char* str, size_type n, const allocator_type& a = allocator_type());
108
111 String(const wchar_t* str, const allocator_type& a = allocator_type());
112
115 String(const wchar_t* str, size_type n, const allocator_type& a = allocator_type());
116
119 String(const char* str, const allocator_type& a = allocator_type());
120
123 String(const char* str, size_type n, const allocator_type& a = allocator_type());
124
127 String(size_type n, Pt::Char c, const allocator_type& a = allocator_type());
128
131 String(const String& str);
132
135 String(const String& str, const allocator_type& a);
136
139 String(const String& str, size_type pos, size_type n = npos, const allocator_type& a = allocator_type());
140
143 String(const Pt::Char* begin, const Pt::Char* end, const allocator_type& a = allocator_type());
144
145 template <typename InputIterator>
146 String(InputIterator begin, InputIterator end, const allocator_type& a = allocator_type());
147
151
152 public:
155 iterator begin()
156 { return privdata_rw(); }
157
160 iterator end()
161 { return privdata_rw() + length(); }
162
165 const_iterator begin() const
166 { return privdata_ro(); }
167
170 const_iterator end() const
171 { return privdata_ro() + length(); }
172
175 reverse_iterator rbegin()
176 { return reverse_iterator( this->end() ); }
177
180 reverse_iterator rend()
181 { return reverse_iterator( this->begin() ); }
182
185 const_reverse_iterator rbegin() const
186 { return const_reverse_iterator( this->end() ); }
187
190 const_reverse_iterator rend() const
191 { return const_reverse_iterator( this->begin() ); }
192
195 reference operator[](size_type n)
196 { return privdata_rw()[n]; }
197
200 const_reference operator[](size_type n) const
201 { return privdata_ro()[n]; }
202
205 reference at(size_type n)
206 {
207 if( n >= size() )
208 throw out_of_range("at");
209
210 return privdata_rw()[n];
211 }
212
215 const_reference at(size_type n) const
216 {
217 if( n >= size() )
218 throw out_of_range("at");
219
220 return privdata_ro()[n];
221 }
222
223 public:
227 { (*this) += ch; }
228
231 void resize( std::size_t n, Pt::Char ch = value_type() );
232
235 void reserve(std::size_t n = 0);
236
239 void swap(String& str);
240
243 allocator_type get_allocator() const
244 { return _d; }
245
248 size_type copy(Pt::Char* a, size_type n, size_type pos = 0) const;
249
252 String substr(size_type pos = 0, size_type n = npos) const
253 { return String(*this, pos, n); }
254
255 public:
258 size_type length() const
259 { return isShortString() ? shortStringLength() : longStringLength(); }
260
263 size_type size() const
264 { return length(); }
265
268 bool empty() const
269 { return length() == 0; }
270
273 size_type max_size() const
274 { return ( size_type(-1) / sizeof(Pt::Char) ) - 1; }
275
278 size_type capacity() const
279 { return isShortString() ? shortStringCapacity() : longStringCapacity(); }
280
283 const Pt::Char* data() const
284 { return privdata_ro(); }
285
288 const Pt::Char* c_str() const
289 { return privdata_ro(); }
290
293 String& assign(const String& str);
294
297 String& assign(const String& str, size_type pos, size_type n);
298
301 String& assign(const wchar_t* str);
302
305 String& assign(const wchar_t* str, size_type n);
306
309 String& assign(const Pt::Char* str);
310
313 String& assign(const Pt::Char* str, size_type length);
314
317 String& assign(const char* str);
318
321 String& assign(const char* str, size_type length);
322
325 String& assign(size_type n, Pt::Char c);
326
327 template <typename InputIterator>
328 String& assign(InputIterator begin, InputIterator end);
329
332 String& append(const Pt::Char* str);
333
336 String& append(const Pt::Char* str, size_type n);
337
340 String& append(size_type n, Pt::Char ch);
341
344 String& append(const String& str);
345
348 String& append(const String& str, size_type pos, size_type n);
349
350 template <typename InputIterator>
351 String& append(InputIterator begin, InputIterator end);
352
356
359 String& insert(size_type pos, const Pt::Char* str);
360
363 String& insert(size_type pos, const Pt::Char* str, size_type n);
364
367 String& insert(size_type pos, size_type n, Pt::Char ch);
368
371 String& insert(size_type pos, const String& str);
372
375 String& insert(size_type pos, const String& str, size_type pos2, size_type n);
376
379 String& insert(iterator p, Pt::Char ch);
380
383 String& insert(iterator p, size_type n, Pt::Char ch);
384
385 // unimplemented
386 //template <typename InputIterator>
387 //String& insert(iterator p, InputIterator first, InputIterator last);
388
391 void clear()
392 { setLength(0); }
393
396 String& erase(size_type pos = 0, size_type n = npos);
397
400 iterator erase(iterator pos);
401
404 iterator erase(iterator first, iterator last);
405
408 String& replace(size_type pos, size_type n, const Pt::Char* str);
409
412 String& replace(size_type pos, size_type n, const Pt::Char* str, size_type n2);
413
416 String& replace(size_type pos, size_type n, size_type n2, Pt::Char ch);
417
420 String& replace(size_type pos, size_type n, const String& str);
421
424 String& replace(size_type pos, size_type n, const String& str, size_type pos2, size_type n2);
425
428 String& replace(iterator i1, iterator i2, const Pt::Char* str);
429
432 String& replace(iterator i1, iterator i2, const Pt::Char* str, size_type n);
433
436 String& replace(iterator i1, iterator i2, size_type n, Pt::Char ch);
437
440 String& replace(iterator i1, iterator i2, const String& str);
441
444 int compare(const String& str) const;
445
448 int compare(const Pt::Char* str) const;
449
452 int compare(const Pt::Char* str, size_type n) const;
453
456 int compare(const wchar_t* str) const;
457
460 int compare(const wchar_t* str, size_type n) const;
461
464 int compare(const char* str) const;
465
468 int compare(const char* str, size_type n) const;
469
472 int compare(size_type pos, size_type n, const String& str) const;
473
476 int compare(size_type pos, size_type n, const String& str, size_type pos2, size_type n2) const;
477
480 int compare(size_type pos, size_type n, const Pt::Char* str) const;
481
484 int compare(size_type pos, size_type n, const Pt::Char* str, size_type n2) const;
485
488 size_type find(const String& str, size_type pos = 0) const;
489
492 size_type find(const Pt::Char* str, size_type pos, size_type n) const;
493
496 size_type find(const Pt::Char* str, size_type pos = 0) const;
497
500 size_type find(Pt::Char ch, size_type pos = 0) const;
501
504 size_type rfind(const String& str, size_type pos = npos) const;
505
508 size_type rfind(const Pt::Char* str, size_type pos, size_type n) const;
509
512 size_type rfind(const Pt::Char* str, size_type pos = npos) const;
513
516 size_type rfind(Pt::Char ch, size_type pos = npos) const;
517
520 size_type find_first_of(const String& str, size_type pos = 0) const
521 { return this->find_first_of( str.data(), pos, str.size() ); }
522
525 size_type find_first_of(const Pt::Char* s, size_type pos, size_type n) const;
526
529 size_type find_first_of(const Pt::Char* str, size_type pos = 0) const
530 { return this->find_first_of( str, pos, traits_type::length(str) ); }
531
534 size_type find_first_of(const Pt::Char ch, size_type pos = 0) const
535 { return this->find(ch, pos); }
536
539 size_type find_last_of(const String& str, size_type pos = npos) const
540 { return this->find_last_of( str.data(), pos, str.size() ); }
541
544 size_type find_last_of(const Pt::Char* s, size_type pos, size_type n) const;
545
548 size_type find_last_of(const Pt::Char* str, size_type pos = npos) const
549 { return this->find_last_of( str, pos, traits_type::length(str) ); }
550
553 size_type find_last_of(const Pt::Char ch, size_type pos = npos) const
554 { return this->rfind(ch, pos); }
555
558 size_type find_first_not_of(const String& str, size_type pos = 0) const
559 { return this->find_first_not_of( str.data(), pos, str.size() ); }
560
563 size_type find_first_not_of(const Pt::Char* s, size_type pos, size_type n) const;
564
567 size_type find_first_not_of(const Pt::Char* str, size_type pos = 0) const
568 { return this->find_first_not_of( str, pos, traits_type::length(str) ); }
569
572 size_type find_first_not_of(const Pt::Char ch, size_type pos = 0) const;
573
576 size_type find_last_not_of(const String& str, size_type pos = npos) const
577 { return this->find_last_not_of( str.data(), pos, str.size() ); }
578
581 size_type find_last_not_of(const Pt::Char* tok, size_type pos, size_type n) const;
582
585 size_type find_last_not_of(const Pt::Char* str, size_type pos = npos) const
586 { return this->find_last_not_of( str, pos, traits_type::length(str) ); }
587
590 size_type find_last_not_of(Pt::Char ch, size_type pos = npos) const;
591
592 public:
595 std::string narrow(char dfault = '?') const;
596
599 static String widen(const char* str);
600
603 static String widen(const std::string& str);
604
607 template <typename OutIterT>
608 OutIterT toUtf16(OutIterT to) const;
609
612 template <typename InIterT>
613 static String fromUtf16(InIterT from, InIterT fromEnd);
614
615 public:
619 { return this->assign(str); }
620
623 String& operator=(const wchar_t* str)
624 { return this->assign(str); }
625
628 String& operator=(const char* str)
629 { return this->assign(str); }
630
634 { return this->assign(str); }
635
639 {
640 // no privreserve(1), short string capacity is large enough
641
642 Pt::Char* p = privdata_rw();
643 p[0] = ch;
644 setLength(1);
645 return *this;
646 }
647
651 { return this->append(str); }
652
656 { return this->append(str); }
657
661
662 private:
663 struct Ptr
664 {
665 Pt::Char* _begin;
666 Pt::Char* _end;
667 Pt::Char* _capacity;
668 };
669
670 // minimum possible short string character count
671 static const unsigned _minN = (sizeof(Ptr) / sizeof(Pt::Char)) + 1;
672
673 // short string character count
674 static const unsigned _nN = _minN < 8 ? 8 : _minN;
675
676 // short string raw storage size in bytes
677 static const unsigned _nS = _nN * sizeof(Pt::Char);
678
679 struct Data : public allocator_type
680 {
681 Data(const allocator_type& a)
682 : allocator_type(a)
683 {
684 Pt::Char* str = reinterpret_cast<Pt::Char*>(&_u._s[0]);
685 *str = 0;
686
687 _u._s[_nS - 1] = _nN - 1;
688 }
689
690 union
691 {
692 Ptr _p;
693 unsigned char _s[_nS];
694 } _u;
695 } _d;
696
697 private:
698 const Pt::Char* privdata_ro() const
699 { return isShortString() ? shortStringData() : longStringData(); }
700
701 Pt::Char* privdata_rw()
702 { return isShortString() ? shortStringData() : longStringData(); }
703
704 void privreserve(std::size_t n);
705
706 bool isShortString() const
707 { return shortStringMagic() != 0xff; }
708
709 void markLongString()
710 { shortStringMagic() = 0xff; }
711
712 const Pt::Char* shortStringData() const
713 { return reinterpret_cast<const Pt::Char*>(&_d._u._s[0]); }
714
715 Pt::Char* shortStringData()
716 { return reinterpret_cast<Pt::Char*>(&_d._u._s[0]); }
717
718 unsigned char shortStringMagic() const
719 { return _d._u._s[_nS - 1]; }
720
721 unsigned char& shortStringMagic()
722 { return _d._u._s[_nS - 1]; }
723
724 size_type shortStringLength() const
725 { return _nN - 1 - shortStringMagic(); }
726
727 size_type shortStringCapacity() const
728 { return _nN - 1; }
729
730 void setShortStringLength(size_type n)
731 {
732 shortStringData()[n] = Pt::Char(0);
733 shortStringMagic() = static_cast<unsigned char>(_nN - n - 1);
734 }
735
736 void shortStringAssign(const Pt::Char* str, size_type n)
737 {
738 traits_type::copy(shortStringData(), str, n);
739 shortStringData()[n] = Pt::Char(0);
740 shortStringMagic() = static_cast<unsigned char>(_nN - n - 1);
741 }
742 void shortStringAssign(const wchar_t* str, size_type n)
743 {
744 for (size_type nn = 0; nn < n; ++nn)
745 shortStringData()[nn] = str[nn];
746 shortStringData()[n] = Pt::Char(0);
747 shortStringMagic() = static_cast<unsigned char>(_nN - n - 1);
748 }
749
750 const Pt::Char* longStringData() const
751 { return _d._u._p._begin; }
752
753 Pt::Char* longStringData()
754 { return _d._u._p._begin; }
755
756 size_type longStringLength() const
757 { return _d._u._p._end - _d._u._p._begin; }
758
759 size_type longStringCapacity() const
760 { return _d._u._p._capacity - _d._u._p._begin; }
761
762 void setLength(size_type n)
763 {
764 if (isShortString())
765 setShortStringLength(n);
766 else
767 {
768 _d._u._p._end = _d._u._p._begin + n;
769 _d._u._p._begin[n] = 0;
770 }
771 }
772};
773
778inline void swap(String& a, String& b)
779{ a.swap(b); }
780
781// operator +
782
787inline String operator+(const String& a, const String& b)
788{ String temp; temp += a; temp += b; return temp; }
789
794inline String operator+(const String& a, const Pt::Char* b)
795{ String temp; temp += a; temp += b; return temp; }
796
801inline String operator+(const Pt::Char* a, const String& b)
802{ String temp; temp += a; temp += b; return temp; }
803
808inline String operator+(const String& a, Pt::Char b)
809{ String temp; temp += a; temp += b; return temp; }
810
815inline String operator+(Pt::Char a, const String& b)
816{ String temp; temp += a; temp += b; return temp; }
817
818// operator ==
819
824inline bool operator==(const String& a, const String& b)
825{ return a.compare(b) == 0; }
826
831inline bool operator==(const Pt::Char* a, const String& b)
832{ return b.compare(a) == 0; }
833
838inline bool operator==(const String& a, const Pt::Char* b)
839{ return a.compare(b) == 0; }
840
845inline bool operator==(const String& a, const wchar_t* b)
846{ return a.compare(b) == 0; }
847
852inline bool operator==(const wchar_t* b, const String& a)
853{ return a.compare(b) == 0; }
854
859inline bool operator==(const String& a, const char* b)
860{ return a.compare(b) == 0; }
861
866inline bool operator==(const char* b, const String& a)
867{ return a.compare(b) == 0; }
868
869// operator !=
870
875inline bool operator!=(const String& a, const String& b)
876{ return a.compare(b) != 0; }
877
882inline bool operator!=(const Pt::Char* a, const String& b)
883{ return b.compare(a) != 0; }
884
889inline bool operator!=(const String& a, const Pt::Char* b)
890{ return a.compare(b) != 0; }
891
896inline bool operator!=(const String& a, const wchar_t* b)
897{ return a.compare(b) != 0; }
898
903inline bool operator!=(const wchar_t* b, const String& a)
904{ return a.compare(b) != 0; }
905
910inline bool operator!=(const String& a, const char* b)
911{ return a.compare(b) != 0; }
912
917inline bool operator!=(const char* b, const String& a)
918{ return a.compare(b) != 0; }
919
920// operator <
921
926inline bool operator<(const String& a, const String& b)
927{ return a.compare(b) < 0; }
928
933inline bool operator<(const Pt::Char* a, const String& b)
934{ return b.compare(a) > 0; }
935
940inline bool operator<(const String& a, const Pt::Char* b)
941{ return a.compare(b) < 0; }
942
947inline bool operator<(const String& a, const wchar_t* b)
948{ return a.compare(b) < 0; }
949
954inline bool operator<(const wchar_t* b, const String& a)
955{ return a.compare(b) > 0; }
956
961inline bool operator<(const String& a, const char* b)
962{ return a.compare(b) < 0; }
963
968inline bool operator<(const char* b, const String& a)
969{ return a.compare(b) > 0; }
970
971// operator <=
972
977inline bool operator<=(const String& a, const String& b)
978{ return a.compare(b) <= 0; }
979
984inline bool operator<=(const Pt::Char* a, const String& b)
985{ return b.compare(a) >= 0; }
986
991inline bool operator<=(const String& a, const Pt::Char* b)
992{ return a.compare(b) <= 0; }
993
998inline bool operator<=(const String& a, const wchar_t* b)
999{ return a.compare(b) <= 0; }
1000
1005inline bool operator<=(const wchar_t* b, const String& a)
1006{ return a.compare(b) >= 0; }
1007
1012inline bool operator<=(const String& a, const char* b)
1013{ return a.compare(b) <= 0; }
1014
1019inline bool operator<=(const char* b, const String& a)
1020{ return a.compare(b) >= 0; }
1021
1022// operator >
1023
1028inline bool operator>(const String& a, const String& b)
1029{ return a.compare(b) > 0; }
1030
1035inline bool operator>(const Pt::Char* a, const String& b)
1036{ return b.compare(a) < 0; }
1037
1042inline bool operator>(const String& a, const Pt::Char* b)
1043{ return a.compare(b) > 0; }
1044
1049inline bool operator>(const String& a, const wchar_t* b)
1050{ return a.compare(b) > 0; }
1051
1056inline bool operator>(const wchar_t* b, const String& a)
1057{ return a.compare(b) < 0; }
1058
1063inline bool operator>(const String& a, const char* b)
1064{ return a.compare(b) > 0; }
1065
1070inline bool operator>(const char* b, const String& a)
1071{ return a.compare(b) < 0; }
1072
1073// operator >=
1074
1079inline bool operator>=(const String& a, const String& b)
1080{ return a.compare(b) >= 0; }
1081
1086inline bool operator>=(const Pt::Char* a, const String& b)
1087{ return b.compare(a) <= 0; }
1088
1093inline bool operator>=(const String& a, const Pt::Char* b)
1094{ return a.compare(b) >= 0; }
1095
1100inline bool operator>=(const String& a, const wchar_t* b)
1101{ return a.compare(b) >= 0; }
1102
1107inline bool operator>=(const wchar_t* b, const String& a)
1108{ return a.compare(b) <= 0; }
1109
1114inline bool operator>=(const String& a, const char* b)
1115{ return a.compare(b) >= 0; }
1116
1121inline bool operator>=(const char* b, const String& a)
1122{ return a.compare(b) <= 0; }
1123
1128PT_API ostream& operator<< (ostream& out, const String& str);
1129
1130} // namespace Pt
1131
1132
1133#endif
void swap(String &str)
Swaps with another string.
String(const char *str, size_type n, const allocator_type &a=allocator_type())
Constructor.
String & operator=(const String &str)
Assignment operator.
Definition Api-String.h:618
String & assign(const Pt::Char *str)
Assign content to the string.
const_reverse_iterator rend() const
Returns an reverse iterator to the begin of the string.
Definition Api-String.h:190
size_type find_last_not_of(const Pt::Char *str, size_type pos=npos) const
Find content in the string.
Definition Api-String.h:585
bool operator<=(const wchar_t *b, const String &a)
Compares two strings.
Definition Api-String.h:1005
size_type rfind(const Pt::Char *str, size_type pos, size_type n) const
Find content in the string.
size_type find_last_not_of(const Pt::Char *tok, size_type pos, size_type n) const
Find content in the string.
String & operator+=(const String &str)
Append a string.
Definition Api-String.h:650
bool operator<=(const char *b, const String &a)
Compares two strings.
Definition Api-String.h:1019
String & replace(iterator i1, iterator i2, const Pt::Char *str, size_type n)
Replace portion of the string.
size_type find_first_not_of(const Pt::Char *s, size_type pos, size_type n) const
Find content in the string.
bool operator!=(const String &a, const char *b)
Compares two strings.
Definition Api-String.h:910
void swap(String &a, String &b)
Swaps two strings.
Definition Api-String.h:778
String & insert(size_type pos, size_type n, Pt::Char ch)
Insert into string.
String & replace(iterator i1, iterator i2, const String &str)
Replace portion of the string.
String & assign(const wchar_t *str)
Assign content to the string.
String & assign(const wchar_t *str, size_type n)
Assign content to the string.
bool operator<(const String &a, const Pt::Char *b)
Compares two strings.
Definition Api-String.h:940
bool operator==(const char *b, const String &a)
Compares two strings.
Definition Api-String.h:866
bool operator<(const wchar_t *b, const String &a)
Compares two strings.
Definition Api-String.h:954
bool operator>(const Pt::Char *a, const String &b)
Compares two strings.
Definition Api-String.h:1035
bool operator<(const char *b, const String &a)
Compares two strings.
Definition Api-String.h:968
bool operator!=(const String &a, const String &b)
Compares two strings.
Definition Api-String.h:875
const_iterator begin() const
Returns an iterator to the begin of the string.
Definition Api-String.h:165
size_type rfind(const Pt::Char *str, size_type pos=npos) const
Find content in the string.
size_type find_first_not_of(const Pt::Char *str, size_type pos=0) const
Find content in the string.
Definition Api-String.h:567
bool operator>(const String &a, const char *b)
Compares two strings.
Definition Api-String.h:1063
String(const wchar_t *str, size_type n, const allocator_type &a=allocator_type())
Constructor.
bool operator<(const Pt::Char *a, const String &b)
Compares two strings.
Definition Api-String.h:933
size_type find(const Pt::Char *str, size_type pos=0) const
Find content in the string.
String(const String &str)
Copy Constructor.
int compare(const char *str, size_type n) const
Compare strings.
size_type find_last_not_of(const String &str, size_type pos=npos) const
Find content in the string.
Definition Api-String.h:576
String & replace(size_type pos, size_type n, size_type n2, Pt::Char ch)
Replace portion of the string.
String operator+(Pt::Char a, const String &b)
Concatenates two strings.
Definition Api-String.h:815
String & replace(size_type pos, size_type n, const String &str)
Replace portion of the string.
String & append(const Pt::Char *str, size_type n)
Append content to the string.
int compare(size_type pos, size_type n, const Pt::Char *str) const
Compare strings.
String & operator+=(Pt::Char c)
Append a character.
String(const Pt::Char *str, size_type n, const allocator_type &a=allocator_type())
Constructor.
bool operator>=(const char *b, const String &a)
Compares two strings.
Definition Api-String.h:1121
bool operator>(const String &a, const Pt::Char *b)
Compares two strings.
Definition Api-String.h:1042
int compare(const String &str) const
Compare strings.
void resize(std::size_t n, Pt::Char ch=value_type())
Resizes the string.
String & assign(const char *str)
Assign content to the string.
bool operator<=(const String &a, const String &b)
Compares two strings.
Definition Api-String.h:977
String(const Pt::Char *str, const allocator_type &a=allocator_type())
Constructor.
size_type find_first_not_of(const String &str, size_type pos=0) const
Find content in the string.
Definition Api-String.h:558
bool operator==(const String &a, const String &b)
Compares two strings.
Definition Api-String.h:824
size_type find_last_of(const String &str, size_type pos=npos) const
Find content in the string.
Definition Api-String.h:539
String(const Pt::Char *begin, const Pt::Char *end, const allocator_type &a=allocator_type())
Constructor.
String & insert(size_type pos, const Pt::Char *str)
Insert into string.
static String widen(const char *str)
Widen 8-bit string .
String & replace(iterator i1, iterator i2, const Pt::Char *str)
Replace portion of the string.
size_type find_first_of(const String &str, size_type pos=0) const
Find content in the string.
Definition Api-String.h:520
bool operator>=(const Pt::Char *a, const String &b)
Compares two strings.
Definition Api-String.h:1086
size_type rfind(Pt::Char ch, size_type pos=npos) const
Find content in the string.
size_type find(const String &str, size_type pos=0) const
Find content in the string.
size_type size() const
Returns the length of the string.
Definition Api-String.h:263
int compare(size_type pos, size_type n, const Pt::Char *str, size_type n2) const
Compare strings.
int compare(const wchar_t *str, size_type n) const
Compare strings.
bool empty() const
Returns true if empty.
Definition Api-String.h:268
bool operator<=(const Pt::Char *a, const String &b)
Compares two strings.
Definition Api-String.h:984
size_type find_last_of(const Pt::Char ch, size_type pos=npos) const
Find content in the string.
Definition Api-String.h:553
reverse_iterator rend()
Returns an reverse iterator to the begin of the string.
Definition Api-String.h:180
String & operator=(Pt::Char ch)
Assignment operator.
Definition Api-String.h:638
String operator+(const String &a, const Pt::Char *b)
Concatenates two strings.
Definition Api-String.h:794
String & insert(size_type pos, const String &str)
Insert into string.
allocator_type get_allocator() const
Returns the used allocator.
Definition Api-String.h:243
String & replace(size_type pos, size_type n, const String &str, size_type pos2, size_type n2)
Replace portion of the string.
bool operator>=(const String &a, const Pt::Char *b)
Compares two strings.
Definition Api-String.h:1093
size_type copy(Pt::Char *a, size_type n, size_type pos=0) const
Copy characters to a buffer.
int compare(size_type pos, size_type n, const String &str) const
Compare strings.
bool operator<(const String &a, const String &b)
Compares two strings.
Definition Api-String.h:926
size_type find_first_of(const Pt::Char *s, size_type pos, size_type n) const
Find content in the string.
std::string narrow(char dfault='?') const
Narrow string to 8-bit.
String operator+(const String &a, Pt::Char b)
Concatenates two strings.
Definition Api-String.h:808
bool operator>=(const String &a, const wchar_t *b)
Compares two strings.
Definition Api-String.h:1100
bool operator<=(const String &a, const char *b)
Compares two strings.
Definition Api-String.h:1012
void reserve(std::size_t n=0)
Reserves space.
String & replace(size_type pos, size_type n, const Pt::Char *str)
Replace portion of the string.
bool operator==(const String &a, const char *b)
Compares two strings.
Definition Api-String.h:859
String(const String &str, const allocator_type &a)
Constructor.
OutIterT toUtf16(OutIterT to) const
Convert to UTF-16.
String(const String &str, size_type pos, size_type n=npos, const allocator_type &a=allocator_type())
Constructor.
String & append(const String &str)
Append content to the string.
String(const char *str, const allocator_type &a=allocator_type())
Constructor.
int compare(const Pt::Char *str) const
Compare strings.
size_type find(Pt::Char ch, size_type pos=0) const
Find content in the string.
void push_back(Pt::Char ch)
Append a character.
Definition Api-String.h:226
bool operator!=(const Pt::Char *a, const String &b)
Compares two strings.
Definition Api-String.h:882
String & assign(const String &str)
Assign content to the string.
size_type max_size() const
Returns the maximum possible length.
Definition Api-String.h:273
const_reference at(size_type n) const
Random access to characters.
Definition Api-String.h:215
~String()
Destructor.
String & replace(size_type pos, size_type n, const Pt::Char *str, size_type n2)
Replace portion of the string.
int compare(size_type pos, size_type n, const String &str, size_type pos2, size_type n2) const
Compare strings.
static String widen(const std::string &str)
Widen 8-bit string .
bool operator!=(const char *b, const String &a)
Compares two strings.
Definition Api-String.h:917
String & assign(const String &str, size_type pos, size_type n)
Assign content to the string.
String & append(const Pt::Char *begin, const Pt::Char *end)
Append content to the string.
bool operator<(const String &a, const char *b)
Compares two strings.
Definition Api-String.h:961
String & append(const Pt::Char *str)
Append content to the string.
bool operator!=(const wchar_t *b, const String &a)
Compares two strings.
Definition Api-String.h:903
size_type find(const Pt::Char *str, size_type pos, size_type n) const
Find content in the string.
reference operator[](size_type n)
Random access to characters.
Definition Api-String.h:195
String & append(const String &str, size_type pos, size_type n)
Append content to the string.
bool operator==(const String &a, const Pt::Char *b)
Compares two strings.
Definition Api-String.h:838
String & operator=(const wchar_t *str)
Assignment operator.
Definition Api-String.h:623
size_type find_last_of(const Pt::Char *s, size_type pos, size_type n) const
Find content in the string.
String & operator+=(const Pt::Char *str)
Append a string.
Definition Api-String.h:655
bool operator<(const String &a, const wchar_t *b)
Compares two strings.
Definition Api-String.h:947
const_reference operator[](size_type n) const
Random access to characters.
Definition Api-String.h:200
String & erase(size_type pos=0, size_type n=npos)
Erase characters from the string.
bool operator>(const String &a, const String &b)
Compares two strings.
Definition Api-String.h:1028
bool operator>(const char *b, const String &a)
Compares two strings.
Definition Api-String.h:1070
String(const wchar_t *str, const allocator_type &a=allocator_type())
Constructor.
String & insert(size_type pos, const Pt::Char *str, size_type n)
Insert into string.
String(const allocator_type &a=allocator_type())
Default Constructor.
String & assign(const Pt::Char *str, size_type length)
Assign content to the string.
bool operator>(const String &a, const wchar_t *b)
Compares two strings.
Definition Api-String.h:1049
String & assign(const char *str, size_type length)
Assign content to the string.
size_type length() const
Returns the length of the string.
Definition Api-String.h:258
size_type find_first_of(const Pt::Char *str, size_type pos=0) const
Find content in the string.
Definition Api-String.h:529
bool operator==(const String &a, const wchar_t *b)
Compares two strings.
Definition Api-String.h:845
void clear()
Clears the string.
Definition Api-String.h:391
String operator+(const String &a, const String &b)
Concatenates two strings.
Definition Api-String.h:787
iterator end()
Returns an iterator to the end of the string.
Definition Api-String.h:160
size_type find_last_of(const Pt::Char *str, size_type pos=npos) const
Find content in the string.
Definition Api-String.h:548
bool operator<=(const String &a, const Pt::Char *b)
Compares two strings.
Definition Api-String.h:991
const Pt::Char * c_str() const
Returns a null terminated C string.
Definition Api-String.h:288
const_iterator end() const
Returns an iterator to the end of the string.
Definition Api-String.h:170
reverse_iterator rbegin()
Returns an reverse iterator to the end of the string.
Definition Api-String.h:175
bool operator!=(const String &a, const Pt::Char *b)
Compares two strings.
Definition Api-String.h:889
String & insert(size_type pos, const String &str, size_type pos2, size_type n)
Insert into string.
size_type capacity() const
Returns the capacity.
Definition Api-String.h:278
int compare(const wchar_t *str) const
Compare strings.
String & replace(iterator i1, iterator i2, size_type n, Pt::Char ch)
Replace portion of the string.
String & insert(iterator p, Pt::Char ch)
Insert into string.
size_type find_last_not_of(Pt::Char ch, size_type pos=npos) const
Find content in the string.
bool operator>=(const wchar_t *b, const String &a)
Compares two strings.
Definition Api-String.h:1107
iterator begin()
Returns an iterator to the begin of the string.
Definition Api-String.h:155
int compare(const char *str) const
Compare strings.
String(size_type n, Pt::Char c, const allocator_type &a=allocator_type())
Constructor.
size_type find_first_of(const Pt::Char ch, size_type pos=0) const
Find content in the string.
Definition Api-String.h:534
String & append(size_type n, Pt::Char ch)
Append content to the string.
bool operator!=(const String &a, const wchar_t *b)
Compares two strings.
Definition Api-String.h:896
bool operator>=(const String &a, const char *b)
Compares two strings.
Definition Api-String.h:1114
reference at(size_type n)
Random access to characters.
Definition Api-String.h:205
size_type rfind(const String &str, size_type pos=npos) const
Find content in the string.
String & insert(iterator p, size_type n, Pt::Char ch)
Insert into string.
bool operator<=(const String &a, const wchar_t *b)
Compares two strings.
Definition Api-String.h:998
static String fromUtf16(InIterT from, InIterT fromEnd)
Convert from UTF-16.
bool operator>=(const String &a, const String &b)
Compares two strings.
Definition Api-String.h:1079
String operator+(const Pt::Char *a, const String &b)
Concatenates two strings.
Definition Api-String.h:801
const_reverse_iterator rbegin() const
Returns an reverse iterator to the end of the string.
Definition Api-String.h:185
int compare(const Pt::Char *str, size_type n) const
Compare strings.
bool operator>(const wchar_t *b, const String &a)
Compares two strings.
Definition Api-String.h:1056
String & operator=(const char *str)
Assignment operator.
Definition Api-String.h:628
String & operator=(const Pt::Char *str)
Assignment operator.
Definition Api-String.h:633
String & assign(size_type n, Pt::Char c)
Assign content to the string.
iterator erase(iterator pos)
Erase characters from the string.
const Pt::Char * data() const
Returns the string character buffer.
Definition Api-String.h:283
iterator erase(iterator first, iterator last)
Erase characters from the string.
size_type find_first_not_of(const Pt::Char ch, size_type pos=0) const
Find content in the string.
bool operator==(const Pt::Char *a, const String &b)
Compares two strings.
Definition Api-String.h:831
String substr(size_type pos=0, size_type n=npos) const
Returns a substring.
Definition Api-String.h:252
bool operator==(const wchar_t *b, const String &a)
Compares two strings.
Definition Api-String.h:852
Core module.
Definition Allocator.h:33
Unicode character type.
Definition String.h:67