5 #ifndef CMR_STRING_INCLUDED
6 #define CMR_STRING_INCLUDED
42 friend class Iterator;
58 typedef Char value_type;
59 typedef size_t size_type;
60 typedef Char& reference;
61 typedef const Char& const_reference;
62 typedef Char* pointer;
63 typedef const Char* const_pointer;
65 enum { STRING_INCREMENT_SIZE = 16 };
76 String(
const String& str,
size_t pos,
size_t n = (
size_t)npos);
82 String(
const Char* str,
size_t n);
93 String(
const AChar* str,
size_t n);
106 String& operator = (
const String& str) {
return assign(str); }
112 String& operator = (
const AChar* str) {
return assign(str); }
117 String& operator = (
const Char* str) {
return assign(str); }
122 String& operator = (Char c) { assign_helper(c, 1);
return *
this; }
129 bool operator == (
const AChar* str)
const {
return compare(str) == 0; }
133 bool operator == (
const String& str)
const {
return compare(str) == 0; }
137 bool operator == (
const Char* str)
const {
return compare(str) == 0; }
141 bool operator != (
const AChar* str)
const {
return !compare(str) == 0; }
145 bool operator != (
const String& str)
const {
return !compare(str) == 0; }
149 bool operator != (
const Char* str)
const {
return !compare(str) == 0; }
162 String& operator += (
const Char* str) {
return append(str); }
166 String& operator += (
const AChar* str) {
return append(str); }
170 String& operator += (Char c) { append_helper(c, 1);
return *
this; }
174 String& operator += (AChar c) { append_helper(c, 1);
return *
this; }
179 inline bool operator < (
const String& s)
const;
183 inline bool operator > (
const String& s)
const;
191 append_helper(str, 0, (
size_t)npos);
203 append_helper(str, pos, n);
213 append_helper(str, n);
223 append_helper(str, n);
232 append_helper(str, length(str));
241 append_helper(str, length(str));
272 if (*len > (s - pos))
290 assign_helper(str.data_->
data + pos, n);
299 assign_helper(str, n);
307 assign_helper(str, length(str));
323 assign_helper(str, n);
331 assign_helper(str, length(str));
359 replace_helper(pos1, 0, str, 0, (
size_t)npos);
371 replace_helper(pos1, 0, str, pos2, n);
382 replace_helper(pos, 0, str, n);
392 replace_helper(pos, 0, str, length(str));
403 replace_helper(pos, 0, c, n);
423 replace_helper(pos, n, (
const Char*)0, 0);
435 replace_helper(pos1, n1, str, 0, str.
size());
449 replace_helper(pos1, n1, str, pos2, n2);
461 replace_helper(pos, n1, str, n2);
472 replace_helper(pos, n1, str, length(str));
484 replace_helper(pos, n1, c, n2);
494 return pos == size() ? eos() : get_at(pos);
505 return *(data_->data + pos);
516 Char
at(
size_t pos)
const
526 return operator[](pos);
535 return data_ ? data_->data : nil_data();
540 operator const Char* ()
const
549 return data_ ? data_->data : nil_data();
578 return (
size_t)npos - 1;
607 return data_->capacity;
615 reserve_helper(size);
628 size_t copy(Char* str,
size_t n,
size_t pos = 0)
const
630 if (validate_range(pos, &n))
632 copy(str, data_->data + pos, n);
657 return find(str.
data(), pos, str.
size());
659 size_t find(
const Char* s,
size_t pos,
size_t n)
const;
660 size_t find(
const Char* str,
size_t pos = 0)
const
662 return find(str, pos, length(str));
664 size_t find(Char c,
size_t pos = 0)
const
666 return find(&c, pos, 1);
668 size_t find_first_of(
const String& str,
size_t pos = 0)
const
670 return find_first_of(str.data(), pos, str.size());
672 size_t find_first_of(
const Char* s,
size_t pos,
size_t n)
const;
673 size_t find_first_of(
const Char* str,
size_t pos = 0)
const
675 return find_first_of(str, pos, length(str));
677 size_t find_first_of(Char c,
size_t pos = 0)
const
679 return find_first_of(&c, pos, 1);
681 size_t find_first_not_of(
const String& str,
size_t pos = 0)
const
683 return find_first_not_of(str.data(), pos, str.size());
685 size_t find_first_not_of(
const Char* s,
size_t pos,
size_t n)
const;
686 size_t find_first_not_of(Char c,
size_t pos = 0)
const
688 return find_first_not_of(&c, pos, 1);
690 size_t find_first_not_of(
const Char* str,
size_t pos = 0)
const
692 return find_first_not_of(str, pos, length(str));
694 size_t rfind(
const Char* str,
size_t pos,
size_t n)
const;
695 size_t find_last_of(
const Char* s,
size_t pos,
size_t n)
const;
696 size_t find_last_not_of(
const Char* s,
size_t pos,
size_t n)
const;
697 size_t rfind(
const String& str,
size_t pos = (
size_t)npos)
const
699 return rfind(str.data(), pos, str.size());
701 size_t rfind(
const Char* str,
size_t pos = (
size_t)npos)
const
703 return rfind(str, pos, length(str));
705 size_t rfind(Char c,
size_t pos = (
size_t)npos)
const
707 return rfind(&c, pos, 1);
709 size_t find_last_of(
const String& str,
size_t pos = (
size_t)npos)
const
711 return find_last_of(str.data(), pos, str.size());
713 size_t find_last_of(Char c,
size_t pos = (
size_t)npos)
const
715 return find_last_of(&c, pos, 1);
717 size_t find_last_of(
const Char* str,
size_t pos = (
size_t)npos)
const
719 return find_last_of(str, pos, length(str));
721 size_t find_last_not_of(
const String& str,
size_t pos = (
size_t)npos)
const
723 return find_last_not_of(str.data(), pos, str.size());
725 size_t find_last_not_of(
const Char& c,
size_t pos = (
size_t)npos)
const
727 return find_last_not_of(&c, pos, 1);
729 size_t find_last_not_of(
const Char* str,
size_t pos = (
size_t)npos)
const
731 return find_last_not_of(str, pos, length(str));
733 String substr(
size_t pos = 0,
size_t n = (
size_t)npos)
const;
734 int compare(
const String& str)
const
736 return compare_helper(str, 0, (
size_t)npos);
738 int compare(
size_t pos,
size_t n,
const String& str)
const
740 return compare_helper(str, pos, n);
742 int compare(
size_t pos1,
size_t n1,
const String& str,
size_t pos2,
size_t n2)
const
744 String temp(str, pos2, n2);
745 return compare_helper(temp, pos1, n1);
747 int compare(
const Char* s)
const
749 return compare_helper(s, 0, length(s));
751 int compare(
const AChar* s)
const
753 return compare_helper(s, 0, length(s));
755 int compare(
size_t pos,
size_t n1,
const Char* str,
size_t n2 = (
size_t)npos)
const;
757 int icompare(
const String& str)
const
759 return icompare_helper(str, 0, (
size_t)npos);
761 int icompare(
size_t pos,
size_t n,
const String& str)
const
763 return icompare_helper(str, pos, n);
765 int icompare(
size_t pos1,
size_t n1,
const String& str,
size_t pos2,
size_t n2)
const
767 String temp(str, pos2, n2);
768 return icompare_helper(temp, pos1, n1);
770 int icompare(
const Char* s)
const
772 return icompare_helper(s, 0, length(s));
774 int icompare(
const AChar* s)
const
776 return icompare_helper(s, 0, length(s));
778 int icompare(
size_t pos,
size_t n1,
const Char* str,
size_t n2 = (
size_t)npos)
const;
781 String& make_upper();
782 String& make_lower();
783 bool match(
const String& pattern,
785 bool match(
const String& pattern,
786 String& a0, String& a1)
const;
787 bool match(
const String& pattern,
788 String& a0, String& a1, String& a2)
const;
789 bool match(
const String& pattern,
790 String& a0, String& a1, String& a2, String& a3)
const;
791 bool match(
const String& pattern,
792 String& a0, String& a1, String& a2,
793 String& a3, String& a4)
const;
794 bool match(
const String& pattern,
795 String& a0, String& a1, String& a2,
796 String& a3, String& a4, String& a5)
const;
797 bool match(
const String& pattern,
798 String& a0, String& a1, String& a2,
799 String& a3, String& a4, String& a5,
801 bool match(
const String& pattern,
802 String& a0, String& a1, String& a2,
803 String& a3, String& a4, String& a5,
804 String& a6, String& a7)
const;
805 long write_xml(OBStream& o)
const;
806 long write(CommBuffer& buffer)
const;
807 long read_xml(IBStream& i);
808 long read(
const CommBuffer& buffer);
809 String& from_acsii(
const AChar* s);
816 static int compare(
const Char* s1,
const Char* s2,
size_t n);
817 static int compare(
const Char* s1,
const AChar* s2,
size_t n);
818 static int icompare(
const Char* s1,
const Char* s2,
size_t n);
819 static const Char* find(
const Char* s,
int n,
const Char& a);
820 static size_t length(
const Char* s);
821 static size_t length(
const AChar* s);
822 static Char* copy(Char* dest,
const Char* src,
size_t n);
823 static Char* copy(Char* dest,
const AChar* src,
size_t n);
824 static Char* move(Char* dest,
const Char* src,
size_t n);
825 static Char* assign(Char* dest,
size_t n,
const Char& c);
826 static void assign(Char& c1,
const Char& c2)
830 static bool eq(
const Char& c1,
const Char& c2)
834 static bool ne(
const Char& c1,
const Char& c2)
838 static bool lt(
const Char& c1,
const Char& c2)
842 static bool ieq(
const Char& c1,
const Char& c2);
843 static bool ine(
const Char& c1,
const Char& c2)
847 static bool ilt(
const Char& c1,
const Char& c2);
850 String& assign(Char c,
size_t n = 1)
856 String& append(Char c,
size_t n = 1)
862 const Char& get_at(
size_t pos)
const
866 return *(data_->data + pos);
869 void put_at(
size_t pos, Char c);
871 void assign_helper(
const Char* data,
size_t n);
872 void assign_helper(
const AChar* data,
size_t n);
873 void assign_helper(Char c,
size_t n);
875 void replace_helper(
size_t pos,
size_t n1,
const Char* s,
size_t n2);
876 void replace_helper(
size_t pos,
size_t n1, Char c,
size_t n2);
877 void replace_helper(
size_t pos,
size_t n1,
const String& str,
size_t pos2,
size_t n2)
879 str.validate_range(pos2, &n2);
880 replace_helper(pos, n1, str.data_->data + pos2, n2);
883 void append_helper(
const String& str,
size_t pos,
size_t n)
885 str.validate_range(pos, &n);
886 append_helper(str.data_->data + pos, n);
889 void append_helper(
const Char* s,
size_t n);
890 void append_helper(Char c,
size_t n);
892 void append_helper(
const AChar* s,
size_t n);
893 void append_helper(AChar c,
size_t n);
895 int compare_helper(
const String& str,
size_t pos,
size_t n)
const;
896 int compare_helper(
const Char* s,
size_t pos,
size_t n)
const;
897 int compare_helper(
const AChar* s,
size_t pos,
size_t n)
const;
899 int icompare_helper(
const String& str,
size_t pos,
size_t n)
const;
900 int icompare_helper(
const Char* s,
size_t pos,
size_t n)
const;
902 void reserve_helper(
size_t capacity);
903 void resize_helper(
size_t new_count, Char fill_char);
905 Char* allocate(
size_t count);
906 void reallocate(
size_t count);
909 if (n <= data_->capacity)
912 data_->data[ data_->size ] = eos();
917 static Char* nil_data();
926 PAllocator allocator_;
933 return compare(s) < 0;
937 return compare(s) > 0;
946 int strcmp(
const Char* s1,
const Char* s2);
947 int stricmp(
const Char* s1,
const Char* s2);
954 CMREXD
void EncodeToUTF8(
const commore::Char* source,
commore::AString& dest);
String & insert(size_t pos1, const String &str)
Definition: String.h:357
String & append(const AChar *str)
Definition: String.h:239
void resize(size_t n)
Definition: String.h:598
String operator+(const String &str) const
Definition: String.h:940
bool validate_range(size_t pos, size_t *len) const
Definition: String.h:263
String & insert(size_t pos, const Char *str)
Definition: String.h:390
String & append(const Char *str, size_t n)
Definition: String.h:211
bool operator<(const String &s) const
Definition: String.h:931
Char & at(size_t pos)
Definition: String.h:524
const PAllocator & get_allocator() const
Definition: String.h:554
size_t find(const String &str, size_t pos=0) const
Find content in string Searches the string for the first occurrence of the sequence specified by its ...
Definition: String.h:655
String & append(const AChar *str, size_t n)
Definition: String.h:221
String & assign(const AChar *str, size_t n)
Definition: String.h:321
void resize(size_t n, Char c)
Definition: String.h:591
String & append(const String &str)
Definition: String.h:189
const Char * data() const
Definition: String.h:547
String & insert(size_t pos, size_t n, Char c)
Definition: String.h:401
Char & operator[](size_t pos)
Definition: String.h:501
size_t max_size() const
Definition: String.h:576
size_t size
Definition: String.h:23
String & erase(size_t pos=0, size_t n=(size_t) npos)
Definition: String.h:421
void reserve(size_t size)
Definition: String.h:613
String & replace(size_t pos1, size_t n1, const String &str, size_t pos2, size_t n2)
Definition: String.h:447
String & replace(size_t pos, size_t n1, const Char *str, size_t n2)
Definition: String.h:459
size_t size() const
Definition: String.h:569
String & replace(size_t pos, size_t n1, const Char *str)
Definition: String.h:470
String & append(size_t n, Char c)
Definition: String.h:250
String & append(const Char *str)
Definition: String.h:230
String & assign(const Char *str, size_t n)
Definition: String.h:297
String & insert(size_t pos1, const String &str, size_t pos2, size_t n)
Definition: String.h:369
String & insert(size_t pos, const Char *str, size_t n)
Definition: String.h:380
String & assign(const AChar *str)
Definition: String.h:329
Char operator[](size_t pos) const
Definition: String.h:492
String & replace(size_t pos, size_t n1, size_t n2, Char c)
Definition: String.h:482
String & assign(const Char *str)
Definition: String.h:305
size_t copy(Char *str, size_t n, size_t pos=0) const
Copy sequence of characters from string Copies a substring of the current value of the string object ...
Definition: String.h:628
String & assign(size_t n, Char c)
Definition: String.h:313
size_t capacity() const
Definition: String.h:605
Definition: IOBStream.h:166
bool empty() const
Definition: String.h:583
String & clear()
Definition: String.h:410
Char at(size_t pos) const
Definition: String.h:516
String & append(const String &str, size_t pos, size_t n)
Definition: String.h:201
Char data[4]
Definition: String.h:31
String & replace(size_t pos1, size_t n1, const String &str)
Definition: String.h:433
bool operator>(const String &s) const
Definition: String.h:935
const Char * c_str() const
Definition: String.h:533
size_t length() const
Definition: String.h:562
String & assign(const String &str, size_t pos, size_t n)
Definition: String.h:286
size_t capacity
Definition: String.h:27
String & assign(size_t n, AChar c)
Definition: String.h:337