97 char* oldtext = new char[oldlen]; |
97 char* oldtext = new char[oldlen]; |
98 strncpy (oldtext, text, oldlen); |
98 strncpy (oldtext, text, oldlen); |
99 |
99 |
100 delete text; |
100 delete text; |
101 text = new char[len+1]; |
101 text = new char[len+1]; |
|
102 for (unsigned int u = 0; u < len+1; u++) |
|
103 text[u] = 0; |
102 strncpy (text, oldtext, len); |
104 strncpy (text, oldtext, len); |
103 |
105 |
104 alloclen = len; |
106 alloclen = len; |
105 } |
107 } |
106 |
108 |
107 // ============================================================================ |
109 // ============================================================================ |
108 void str::dump () { |
110 void str::dump () { |
109 for (unsigned int u = 0; u <= alloclen; u++) |
111 for (unsigned int u = 0; u <= alloclen; u++) |
110 printf ("\t%u. %d (%c)\n", u, text[u], text[u]); |
112 printf ("\t%u. %u (%c)\n", u, text[u], text[u]); |
111 } |
113 } |
112 |
114 |
113 // ============================================================================ |
115 // ============================================================================ |
114 // Adds a new character at the end of the string. |
116 // Adds a new character at the end of the string. |
115 void str::append (char c) { |
117 void str::append (char c) { |
116 // Out of space, thus resize |
118 // Out of space, thus resize |
117 if (curs == alloclen) |
119 if (curs == alloclen) |
118 resize (alloclen+1); |
120 resize (alloclen+1); |
119 |
|
120 text[curs] = c; |
121 text[curs] = c; |
121 curs++; |
122 curs++; |
122 } |
123 } |
123 |
124 |
124 void str::append (const char* c) { |
125 void str::append (const char* c) { |
346 int str::compare (str c) { |
347 int str::compare (str c) { |
347 return compare (c.chars()); |
348 return compare (c.chars()); |
348 } |
349 } |
349 |
350 |
350 // ============================================================================ |
351 // ============================================================================ |
|
352 str str::tolower () { |
|
353 str n = text; |
|
354 |
|
355 for (uint u = 0; u < len(); u++) { |
|
356 if (n[u] > 'A' && n[u] < 'Z') |
|
357 n.text[u] += ('a' - 'A'); |
|
358 } |
|
359 |
|
360 return n; |
|
361 } |
|
362 |
|
363 // ============================================================================ |
|
364 str str::toupper () { |
|
365 str n = text; |
|
366 |
|
367 for (uint u = 0; u < len(); u++) { |
|
368 if (n[u] > 'a' && n[u] < 'z') |
|
369 n.text[u] -= ('A' - 'a'); |
|
370 } |
|
371 |
|
372 return n; |
|
373 } |
|
374 |
|
375 // ============================================================================ |
351 // OPERATORS |
376 // OPERATORS |
352 str str::operator + (str& c) { |
377 str str::operator + (str& c) { |
353 append (c); |
378 append (c); |
354 return *this; |
379 return *this; |
355 } |
380 } |