Sat, 14 Jul 2012 01:49:32 +0300
Command definitions are now read into memory.
0 | 1 | /* |
2 | * botc source code | |
3 | * Copyright (C) 2012 Santeri `Dusk` Piippo | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright notice, | |
10 | * this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
12 | * this list of conditions and the following disclaimer in the documentation | |
13 | * and/or other materials provided with the distribution. | |
3 | 14 | * 3. Neither the name of the developer nor the names of its contributors may |
15 | * be used to endorse or promote products derived from this software without | |
16 | * specific prior written permission. | |
0 | 17 | * 4. Redistributions in any form must be accompanied by information on how to |
18 | * obtain complete source code for the software and any accompanying | |
19 | * software that uses the software. The source code must either be included | |
20 | * in the distribution or be available for no more than the cost of | |
21 | * distribution plus a nominal fee, and must be freely redistributable | |
22 | * under reasonable conditions. For an executable file, complete source | |
23 | * code means the source code for all modules it contains. It does not | |
24 | * include source code for modules or files that typically accompany the | |
25 | * major components of the operating system on which the executable file | |
26 | * runs. | |
27 | * | |
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
38 | * POSSIBILITY OF SUCH DAMAGE. | |
39 | */ | |
40 | ||
41 | #include <stdio.h> | |
42 | #include <stdlib.h> | |
43 | #include <string.h> | |
44 | #include <stdarg.h> | |
45 | #include "str.h" | |
46 | #include "common.h" | |
47 | ||
48 | #define ITERATE_STRING(u) for (unsigned int u = 0; u < strlen (text); u++) | |
49 | ||
50 | // ============================================================================ | |
51 | // vdynformat: Try to write to a formatted string with size bytes first, if | |
52 | // that fails, double the size and keep recursing until it works. | |
53 | char* vdynformat (const char* c, va_list v, unsigned int size) { | |
54 | char* buffer = new char[size]; | |
55 | int r = vsnprintf (buffer, size-1, c, v); | |
56 | if (r > (int)size-1 || r < 0) { | |
57 | delete buffer; | |
58 | buffer = vdynformat (c, v, size*2); | |
59 | } | |
60 | return buffer; | |
61 | } | |
62 | ||
63 | // ============================================================================ | |
64 | str::str () { | |
65 | text = new char[1]; | |
66 | clear(); | |
67 | alloclen = strlen (text); | |
68 | } | |
69 | ||
70 | str::str (const char* c) { | |
71 | text = new char[1]; | |
72 | clear (); | |
73 | alloclen = strlen (text); | |
74 | append (c); | |
75 | } | |
76 | ||
77 | str::str (char c) { | |
78 | text = new char[1]; | |
79 | clear (); | |
80 | alloclen = strlen (text); | |
81 | append (c); | |
82 | } | |
83 | ||
84 | // ============================================================================ | |
85 | void str::clear () { | |
86 | delete text; | |
87 | text = new char[1]; | |
88 | text[0] = '\0'; | |
89 | curs = 0; | |
90 | } | |
91 | ||
92 | unsigned int str::len () {return strlen(text);} | |
93 | ||
94 | // ============================================================================ | |
95 | void str::resize (unsigned int len) { | |
96 | unsigned int oldlen = strlen (text); | |
97 | char* oldtext = new char[oldlen]; | |
98 | strncpy (oldtext, text, oldlen); | |
99 | ||
100 | delete text; | |
101 | text = new char[len+1]; | |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
102 | for (unsigned int u = 0; u < len+1; u++) |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
103 | text[u] = 0; |
0 | 104 | strncpy (text, oldtext, len); |
105 | ||
106 | alloclen = len; | |
107 | } | |
108 | ||
109 | // ============================================================================ | |
110 | void str::dump () { | |
111 | for (unsigned int u = 0; u <= alloclen; u++) | |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
112 | printf ("\t%u. %u (%c)\n", u, text[u], text[u]); |
0 | 113 | } |
114 | ||
115 | // ============================================================================ | |
116 | // Adds a new character at the end of the string. | |
117 | void str::append (char c) { | |
118 | // Out of space, thus resize | |
119 | if (curs == alloclen) | |
120 | resize (alloclen+1); | |
121 | text[curs] = c; | |
122 | curs++; | |
123 | } | |
124 | ||
125 | void str::append (const char* c) { | |
126 | resize (alloclen + strlen (c)); | |
127 | ||
128 | for (unsigned int u = 0; u < strlen (c); u++) { | |
129 | if (c[u] != 0) | |
130 | append (c[u]); | |
131 | } | |
132 | } | |
133 | ||
134 | void str::append (str c) { | |
135 | append (c.chars()); | |
136 | } | |
137 | ||
138 | // ============================================================================ | |
139 | void str::appendformat (const char* c, ...) { | |
140 | va_list v; | |
141 | ||
142 | va_start (v, c); | |
143 | char* buf = vdynformat (c, v, 256); | |
144 | va_end (v); | |
145 | ||
146 | append (buf); | |
147 | } | |
148 | ||
149 | void str::appendformat (str c, ...) { | |
150 | va_list v; | |
151 | ||
152 | va_start (v, c); | |
153 | char* buf = vdynformat (c.chars(), v, 256); | |
154 | va_end (v); | |
155 | ||
156 | append (buf); | |
157 | } | |
158 | ||
159 | // ============================================================================ | |
160 | char* str::chars () { | |
161 | return text; | |
162 | } | |
163 | ||
164 | // ============================================================================ | |
165 | unsigned int str::first (const char* c, unsigned int a) { | |
166 | unsigned int r = 0; | |
167 | unsigned int index = 0; | |
168 | for (; a < alloclen; a++) { | |
169 | if (text[a] == c[r]) { | |
170 | if (r == 0) | |
171 | index = a; | |
172 | ||
173 | r++; | |
174 | if (r == strlen (c)) | |
175 | return index; | |
176 | } else { | |
177 | if (r != 0) { | |
178 | // If the string sequence broke at this point, we need to | |
179 | // check this character again, for a new sequence just | |
180 | // might start right here. | |
181 | a--; | |
182 | } | |
183 | ||
184 | r = 0; | |
185 | } | |
186 | } | |
187 | ||
188 | return len (); | |
189 | } | |
190 | ||
191 | // ============================================================================ | |
192 | unsigned int str::last (const char* c, int a) { | |
193 | if (a == -1) | |
194 | a = len(); | |
195 | ||
196 | int max = strlen (c)-1; | |
197 | ||
198 | int r = max; | |
199 | for (; a >= 0; a--) { | |
200 | if (text[a] == c[r]) { | |
201 | r--; | |
202 | if (r == -1) | |
203 | return a; | |
204 | } else { | |
205 | if (r != max) | |
206 | a++; | |
207 | ||
208 | r = max; | |
209 | } | |
210 | } | |
211 | ||
212 | return len (); | |
213 | } | |
214 | ||
215 | // ============================================================================ | |
216 | str str::substr (unsigned int a, unsigned int b) { | |
217 | if (a > len()) a = len(); | |
218 | if (b > len()) b = len(); | |
219 | ||
220 | if (b == a) | |
221 | return ""; | |
222 | ||
223 | if (b < a) { | |
224 | printf ("str::substr: indices %u and %u given, should be the other way around, swapping..\n", a, b); | |
225 | ||
226 | // Swap the variables | |
227 | unsigned int c = a; | |
228 | a = b; | |
229 | b = c; | |
230 | } | |
231 | ||
232 | char* s = new char[b-a]; | |
233 | strncpy (s, text+a, b-a); | |
234 | return str(s); | |
235 | } | |
236 | ||
237 | // ============================================================================ | |
238 | void str::remove (unsigned int idx, unsigned int dellen) { | |
239 | str s1 = substr (0, idx); | |
240 | str s2 = substr (idx + dellen, len()); | |
241 | ||
242 | clear(); | |
243 | ||
244 | append (s1); | |
245 | append (s2); | |
246 | } | |
247 | ||
248 | // ============================================================================ | |
249 | void str::trim (int dellen) { | |
250 | if (!dellen) | |
251 | return; | |
252 | ||
253 | str s; | |
254 | // If dellen is positive, trim from the end, | |
255 | // if negative, trim from beginning. | |
256 | if (dellen > 0) | |
257 | s = substr (0, len()-dellen); | |
258 | else | |
259 | s = substr (-dellen, len()); | |
260 | ||
261 | clear(); | |
262 | append (s); | |
263 | } | |
264 | ||
265 | // ============================================================================ | |
266 | void str::replace (const char* o, const char* n, unsigned int a) { | |
267 | unsigned int idx; | |
268 | ||
269 | while ((idx = first (o, a)) != len()) { | |
270 | str s1 = substr (0, idx); | |
271 | str s2 = substr (idx + strlen (o), len()); | |
272 | ||
273 | clear(); | |
274 | ||
275 | append (s1); | |
276 | append (n); | |
277 | append (s2); | |
278 | } | |
279 | } | |
280 | ||
281 | void str::insert (char* c, unsigned int pos) { | |
282 | str s1 = substr (0, pos); | |
283 | str s2 = substr (pos, len()); | |
284 | ||
285 | clear(); | |
286 | append (s1); | |
287 | append (c); | |
288 | append (s2); | |
289 | } | |
290 | ||
291 | void str::reverse () { | |
292 | char* tmp = new char[alloclen]; | |
293 | strcpy (tmp, text); | |
294 | ||
295 | clear(); | |
296 | curs = 0; | |
297 | resize (alloclen); | |
298 | for (int i = alloclen-1; i >= 0; i--) | |
299 | append (tmp[i]); | |
300 | } | |
301 | ||
302 | void str::repeat (unsigned int n) { | |
303 | char* tmp = new char[alloclen]; | |
304 | strcpy (tmp, text); | |
305 | ||
306 | for (; n > 0; n--) | |
307 | append (tmp); | |
308 | } | |
309 | ||
310 | // ============================================================================ | |
311 | bool str::isnumber () { | |
312 | return contentcheck (SCCF_NUMBER); | |
313 | } | |
314 | ||
315 | // ============================================================================ | |
316 | bool str::isword () { | |
317 | return contentcheck (SCCF_WORD); | |
318 | } | |
319 | ||
320 | bool str::contentcheck (int flags) { | |
321 | ITERATE_STRING (u) { | |
322 | if (flags & SCCF_WORD) { | |
323 | // lowercase letters | |
324 | if (text[u] >= 'a' || text[u] <= 'z') | |
325 | continue; | |
326 | ||
327 | // uppercase letters | |
328 | if (text[u] >= 'A' || text[u] <= 'Z') | |
329 | continue; | |
330 | } | |
331 | ||
332 | if (flags & SCCF_NUMBER) { | |
333 | if (text[u] < '0' || text[u] > '9') | |
334 | return false; | |
335 | } | |
336 | ||
337 | return false; | |
338 | } | |
339 | return true; | |
340 | } | |
341 | ||
342 | // ============================================================================ | |
343 | int str::compare (const char* c) { | |
344 | return strcmp (text, c); | |
345 | } | |
346 | ||
347 | int str::compare (str c) { | |
348 | return compare (c.chars()); | |
349 | } | |
350 | ||
351 | // ============================================================================ | |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
352 | str str::tolower () { |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
353 | str n = text; |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
354 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
355 | for (uint u = 0; u < len(); u++) { |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
356 | if (n[u] > 'A' && n[u] < 'Z') |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
357 | n.text[u] += ('a' - 'A'); |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
358 | } |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
359 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
360 | return n; |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
361 | } |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
362 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
363 | // ============================================================================ |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
364 | str str::toupper () { |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
365 | str n = text; |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
366 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
367 | for (uint u = 0; u < len(); u++) { |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
368 | if (n[u] > 'a' && n[u] < 'z') |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
369 | n.text[u] -= ('A' - 'a'); |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
370 | } |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
371 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
372 | return n; |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
373 | } |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
374 | |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
375 | // ============================================================================ |
6
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
376 | unsigned int str::count (char* c) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
377 | unsigned int r = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
378 | unsigned int tmp = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
379 | ITERATE_STRING (u) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
380 | if (text[u] == c[r]) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
381 | r++; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
382 | if (r == strlen (c)) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
383 | r = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
384 | tmp++; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
385 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
386 | } else { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
387 | if (r != 0) |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
388 | u--; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
389 | r = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
390 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
391 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
392 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
393 | return tmp; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
394 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
395 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
396 | // ============================================================================ |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
397 | #if 0 |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
398 | str** str::split (char* del) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
399 | unsigned int arrcount = count (del) + 1; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
400 | str** arr = new str* [arrcount]; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
401 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
402 | unsigned int a = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
403 | unsigned int index = 0; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
404 | while (1) { |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
405 | unsigned int b = first (del, a+1); |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
406 | printf ("next: %u (<-> %u)\n", b, len()); |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
407 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
408 | if (b == len()) |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
409 | break; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
410 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
411 | str* x = new str; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
412 | x->append (substr (a, b)); |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
413 | arr[index] = x; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
414 | index++; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
415 | a = b; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
416 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
417 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
418 | return arr; |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
419 | } |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
420 | #endif |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
421 | |
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
422 | // ============================================================================ |
0 | 423 | // OPERATORS |
424 | str str::operator + (str& c) { | |
425 | append (c); | |
426 | return *this; | |
427 | } | |
428 | ||
429 | str& str::operator += (char c) { | |
430 | append (c); | |
431 | return *this; | |
432 | } | |
433 | ||
434 | str& str::operator += (const char* c) { | |
435 | append (c); | |
436 | return *this; | |
437 | } | |
438 | ||
439 | str& str::operator += (const str c) { | |
440 | append (c); | |
441 | return *this; | |
442 | } | |
443 | ||
444 | char str::operator [] (unsigned int pos) { | |
445 | return text[pos]; | |
446 | } | |
447 | ||
448 | str::operator char* () const { | |
449 | return text; | |
450 | } | |
451 | ||
452 | str::operator int () const {return atoi(text);} | |
453 | str::operator unsigned int () const {return atoi(text);} |