2 Copyright (C) 2005 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.
28 String::String(char *text)
30 int size = strlen(text);
32 this->text = new char[size + 1];
34 strncpy(this->text, text, sizeof this->text);
41 if (this->text != NULL)
49 Got this off Google... not sure I entirely trust it but it seems
59 char *tempText = new char[length + 1];
68 strncpy(tempText, c, sizeof tempText);
70 int len = strlen(tempText);
72 while ((len > 0) && ((tempText[len - 1] == ' ') || (tempText[len - 1] == '\0')))
79 this->text = tempText;
82 void String::operator= (char *text)
84 if (this->text != NULL)
92 printf("WARNING: String - Can't set NULL!\n");
96 int size = strlen(text);
98 this->text = new char[size + 1];
100 strncpy(this->text, text, sizeof this->text);
105 bool String::operator== (char *text)
107 if (strcmp(this->text, text) == 0)
115 bool String::operator== (String string)
117 if (strcmp(this->text, string.getText()) == 0)
125 bool String::operator!= (char *text)
127 if (strcmp(this->text, text) != 0)
135 bool String::operator!= (String string)
137 if (strcmp(this->text, string.getText()) != 0)
145 void String::setText(char *text, ...)
150 va_start(argp, text);
151 vsnprintf(tmpString, sizeof tmpString, text, argp);
154 int size = strlen(tmpString);
156 this->text = new char[size + 1];
158 strncpy(this->text, tmpString, sizeof this->text);
161 char *String::getText()
165 printf("WARNING: String::getText() - text is NULL!\n");
172 int String::getLength()
177 char String::tmpString[1024];