00001
00002
00003
00004
00005
00006
00007 #ifndef __cmt_string_h__
00008 #define __cmt_string_h__
00009
00010 #include
00011 #include
00012
00013 class cmt_string
00014 {
00015 public:
00016 typedef enum
00017 {
00018 npos = -1
00019 } pos_type;
00020
00021
00022
00023
00024 cmt_string ();
00025 cmt_string (int n);
00026 cmt_string (char c);
00027 cmt_string (const char* text);
00028 cmt_string (const cmt_string& other);
00029 ~cmt_string ();
00030
00031
00032
00033
00034 cmt_string& operator = (char c);
00035 cmt_string& operator = (const char* text);
00036 cmt_string& operator = (const cmt_string& other);
00037
00038 bool read (const cmt_string& file_name);
00039 bool write (const cmt_string& file_name) const;
00040 void write (FILE* f) const;
00041 void write (ostream& output);
00042
00043 operator const char* () const;
00044
00045 const char* c_str () const;
00046
00047
00048 void operator += (char c);
00049 void operator += (const char* text);
00050 void operator += (const cmt_string& other);
00051
00052 cmt_string operator + (char c) const;
00053 cmt_string operator + (const char* text) const;
00054 cmt_string operator + (const cmt_string& other) const;
00055
00056 char operator [] (int index) const;
00057 char& operator [] (int index);
00058
00059 int size () const;
00060 int size ();
00061 void resize (int n);
00062
00063 int find (char c) const;
00064 int find (const char* text) const;
00065 int find (const cmt_string& other) const;
00066 int find (int pos, char c) const;
00067 int find (int pos, const char* text) const;
00068 int find (int pos, const cmt_string& other) const;
00069
00070 int find_last_of (char c) const;
00071 int find_last_of (const char* text) const;
00072 int find_last_of (const cmt_string& other) const;
00073
00074 void erase (int pos);
00075 void erase (int pos, int length);
00076
00077 void replace (const char* pattern, const char* replacement);
00078 void replace (const cmt_string& pattern, const cmt_string& replacement);
00079
00080 void replace_all (const char* pattern, const char* replacement);
00081 void replace_all (const cmt_string& pattern, const cmt_string& replacement);
00082
00083 void trim ();
00084
00085 cmt_string substr (int pos) const;
00086 cmt_string substr (int pos, int length) const;
00087
00088 void substr (int pos, cmt_string& dest) const;
00089 void substr (int pos, int length, cmt_string& dest) const;
00090
00091 bool operator < (const char* text) const;
00092 bool operator < (const cmt_string& other) const;
00093
00094 bool operator == (const char* text) const;
00095 bool operator == (const cmt_string& other) const;
00096
00097 bool compare_no_case (const char* text) const;
00098 bool compare_no_case (const cmt_string& other) const;
00099
00100 bool operator != (const char* text) const;
00101 bool operator != (const cmt_string& other) const;
00102
00103 bool operator > (const char* text) const;
00104 bool operator > (const cmt_string& other) const;
00105
00106 private:
00107 void extend (int n);
00108 void allocate (int n);
00109
00110 char* _data;
00111 int _allocated;
00112 int _size;
00113 };
00114
00115 ostream& operator << (ostream& o, const cmt_string& s);
00116 cmt_string operator + (const char* text, const cmt_string& s);
00117 cmt_string operator + (char c, const cmt_string& s);
00118
00119 #endif