str.h

changeset 25
c74bb88f537d
parent 18
a6732098fed8
child 29
55406ce7446e
equal deleted inserted replaced
24:d2d4d0154338 25:c74bb88f537d
4 #include <string.h> 4 #include <string.h>
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 // #include <initializer_list> 7 // #include <initializer_list>
8 #include <vector> 8 #include <vector>
9 9 #include <QString>
10 #ifdef QT_VERSION
11 #include <QString>
12 #endif // QT_VERSION
13 10
14 char* vdynformat (const char* csFormat, va_list vArgs, long int lSize); 11 char* vdynformat (const char* csFormat, va_list vArgs, long int lSize);
15 12
16 class vertex; 13 class vertex;
17 14
34 public: 31 public:
35 // ====================================================================== 32 // ======================================================================
36 str (); 33 str ();
37 str (const char* c); 34 str (const char* c);
38 str (char c); 35 str (char c);
36 str (const QString c);
39 ~str (); 37 ~str ();
40 38
41 static str mkfmt (const char* fmt, ...) { 39 static str mkfmt (const char* fmt, ...) {
42 va_list va; 40 va_list va;
43 char* buf; 41 char* buf;
67 65
68 // Dumps the character table of the string 66 // Dumps the character table of the string
69 void dump (); 67 void dump ();
70 68
71 // Appends text to the string 69 // Appends text to the string
72 void append (char c); 70 void append (const char c);
73 void append (const char* c); 71 void append (const char* c);
74 void append (str c); 72 void append (str c);
73 void append (QString c);
75 74
76 // Formats text to the string. 75 // Formats text to the string.
77 void format (const char* fmt, ...); 76 void format (const char* fmt, ...);
78 str format (...); 77 str format (...);
79 78
95 void replace (const char* o, const char* n, unsigned int a = 0); 94 void replace (const char* o, const char* n, unsigned int a = 0);
96 95
97 // Removes a given index from the string, optionally more characters than just 1. 96 // Removes a given index from the string, optionally more characters than just 1.
98 void remove (unsigned int idx, unsigned int dellen=1); 97 void remove (unsigned int idx, unsigned int dellen=1);
99 98
99 // Trims the given amount of characters. If negative, the characters
100 // are removed from the beginning of the string, if positive, from the
101 // end of the string.
100 str trim (int dellen); 102 str trim (int dellen);
101 103
102 // Inserts a substring into a certain position. 104 // Inserts a substring into a certain position.
103 void insert (char* c, unsigned int pos); 105 void insert (char* c, unsigned int pos);
104 106
160 append (c); 162 append (c);
161 return *this; 163 return *this;
162 } 164 }
163 165
164 str& operator+= (const str c) { 166 str& operator+= (const str c) {
167 append (c);
168 return *this;
169 }
170
171 str& operator+= (const QString c) {
165 append (c); 172 append (c);
166 return *this; 173 return *this;
167 } 174 }
168 175
169 str& operator+= (vertex vrt); 176 str& operator+= (vertex vrt);
243 250
244 operator char* () const { 251 operator char* () const {
245 return text; 252 return text;
246 } 253 }
247 254
248 #ifdef QT_VERSION
249 operator QString () const { 255 operator QString () const {
250 return text; 256 return text;
251 } 257 }
252 #endif // QT_VERSION
253 258
254 operator int () const { 259 operator int () const {
255 return atoi (text); 260 return atoi (text);
256 } 261 }
257 262

mercurial