2
Copyright (C) 2006 Parallel Realities
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include "../headers.h"
30
String::String(const char *text)
32
int size = strlen(text);
34
this->text = new char[size + 1];
36
strncpy(this->text, text, size);
37
this->text[size] = '\0';
39
length = strlen(this->text);
44
if (this->text != NULL)
52
Got this off Google... not sure I entirely trust it but it seems
62
if ((strcmp(text, "") == 0) || (strlen(text) == 0))
67
char *tempText = new char[length + 1];
71
while ((*c <= 32) || (*c >= 127))
84
int len = strlen(tempText);
86
while ((len > 0) && ((tempText[len - 1] <= 32) || (tempText[len - 1] >= 127)))
93
this->text = tempText;
95
length = strlen(this->text);
98
void String::toLowerCase()
100
for (unsigned int i = 0 ; i < strlen(text) ; i++)
102
if ((text[i] >= SDLK_a - 32) && (text[i] <= SDLK_z - 32))
109
void String::toUpperCase()
111
for (unsigned int i = 0 ; i < strlen(text) ; i++)
113
if ((text[i] >= SDLK_a) && (text[i] <= SDLK_z))
120
void String::setText(const char *text, ...)
122
if (this->text != NULL)
128
strcpy(tmpString, "");
131
va_start(argp, text);
132
vsprintf(tmpString, text, argp);
135
int size = strlen(tmpString);
137
this->text = new char[size + 1];
139
strncpy(this->text, tmpString, size);
140
this->text[size] = '\0';
142
length = strlen(this->text);
145
void String::captialise()
147
bool uppercase = true;
152
if ((*c >= SDLK_a) && (*c <= SDLK_z))
160
else if (*c == SDLK_SPACE)
169
void String::operator= (const char *text)
171
if (text == this->text)
176
if (this->text != NULL)
184
printf("WARNING: String - Can't set NULL!\n");
189
int size = strlen(text);
191
this->text = new char[size + 1];
193
strncpy(this->text, text, size);
194
this->text[size] = '\0';
196
length = strlen(this->text);
199
void String::operator= (String string)
201
if (this->text != NULL)
209
bool String::operator== (const char *text)
211
if (strcmp(this->text, text) == 0)
219
bool String::operator== (String string)
221
if (strcmp(this->text, string.getText()) == 0)
229
bool String::operator!= (const char *text)
231
if (strcmp(this->text, text) != 0)
239
bool String::operator!= (String string)
241
if (strcmp(this->text, string.getText()) != 0)
249
char *String::getText()
253
printf("WARNING: String::getText() - text is NULL!\n");
260
int String::getLength()
265
char String::tmpString[1024];