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