[1] | 1 | #ifndef __cmt_string_h__ |
---|
| 2 | #define __cmt_string_h__ |
---|
| 3 | |
---|
| 4 | #include <stdio.h> |
---|
| 5 | #include <string.h> |
---|
| 6 | |
---|
| 7 | class cmt_string |
---|
| 8 | { |
---|
| 9 | public: |
---|
| 10 | typedef enum |
---|
| 11 | { |
---|
| 12 | npos = -1 |
---|
| 13 | } pos_type; |
---|
| 14 | |
---|
| 15 | // |
---|
| 16 | // Constructors |
---|
| 17 | // |
---|
| 18 | cmt_string (); |
---|
| 19 | cmt_string (int n); |
---|
| 20 | cmt_string (char c); |
---|
| 21 | cmt_string (const char* text); |
---|
| 22 | cmt_string (const cmt_string& other); |
---|
| 23 | ~cmt_string (); |
---|
| 24 | |
---|
| 25 | // |
---|
| 26 | // Operators |
---|
| 27 | // |
---|
| 28 | cmt_string& operator = (char c); |
---|
| 29 | cmt_string& operator = (const char* text); |
---|
| 30 | cmt_string& operator = (const cmt_string& other); |
---|
| 31 | |
---|
| 32 | bool read (const cmt_string& file_name); |
---|
| 33 | bool write (const cmt_string& file_name) const; |
---|
| 34 | void write (FILE* f) const; |
---|
| 35 | void write (ostream& output); |
---|
| 36 | |
---|
| 37 | operator const char* () const; |
---|
| 38 | |
---|
| 39 | const char* c_str () const; |
---|
| 40 | /*char* c_str (); */ |
---|
| 41 | |
---|
| 42 | void operator += (char c); |
---|
| 43 | void operator += (const char* text); |
---|
| 44 | void operator += (const cmt_string& other); |
---|
| 45 | |
---|
| 46 | cmt_string operator + (char c) const; |
---|
| 47 | cmt_string operator + (const char* text) const; |
---|
| 48 | cmt_string operator + (const cmt_string& other) const; |
---|
| 49 | |
---|
| 50 | char operator [] (int index) const; |
---|
| 51 | char& operator [] (int index); |
---|
| 52 | |
---|
| 53 | int size () const; |
---|
| 54 | int size (); |
---|
| 55 | void resize (int n); |
---|
| 56 | |
---|
| 57 | int find (char c) const; |
---|
| 58 | int find (const char* text) const; |
---|
| 59 | int find (const cmt_string& other) const; |
---|
| 60 | int find (int pos, char c) const; |
---|
| 61 | int find (int pos, const char* text) const; |
---|
| 62 | int find (int pos, const cmt_string& other) const; |
---|
| 63 | |
---|
| 64 | int find_last_of (char c) const; |
---|
| 65 | int find_last_of (const char* text) const; |
---|
| 66 | int find_last_of (const cmt_string& other) const; |
---|
| 67 | |
---|
| 68 | void erase (int pos); |
---|
| 69 | void erase (int pos, int length); |
---|
| 70 | |
---|
| 71 | void replace (const char* pattern, const char* replacement); |
---|
| 72 | void replace (const cmt_string& pattern, const cmt_string& replacement); |
---|
| 73 | |
---|
| 74 | void replace_all (const char* pattern, const char* replacement); |
---|
| 75 | void replace_all (const cmt_string& pattern, const cmt_string& replacement); |
---|
| 76 | |
---|
| 77 | void trim (); |
---|
| 78 | |
---|
| 79 | cmt_string substr (int pos) const; |
---|
| 80 | cmt_string substr (int pos, int length) const; |
---|
| 81 | |
---|
| 82 | void substr (int pos, cmt_string& dest) const; |
---|
| 83 | void substr (int pos, int length, cmt_string& dest) const; |
---|
| 84 | |
---|
| 85 | bool operator < (const char* text) const; |
---|
| 86 | bool operator < (const cmt_string& other) const; |
---|
| 87 | |
---|
| 88 | bool operator == (const char* text) const; |
---|
| 89 | bool operator == (const cmt_string& other) const; |
---|
| 90 | |
---|
| 91 | bool compare_no_case (const char* text) const; |
---|
| 92 | bool compare_no_case (const cmt_string& other) const; |
---|
| 93 | |
---|
| 94 | bool operator != (const char* text) const; |
---|
| 95 | bool operator != (const cmt_string& other) const; |
---|
| 96 | |
---|
| 97 | bool operator > (const char* text) const; |
---|
| 98 | bool operator > (const cmt_string& other) const; |
---|
| 99 | |
---|
| 100 | private: |
---|
| 101 | void extend (int n); |
---|
| 102 | void allocate (int n); |
---|
| 103 | |
---|
| 104 | char* _data; |
---|
| 105 | int _allocated; |
---|
| 106 | int _size; |
---|
| 107 | }; |
---|
| 108 | |
---|
| 109 | ostream& operator << (ostream& o, const cmt_string& s); |
---|
| 110 | cmt_string operator + (const char* text, const cmt_string& s); |
---|
| 111 | cmt_string operator + (char c, const cmt_string& s); |
---|
| 112 | |
---|
| 113 | #endif |
---|