Subversion Repositories spk

Rev

Rev 48 | Rev 56 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 48 Rev 50
Line 1... Line 1...
1
#include "String.h"
1
ÿþ#include "String.h"
2
 
2

3
#include <sstream>
3
#include <sstream>
4
#include <stdarg.h>
4
#include <stdarg.h>
5
#include <algorithm>
5
#include <algorithm>
6
 
6
#include <iomanip>
7
namespace Utils {
7
8
 
8
namespace Utils {
9
String operator+(const char *str1, const String &str2)
9
10
{
10
String operator+(const char *str1, const String &str2)
11
	return String(str1) + str2;
11
{
12
}
12
	return String(str1) + str2;
13
 
13
}
14
 
14

15
String::String(void)						{ this->assign(""); }
15
16
String::String(const char *str)				{ this-&gt;assign(str); }
16
String::String(void)						{ this-&gt;assign(""); }
17
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
17
String::String(const char *str)				{ this->assign(str); }
18
String::String(const std::string &str)		{ this->assign(str);}
18
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
19
String::String(const unsigned char c)		{ this->assign(1, c); }
19
String::String(const std::string &str)		{ this->assign(str);}
20
String::String(const char c)				{ this->assign(1, c); }
20
String::String(const unsigned char c)		{ this->assign(1, c); }
21
String::String(const String &str)			{ this->assign(str); }
21
String::String(const char c)				{ this->assign(1, c); }
22
String::String(long l)						{ this->fromLong(l); }
22
String::String(const String &str)			{ this->assign(str); }
23
String::String(unsigned long l)				{ this->fromLong((long)l); }
23
String::String(long l)						{ this->fromLong(l); }
24
String::String(float f)						{ this->fromFloat(f); }
24
String::String(unsigned long l)				{ this->fromLong((long)l); }
25
String::String(double f)					{ this->fromDouble(f); }
25
String::String(float f)						{ this->fromFloat(f); }
26
 
26
String::String(double f)					{ this->fromDouble(f); }
27
String::~String(void)
27
28
{
28
String::~String(void)
29
}
29
{
30
 
30
}
31
/////////////////////////////////////////////////////////////////
31
32
// Conversion functions
32
String String::PadNumber(long iNumber, int iAmount)
33
 
33
{
34
void String::fromLong(long l)
34
	String str(iNumber);
35
{
35
	return str.padNumber(iAmount);
36
	std::stringstream strstream;
36
}
37
	strstream << l;
37
38
	*this = strstream.str();
38
const String &String::padNumber(int iAmount)
39
}
39
{
40
 
40
	return this->pad(iAmount, '0');
41
void String::fromFloat(float f, int dp)
41
}
42
{
42
43
	std::stringstream strstream;
43
const String &String::pad(int iAmount, char cWith)
44
	strstream.precision(dp);
44
{
45
	strstream << std::fixed << f;
45
	std::stringstream strm;
46
	*this = strstream.str();
46
	strm << std::setw(iAmount) << std::setfill(cWith) << *this;
47
}
47
	*this = strm.str();
48
 
48
	return (*this);
49
void String::fromFloat(float f)
49
}
50
{
50
51
	std::stringstream strstream;
51
/////////////////////////////////////////////////////////////////
52
	strstream << f;
52
// Conversion functions
53
	*this = strstream.str();
53
54
}
54
void String::fromLong(long l)
55
void String::fromDouble(double f)
55
{
56
{
56
	std::stringstream strstream;
57
	std::stringstream strstream;
57
	strstream <;< l;
58
	strstream << f;
58
	*this = strstream.str();
59
	*this = strstream.str();
59
}
60
}
60
61
 
61
void String::fromFloat(float f, int dp)
62
const String &String::format(const char *sFormat, ...)
62
{
63
{
63
	std::stringstream strstream;
64
	char buffer[1024];
64
	strstream.precision(dp);
65
	va_list args;
65
	strstream <;< std::fixed << f;
66
	va_start (args, sFormat);
66
	*this = strstream.str();
67
	vsprintf (buffer, sFormat, args);
67
}
68
	va_end (args);
68
69
 
69
void String::fromFloat(float f)
70
	this->assign(buffer);
70
{
71
	return (*this);
71
	std::stringstream strstream;
72
}
72
	strstream << f;
73
 
73
	*this = strstream.str();
74
String String::fromFormat(const char *sFormat, ...)
74
}
75
{
75
void String::fromDouble(double f)
76
	char buffer[1024];
76
{
77
	va_list args;
77
	std::stringstream strstream;
78
	va_start (args, sFormat);
78
	strstream << f;
79
	vsprintf (buffer, sFormat, args);
79
	*this = strstream.str();
80
	va_end (args);
80
}
81
 
81

82
	return String(buffer);
82
const String &String::format(const char *sFormat, ...)
83
}
83
{
84
 
84
	char buffer[1024];
85
long String::toLong() const
85
	va_list args;
86
{
86
	va_start (args, sFormat);
87
	return atoi(this->c_str());
87
	vsprintf (buffer, sFormat, args);
88
}
88
	va_end (args);
89
double String::toDouble() const
89
90
{
90
	this->assign(buffer);
91
	return atof(this->c_str());
91
	return (*this);
92
}
92
}
93
float String::toFloat() const
93
94
{
94
String String::Format(const char *sFormat, ...)
95
	return (float)atof(this->c_str());
95
{
96
}
96
	char buffer[1024];
97
 
97
	va_list args;
98
 
98
	va_start (args, sFormat);
99
const String &String::operator= ( const char *str )				{ this->assign(str); return (*this); }
99
	vsprintf (buffer, sFormat, args);
100
const String &String::operator= ( const unsigned char *str )	{ this->assign((const char *)str); return (*this); }
100
	va_end (args);
101
const String &String::operator= ( const String &str )			{ this->assign((std::string &)str); return (*this); }
101
102
const String &String::operator= ( const std::string &str )		{ this->assign(str); return (*this); }
102
	return String(buffer);
103
const String &String::operator= ( unsigned char c )				{ this->assign(1, c); return (*this); }
103
}
104
const String &String::operator= ( char c )						{ this->assign(1, c); return (*this); }
104
105
const String &String::operator= ( long l )						{ this->fromLong(l); return (*this); }
105
long String::toLong() const
106
const String &String::operator= ( unsigned long l )				{ this->fromLong(l); return (*this); }
106
{
107
const String &String::operator= ( float f )						{ this->;fromFloat(f); return (*this); }
107
	return atoi(this->;c_str());
108
const String &String::operator= ( double f )					{ this->fromDouble(f); return (*this); }
108
}
109
 
109
double String::toDouble() const
110
const unsigned char String::operator[] ( int num ) const			{ return this->at(num); }
110
{
111
unsigned char &String::operator[] ( int num )						{ return (unsigned char &)this->;at(num); }
111
	return atof(this->;c_str());
112
 
112
}
113
const String &String::operator+= ( const char *str )			{ this->append(str); return (*this); }
113
float String::toFloat() const
114
const String &String::operator+= ( const unsigned char *str ) 	{ this->append((const char *)str); return (*this); }
114
{
115
const String &String::operator+= ( const std::string &str )		{ this->;append(str); return (*this); }
115
	return (float)atof(this->;c_str());
116
const String &String::operator+= ( const String &str )		{ this->append(str); return (*this); }
116
}
117
const String &String::operator+= ( const char c )				{ this->append(1, c); return (*this); }
117
118
const String &String::operator+= ( const unsigned char c )		{ this->append(1, c); return (*this); }
118
119
const String &String::operator+= ( const unsigned long l )		
119
const String &String::operator= ( const char *str )				{ this->assign(str); return (*this); }
120
{ 
120
const String &String::operator= ( const unsigned char *str )	{ this->assign((const char *)str); return (*this); }
121
	std::stringstream strm;
121
const String &String::operator= ( const String &str )			{ this->assign((std::string &)str); return (*this); }
122
	strm &lt;<; (*this) <<; l;
122
const String &String::operator= ( const std::string &str )		{ this-&gt;assign(str); return (*this); }
123
	strm >> (*this);
123
const String &String::operator= ( unsigned char c )				{ this->assign(1, c); return (*this); }
124
	return (*this); 
124
const String &String::operator= ( char c )						{ this->assign(1, c); return (*this); }
125
}
125
const String &String::operator= ( long l )						{ this->fromLong(l); return (*this); }
126
const String &String::operator+= ( const long l )		
126
const String &String::operator= ( unsigned long l )				{ this->fromLong(l); return (*this); }
127
{ 
127
const String &String::operator= ( float f )						{ this->fromFloat(f); return (*this); }
128
	std::stringstream strm;
128
const String &String::operator= ( double f )					{ this->fromDouble(f); return (*this); }
129
	strm << (*this) << l;
129
130
	*this = strm.str();
130
const unsigned char String::operator[] ( int num ) const			{ return this->at(num); }
131
	return (*this); 
131
unsigned char &String::operator[] ( int num )						{ return (unsigned char &)this->at(num); }
132
}
132
133
const String &String::operator+= ( const float f )		
133
const String &String::operator+= ( const char *str )			{ this->append(str); return (*this); }
134
{ 
134
const String &String::operator+= ( const unsigned char *str ) 	{ this->append((const char *)str); return (*this); }
135
	std::stringstream strm;
135
const String &String::operator+= ( const std::string &str )		{ this->append(str); return (*this); }
136
	strm &lt;<; (*this) <<; f;
136
const String &String::operator+= ( const String &str )		{ this-&gt;append(str); return (*this); }
137
	*this = strm.str();
137
const String &String::operator+= ( const char c )				{ this->append(1, c); return (*this); }
138
	return (*this); 
138
const String &String::operator+= ( const unsigned char c )		{ this->append(1, c); return (*this); }
139
}
139
const String &String::operator+= ( const unsigned long l )		
140
const String &String::operator+= ( const double f )		
140
{ 
141
{ 
141
	std::stringstream strm;
142
	std::stringstream strm;
142
	strm <;< (*this) << l;
143
	strm &lt;&lt; (*this) << f;
143
	strm &gt;&gt; (*this);
144
	*this = strm.str();
144
	return (*this); 
145
	return (*this); 
145
}
146
}
146
const String &String::operator+= ( const long l )		
147
 
147
{ 
148
 
148
	std::stringstream strm;
149
String String::operator+ ( const char *str ) const			{ return String(*this) += str; }
149
	strm << (*this) <;< l;
150
String String::operator+ ( const unsigned char *str ) const	{ return String(*this) += str; }
150
	*this = strm.str();
151
String String::operator+ ( const std::string &str ) const	{ return String(*this) += str; }
151
	return (*this); 
152
String String::operator+ ( const String &str ) const		{ return String(*this) += str; }
152
}
153
String String::operator+ ( const char c ) const				{ return String(*this) += c; }
153
const String &String::operator+= ( const float f )		
154
String String::operator+ ( const unsigned char c ) const	{ return String(*this) += c; }
154
{ 
155
String String::operator+ ( const long l ) const				{ return String(*this) += l; }
155
	std::stringstream strm;
156
String String::operator+ ( const unsigned long l ) const	{ return String(*this) += l; }
156
	strm << (*this) <;< f;
157
String String::operator+ ( const float f ) const			{ return String(*this) += f; }
157
	*this = strm.str();
158
String String::operator+ ( const double f ) const			{ return String(*this) += f; }
158
	return (*this); 
159
 
159
}
160
bool String::operator== ( const char *str ) const				{ return (this->compare(str)) ? false : true; }
160
const String &String::operator+= ( const double f )		
161
bool String::operator== ( const unsigned char *str ) const	{ return (this->compare((const char *)str)) ? false : true; }
161
{ 
162
bool String::operator== ( const std::string &str ) const		{ return (this->compare(str)) ? false : true; }
162
	std::stringstream strm;
163
bool String::operator== ( const String &str ) const			{ return (this-&gt;compare(str)) ? false : true; }
163
	strm &lt;<; (*this) <;< f;
164
 
164
	*this = strm.str();
165
bool String::operator!= ( const char *str ) const				{ return (this->compare(str)) ? true : false; }
165
	return (*this); 
166
bool String::operator!= ( const unsigned char *str ) const	{ return (this->compare((const char *)str)) ? true : false; }
166
}
167
bool String::operator!= ( const std::string &str ) const		{ return (this->compare(str)) ? true : false; }
167
168
bool String::operator!= ( const String &str ) const			{ return (this->compare(str)) ? true : false; }
168
169
 
169
String String::operator+ ( const char *str ) const			{ return String(*this) += str; }
170
bool String::Compare(const String &str, bool bCaseSensative) const
170
String String::operator+ ( const unsigned char *str ) const	{ return String(*this) += str; }
171
{
171
String String::operator+ ( const std::string &str ) const	{ return String(*this) += str; }
172
	if ( bCaseSensative ) {
172
String String::operator+ ( const String &str ) const		{ return String(*this) += str; }
173
		return (this->compare(str) == 0) ? true : false;
173
String String::operator+ ( const char c ) const				{ return String(*this) += c; }
174
	}
174
String String::operator+ ( const unsigned char c ) const	{ return String(*this) += c; }
175
 
175
String String::operator+ ( const long l ) const				{ return String(*this) += l; }
176
	if ( str.length() != this->;length() ) return false;
176
String String::operator+ ( const unsigned long l ) const	{ return String(*this) += l; }
177
	for ( unsigned int i = 0; i < str.length(); i++ ) {
177
String String::operator+ ( const float f ) const			{ return String(*this) += f; }
178
		if ( tolower(this->at(i)) != tolower(str[i]) ) {
178
String String::operator+ ( const double f ) const			{ return String(*this) += f; }
179
			return false;
179
180
		}
180
bool String::operator== ( const char *str ) const				{ return (this->compare(str)) ? false : true; }
181
	}
181
bool String::operator== ( const unsigned char *str ) const	{ return (this->compare((const char *)str)) ? false : true; }
182
	return true;
182
bool String::operator== ( const std::string &str ) const		{ return (this->compare(str)) ? false : true; }
183
}
183
bool String::operator== ( const String &str ) const			{ return (this->compare(str)) ? false : true; }
184
 
184

185
bool String::Compare(const unsigned char *str, bool bCaseSensative) const
185
bool String::operator!= ( const char *str ) const				{ return (this->compare(str)) ? true : false; }
186
{
186
bool String::operator!= ( const unsigned char *str ) const	{ return (this->compare((const char *)str)) ? true : false; }
187
	return this->;Compare((const char *)str, bCaseSensative);
187
bool String::operator!= ( const std::string &str ) const		{ return (this->;compare(str)) ? true : false; }
188
}
188
bool String::operator!= ( const String &str ) const			{ return (this->compare(str)) ? true : false; }
189
 
189

190
bool String::Compare(const char *str, bool bCaseSensative) const
190
bool String::Compare(const String &str, bool bCaseSensative) const
191
{
191
{
192
	if ( bCaseSensative ) {
192
	if ( bCaseSensative ) {
193
		return (this->compare(str) == 0) ? true : false;
193
		return (this->compare(str) == 0) ? true : false;
194
	}
194
	}
195
 
195

196
	if ( strlen(str) != this->length() ) return false;
196
	if ( str.length() != this->length() ) return false;
197
	for ( unsigned int i = 0; i < this->length(); i++ ) {
197
	for ( unsigned int i = 0; i < str.length(); i++ ) {
198
		if ( tolower(this->at(i)) != tolower(*(str + i)) ) {
198
		if ( tolower(this->at(i)) != tolower(str[i]) ) {
199
			return false;
199
			return false;
200
		}
200
		}
201
	}
201
	}
202
 
202
	return true;
203
	return true;
203
}
204
}
204
205
 
205
bool String::Compare(const unsigned char *str, bool bCaseSensative) const
206
String String::token(const char *token, int tok) const
206
{
207
{
207
	return this->Compare((const char *)str, bCaseSensative);
208
	return this->tokens(token, tok, tok);
208
}
209
}
209
210
 
210
bool String::Compare(const char *str, bool bCaseSensative) const
211
String String::tokens(const char *token, int from, int to) const
211
{
212
{
212
	if ( bCaseSensative ) {
213
	if ( this->empty() ) return "";
213
		return (this->compare(str) == 0) ? true : false;
214
 
214
	}
215
	int max = this->countToken(token);
215
216
 
216
	if ( strlen(str) != this->length() ) return false;
217
	std::string newstr;
217
	for ( unsigned int i = 0; i < this->length(); i++ ) {
218
 
218
		if ( tolower(this->at(i)) != tolower(*(str + i)) ) {
219
	int whichtok = 1;
219
			return false;
220
	std::string::size_type lastPos = 0;
220
		}
221
	std::string::size_type pos     = _token_nextPos(token, 0);
221
	}
222
 
222

223
	if ( from <; 0 )
223
	return true;
224
		from = max + (from + 1);
224
}
225
	if ( to < 0 )
225
226
		to = max + (to + 1);
226
String String::token(const char *token, int tok) const
227
 
227
{
228
	while (std::string::npos != pos || std::string::npos != lastPos)
228
	return this->tokens(token, tok, tok);
229
	{
229
}
230
		if ( to == 0 )
230
231
		{
231
String String::tokens(const char *token, int from, int to) const
232
			if ( whichtok >= from )
232
{
233
			{
233
	if ( this->empty() ) return "";
234
				if ( newstr != "" ) newstr = newstr + token;
234
235
				newstr = newstr + this->substr(lastPos, pos - lastPos);
235
	int max = this->countToken(token);
236
			}
236
237
		}
237
	std::string newstr;
238
		else
238
239
		{
239
	int whichtok = 1;
240
			if ( (whichtok >= from) && (whichtok <= to) )
240
	std::string::size_type lastPos = 0;
241
			{
241
	std::string::size_type pos     = _token_nextPos(token, 0);
242
				if ( newstr != "" ) newstr = newstr + token;
242
243
				newstr = newstr + this->substr(lastPos, pos - lastPos);
243
	if ( from < 0 )
244
			}
244
		from = max + (from + 1);
245
			if ( whichtok &gt; to )
245
	if ( to &lt; 0 )
246
				break;
246
		to = max + (to + 1);
247
		}
247
248
		// Found a token, add it to the vector.
248
	while (std::string::npos != pos || std::string::npos != lastPos)
249
		whichtok++;
249
	{
250
 
250
		if ( to == 0 )
251
		if ( pos >= this->length() )
251
		{
252
			break;
252
			if ( whichtok >;= from )
253
 
253
			{
254
		// skip past token
254
				if ( newstr != "" ) newstr = newstr + token;
255
		size_t i = 0;
255
				newstr = newstr + this->substr(lastPos, pos - lastPos);
256
		size_t max = strlen(token);
256
			}
257
		lastPos = pos;
257
		}
258
		while ( (i < max) && (token[i] == this->at(lastPos)) )
258
		else
259
		{
259
		{
260
			++i;
260
			if ( (whichtok >;= from) && (whichtok <= to) )
261
			++lastPos;
261
			{
262
		}
262
				if ( newstr != "" ) newstr = newstr + token;
263
 
263
				newstr = newstr + this->substr(lastPos, pos - lastPos);
264
		// get the next token
264
			}
265
		pos = _token_nextPos(token, lastPos);
265
			if ( whichtok > to )
266
	}
266
				break;
267
	return newstr;
267
		}
268
}
268
		// Found a token, add it to the vector.
269
 
269
		whichtok++;
270
String String::remToken(const char *token, int from) const
270
271
{
271
		if ( pos >= this->length() )
272
	std::string newstr;
272
			break;
273
 
273

274
	int whichtok = 1;
274
		// skip past token
275
	std::string::size_type lastPos = 0;
275
		size_t i = 0;
276
	std::string::size_type pos     = _token_nextPos(token, 0);
276
		size_t max = strlen(token);
277
 
277
		lastPos = pos;
278
	while (std::string::npos != pos || std::string::npos != lastPos)
278
		while ( (i < max) && (token[i] == this->at(lastPos)) )
279
	{
279
		{
280
		if ( whichtok != from )
280
			++i;
281
		{
281
			++lastPos;
282
			if ( newstr != "" ) newstr = newstr + token;
282
		}
283
			newstr = newstr + this->substr(lastPos, pos - lastPos);
283
284
		}
284
		// get the next token
285
 
285
		pos = _token_nextPos(token, lastPos);
286
		// Found a token, add it to the vector.
286
	}
287
		whichtok++;
287
	return newstr;
288
 
288
}
289
		if ( pos >= this->length() )
289
290
			break;
290
String String::remToken(const char *token, int from) const
291
 
291
{
292
		// skip past token
292
	std::string newstr;
293
		size_t i = 0;
293
294
		size_t max = strlen(token);
294
	int whichtok = 1;
295
		lastPos = pos;
295
	std::string::size_type lastPos = 0;
296
		while ( (i < max) && (token[i] == this->at(lastPos)) )
296
	std::string::size_type pos     = _token_nextPos(token, 0);
297
		{
297
298
			++i;
298
	while (std::string::npos != pos || std::string::npos != lastPos)
299
			++lastPos;
299
	{
300
		}
300
		if ( whichtok != from )
301
 
301
		{
302
		// get the next token
302
			if ( newstr != "" ) newstr = newstr + token;
303
		pos = _token_nextPos(token, lastPos);
303
			newstr = newstr + this->substr(lastPos, pos - lastPos);
304
	}
304
		}
305
	return newstr;
305
306
}
306
		// Found a token, add it to the vector.
307
 
307
		whichtok++;
308
String String::word(int word) const
308
309
{
309
		if ( pos >= this->length() )
310
	return this->token(" ", word);
310
			break;
311
}
311
312
String String::words(int from, int to) const
312
		// skip past token
313
{
313
		size_t i = 0;
314
	return this->tokens(" ", from, to);
314
		size_t max = strlen(token);
315
}
315
		lastPos = pos;
316
int String::countToken(const char *token) const
316
		while ( (i < max) && (token[i] == this->at(lastPos)) )
317
{
317
		{
318
	if ( this->;empty() )
318
			++i;
319
		return 0;
319
			++lastPos;
320
 
320
		}
321
	// finds the number of tokens in a string
321
322
	int found = 1;
322
		// get the next token
323
 
323
		pos = _token_nextPos(token, lastPos);
324
	std::string tmpstr = *this;
324
	}
325
 
325
	return newstr;
326
	// ignore the initial spaces
326
}
327
	std::string::size_type pos = this->find_first_not_of(token, 0);
327
328
 
328
String String::word(int word) const
329
	// remove end spaces
329
{
330
	size_t i = tmpstr.size() - 1;
330
	return this->token(" ", word);
331
	while ( tmpstr[i] == ' ' && i > 0 )
331
}
332
		i--;
332
String String::words(int from, int to) const
333
	if ( i <= 0 ) return 0;
333
{
334
	tmpstr.erase ( i + 1, tmpstr.size() - i );
334
	return this->tokens(" ", from, to);
335
 
335
}
336
	// count tokens
336
int String::countToken(const char *token) const
337
	pos = tmpstr.find (token,pos + 1);
337
{
338
	while ( pos &lt; std::string::npos )
338
	if ( this-&gt;empty() )
339
	{
339
		return 0;
340
		while (tmpstr[pos] == ' ')
340
341
			pos++;
341
	// finds the number of tokens in a string
342
		found++;
342
	int found = 1;
343
		pos = tmpstr.find (token,pos + 1);
343
344
	}
344
	std::string tmpstr = *this;
345
 
345

346
	// return number of tokens
346
	// ignore the initial spaces
347
	return found;
347
	std::string::size_type pos = this->find_first_not_of(token, 0);
348
}
348
349
 
349
	// remove end spaces
350
std::string::size_type String::_token_nextPos(const char *token, std::string::size_type curPos) const
350
	size_t i = tmpstr.size() - 1;
351
{
351
	while ( tmpstr[i] == ' ' && i > 0 )
352
	bool found = false;
352
		i--;
353
	std::string::size_type startPos = 0;
353
	if ( i <;= 0 ) return 0;
354
	size_t max = strlen(token);
354
	tmpstr.erase ( i + 1, tmpstr.size() - i );
355
	while ( !found ) {
355
356
		found = true;
356
	// count tokens
357
		startPos = this->find_first_of(token[0], curPos);
357
	pos = tmpstr.find (token,pos + 1);
358
		if ( startPos == std::string::npos ) {
358
	while ( pos < std::string::npos )
359
			startPos = this->length();
359
	{
360
			break;
360
		while (tmpstr[pos] == ' &apos;)
361
		}
361
			pos++;
362
 
362
		found++;
363
		std::string::size_type pos = startPos;
363
		pos = tmpstr.find (token,pos + 1);
364
		size_t i = 1;
364
	}
365
		while ( i < max )
365
366
		{
366
	// return number of tokens
367
			++pos;
367
	return found;
368
			if ( this->at(pos) != token[i] )
368
}
369
			{
369
370
				found = false;
370
std::string::size_type String::_token_nextPos(const char *token, std::string::size_type curPos) const
371
				break;
371
{
372
			}
372
	bool found = false;
373
			++i;
373
	std::string::size_type startPos = 0;
374
		}
374
	size_t max = strlen(token);
375
		curPos = pos;
375
	while ( !found ) {
376
	}
376
		found = true;
377
	return startPos;
377
		startPos = this->find_first_of(token[0], curPos);
378
}
378
		if ( startPos == std::string::npos ) {
379
 
379
			startPos = this->length();
380
String String::findReplace(const String &;find, const String &replace ) const
380
			break;
381
{
381
		}
382
	std::string newstr = *this;
382
383
	std::string::size_type pos = newstr.find(find, 0);
383
		std::string::size_type pos = startPos;
384
	while ( pos < std::string::npos ) {
384
		size_t i = 1;
385
		newstr.replace(pos, find.length(), replace);
385
		while ( i < max )
386
		pos = newstr.find(find, pos + replace.length());
386
		{
387
	}
387
			++pos;
388
 
388
			if ( this->at(pos) != token[i] )
389
	return newstr;
389
			{
390
}
390
				found = false;
391
 
391
				break;
392
String String::findRemove(const String &find) const
392
			}
393
{
393
			++i;
394
	Utils::String replace = *this;
394
		}
395
 
395
		curPos = pos;
396
	std::string::size_type pos = replace.find(find, 0 );
396
	}
397
	while ( pos != std::string::npos ) {
397
	return startPos;
398
		replace.erase ( pos, find.length() );
398
}
399
		pos = replace.find(find, pos);
399
400
	}
400
String String::findReplace(const String &find, const String &replace ) const
401
 
401
{
402
	return replace;
402
	std::string newstr = *this;
403
}
403
	std::string::size_type pos = newstr.find(find, 0);
404
 
404
	while ( pos < std::string::npos ) {
405
String String::stripHtml() const
405
		newstr.replace(pos, find.length(), replace);
406
{
406
		pos = newstr.find(find, pos + replace.length());
407
	// if empty, theres no to strip
407
	}
408
	if ( this->empty() ) return "";
408
409
 
409
	return newstr;
410
	// replace break line with a new line
410
}
411
	Utils::String newStr = (*this);
411
412
	newStr = newStr.findReplace("<br/>", &quot;\n");
412
String String::findRemove(const String &amp;find) const
413
	newStr = newStr.findReplace("<br />", "\n");
413
{
414
	newStr = newStr.findReplace("<p>", "\n\t");
414
	Utils::String replace = *this;
415
	newStr = newStr.findReplace("</p>", "\n");
415
416
 
416
	std::string::size_type pos = replace.find(find, 0 );
417
	// find any remaining tags and remove them
417
	while ( pos != std::string::npos ) {
418
	std::string::size_type pos     = newStr.find_first_of('<', 0);
418
		replace.erase ( pos, find.length() );
419
	std::string::size_type lastPos = newStr.find_first_of('>', pos);
419
		pos = replace.find(find, pos);
420
 
420
	}
421
	while (std::string::npos != pos || std::string::npos != lastPos)
421
422
	{
422
	return replace;
423
		if ( lastPos > newStr.length() ) break;
423
}
424
		// remove the tag
424
425
		newStr.erase(pos, lastPos + 1);
425
String String::stripHtml() const
426
 
426
{
427
		// find the next tag
427
	// if empty, theres no to strip
428
		pos = newStr.find_first_of(&apos;&lt;&apos;, pos);
428
	if ( this-&gt;empty() ) return &quot;&quot;;
429
		lastPos = newStr.find_first_of('>', pos);
429
430
	}
430
	// replace break line with a new line
431
 
431
	Utils::String newStr = (*this);
432
	// now remove all the starting new lines
432
	newStr = newStr.findReplace("<br/>", "\n");
433
	while ( newStr[0] == '\n' || newStr[0] == &apos;\t&apos; ) newStr.erase(0, 1);
433
	newStr = newStr.findReplace("&lt;br /&gt;", "\n");
434
	return newStr;
434
	newStr = newStr.findReplace("<p>", "\n\t");
435
}
435
	newStr = newStr.findReplace("</p>", "\n");
436
 
436

437
bool String::isin(const String &str, bool bCaseSensative) const
437
	// find any remaining tags and remove them
438
{
438
	std::string::size_type pos     = newStr.find_first_of('<', 0);
439
	unsigned int check = 0;
439
	std::string::size_type lastPos = newStr.find_first_of('>', pos);
440
	for ( unsigned int i = 0; i < this->length(); i++ )
440
441
	{
441
	while (std::string::npos != pos || std::string::npos != lastPos)
442
		bool bCheck	= (bCaseSensative) ? (this->at(i) == str[check]) : (tolower(this->at(i)) == tolower(str[check]));
442
	{
443
		if ( bCheck )
443
		if ( lastPos > newStr.length() ) break;
444
			++check;
444
		// remove the tag
445
		else
445
		newStr.erase(pos, lastPos + 1);
446
			check = 0;
446
447
 
447
		// find the next tag
448
		if ( check >= str.length() )
448
		pos = newStr.find_first_of('<', pos);
449
			return true;
449
		lastPos = newStr.find_first_of('>', pos);
450
	}
450
	}
451
	return false;
451
452
}
452
	// now remove all the starting new lines
453
 
453
	while ( newStr[0] == '\n' || newStr[0] == '\t' ) newStr.erase(0, 1);
454
int String::findPos(const String &;find, int iStartPos) const
454
	return newStr;
455
{
455
}
456
	std::string::size_type pos = this->find(find, iStartPos);
456
457
	if ( pos == std::string::npos ) return -1;
457
bool String::isin(const String &str, bool bCaseSensative) const
458
	return pos;
458
{
459
}
459
	unsigned int check = 0;
460
 
460
	for ( unsigned int i = 0; i < this->length(); i++ )
461
bool String::isin(char c, bool bCaseSensative) const
461
	{
462
{
462
		bool bCheck	= (bCaseSensative) ? (this->at(i) == str[check]) : (tolower(this->at(i)) == tolower(str[check]));
463
	bool f = false;
463
		if ( bCheck )
464
	for ( unsigned int i = 0; i < this->length(); i++ )
464
			++check;
465
	{
465
		else
466
		bool bCheck = (bCaseSensative) ? (this->at(i) == c) : (tolower(this->at(i)) == tolower(c));
466
			check = 0;
467
		if ( bCheck ) {
467
468
			f = true;
468
		if ( check >;= str.length() )
469
			break;
469
			return true;
470
		}
470
	}
471
	}
471
	return false;
472
	return f;
472
}
473
}
473
474
 
474
int String::findPos(const String &find, int iStartPos) const
475
String String::mid(int start, int end) const
475
{
476
{
476
	std::string::size_type pos = this->find(find, iStartPos);
477
	return this->substr(start, end - start);
477
	if ( pos == std::string::npos ) return -1;
478
}
478
	return pos;
479
String String::left(long num) const
479
}
480
{
480
481
	if ( num < 0 )
481
bool String::isin(char c, bool bCaseSensative) const
482
		num = (long)this->length() + num;
482
{
483
	if ( num >; (long)this->length() )
483
	bool f = false;
484
		num = (long)this->;length();
484
	for ( unsigned int i = 0; i < this->;length(); i++ )
485
 
485
	{
486
	return this->substr(0, num);
486
		bool bCheck = (bCaseSensative) ? (this->at(i) == c) : (tolower(this->at(i)) == tolower(c));
487
}
487
		if ( bCheck ) {
488
 
488
			f = true;
489
String String::right(int num) const
489
			break;
490
{
490
		}
491
	if ( num > 0 ) num -= (int)this->length();
491
	}
492
	if ( num < -(int)this->length() ) num = -(int)this->length();
492
	return f;
493
 
493
}
494
	return this->substr(-num);
494
495
}
495
String String::mid(int start, int end) const
496
 
496
{
497
const String &amp;String::readToEndOfLine(FILE *id, int *line, bool upper)
497
	return this-&gt;substr(start, end - start);
498
{
498
}
499
	(*this) == "";
499
String String::left(long num) const
500
	char c = fgetc ( id );
500
{
501
	if ( c == -1 )
501
	if ( num < 0 )
502
		return (*this);
502
		num = (long)this->length() + num;
503
 
503
	if ( num > (long)this->length() )
504
	while ( (c != 13) && (!feof(id)) && (c != '\n&apos;) )
504
		num = (long)this-&gt;length();
505
	{
505
506
		(*this) += c;
506
	return this->substr(0, num);
507
		c = fgetc ( id );
507
}
508
	}
508
509
 
509
String String::right(int num) const
510
	if ( line )
510
{
511
		++(*line);
511
	if ( num > 0 ) num -= (int)this->length();
512
 
512
	if ( num < -(int)this->length() ) num = -(int)this->length();
513
//	if ( upper )
513
514
	//	ToUpper ();
514
	return this->substr(-num);
515
 
515
}
516
	return (*this);
516
517
}
517
const String &String::readToEndOfLine(FILE *id, int *line, bool upper)
518
 
518
{
519
char *String::readToEndOfLine(char *data)
519
	(*this) == "";
520
{
520
	char c = fgetc ( id );
521
	return (char *)this->readToEndOfLine((unsigned char *)data);
521
	if ( c == -1 )
522
}
522
		return (*this);
523
unsigned char *String::readToEndOfLine(unsigned char *data)
523
524
{
524
	while ( (c != 13) && (!feof(id)) && (c != '\n') )
525
	int pos = 0;
525
	{
526
 
526
		(*this) += c;
527
	// do until we get a line break
527
		c = fgetc ( id );
528
	while ( (data[pos] != 13) && (data[pos] != 0) && (data[pos] != '\n') ) {
528
	}
529
		++pos;
529
530
	}
530
	if ( line )
531
 
531
		++(*line);
532
	if ( !pos ) {
532
533
		this->clear();
533
//	if ( upper )
534
	}
534
	//	ToUpper ();
535
	else {
535
536
		if ( pos >; 2000 ) {
536
	return (*this);
537
			char *d = new char[pos + 1];
537
}
538
			memcpy(d, data, pos);
538
539
			d[pos] = 0;
539
char *String::readToEndOfLine(char *data)
540
			*this = d;
540
{
541
			delete d;
541
	return (char *)this->readToEndOfLine((unsigned char *)data);
542
		}
542
}
543
		else {
543
unsigned char *String::readToEndOfLine(unsigned char *data)
544
			char d[2000];
544
{
545
			memcpy(d, data, pos);
545
	int pos = 0;
546
			d[pos] = 0;
546
547
			*this = d;
547
	// do until we get a line break
548
		}
548
	while ( (data[pos] != 13) && (data[pos] != 0) && (data[pos] != '\n') ) {
549
	}
549
		++pos;
550
 
550
	}
551
	if ( data[pos] == 0 ) return NULL;
551
552
	return data + (pos + 1);
552
	if ( !pos ) {
553
}
553
		this->clear();
554
 
554
	}
555
String String::replaceToken(const char *token, int from, const String &replace) const
555
	else {
556
{
556
		if ( pos > 2000 ) {
557
	std::string newstr;
557
			char *d = new char[pos + 1];
558
 
558
			memcpy(d, data, pos);
559
	int whichtok = 1;
559
			d[pos] = 0;
560
	std::string::size_type lastPos = 0;
560
			*this = d;
561
	std::string::size_type pos     = _token_nextPos(token, 0);
561
			delete d;
562
 
562
		}
563
	while (std::string::npos != pos || std::string::npos != lastPos)
563
		else {
564
	{
564
			char d[2000];
565
		if ( whichtok == from )
565
			memcpy(d, data, pos);
566
		{
566
			d[pos] = 0;
567
			if ( newstr != "" ) newstr = newstr + token;
567
			*this = d;
568
			newstr = newstr + replace;
568
		}
569
		}
569
	}
570
		else
570
571
		{
571
	if ( data[pos] == 0 ) return NULL;
572
			if ( newstr != "" ) newstr = newstr + token;
572
	return data + (pos + 1);
573
			newstr = newstr + this->substr(lastPos, pos - lastPos);
573
}
574
		}
574
575
 
575
String String::replaceToken(const char *token, int from, const String &replace) const
576
		// Found a token, add it to the vector.
576
{
577
		whichtok++;
577
	std::string newstr;
578
 
578

579
		if ( pos >= this->;length() )
579
	int whichtok = 1;
580
			break;
580
	std::string::size_type lastPos = 0;
581
 
581
	std::string::size_type pos     = _token_nextPos(token, 0);
582
		// skip past token
582
583
		size_t i = 0;
583
	while (std::string::npos != pos || std::string::npos != lastPos)
584
		size_t max = strlen(token);
584
	{
585
		lastPos = pos;
585
		if ( whichtok == from )
586
		while ( (i < max) && (token[i] == this->at(lastPos)) )
586
		{
587
		{
587
			if ( newstr != "" ) newstr = newstr + token;
588
			++i;
588
			newstr = newstr + replace;
589
			++lastPos;
589
		}
590
		}
590
		else
591
 
591
		{
592
		// get the next token
592
			if ( newstr != "" ) newstr = newstr + token;
593
		pos = _token_nextPos(token, lastPos);
593
			newstr = newstr + this->substr(lastPos, pos - lastPos);
594
	}
594
		}
595
	return newstr;
595
596
}
596
		// Found a token, add it to the vector.
597
 
597
		whichtok++;
598
 
598

599
String *String::tokenise(const char *token, int *max) const
599
		if ( pos >= this->length() )
600
{
600
			break;
601
	if ( empty() ) {
601
602
		*max = 0;
602
		// skip past token
603
		return NULL;
603
		size_t i = 0;
604
	}
604
		size_t max = strlen(token);
605
 
605
		lastPos = pos;
606
	*max = this->countToken(token);
606
		while ( (i < max) && (token[i] == this->at(lastPos)) )
607
 
607
		{
608
	if ( (*max) <;= 0 ) {
608
			++i;
609
		*max = 0;
609
			++lastPos;
610
		return NULL;
610
		}
611
	}
611
612
 
612
		// get the next token
613
	String *newstr = (*max == 1) ? new String : new String[*max];
613
		pos = _token_nextPos(token, lastPos);
614
 
614
	}
615
	int whichtok = 0;
615
	return newstr;
616
	// get first token
616
}
617
	std::string::size_type lastPos = 0;
617
618
	std::string::size_type pos     = this->_token_nextPos(token, 0);
618
619
 
619
String *String::tokenise(const char *token, int *max) const
620
	while (std::string::npos != pos || std::string::npos != lastPos)
620
{
621
	{
621
	if ( empty() ) {
622
		// set token
622
		*max = 0;
623
		if ( *max == 1 ) *newstr = this->substr(lastPos, pos - lastPos);
623
		return NULL;
624
		else			  newstr[whichtok] = this->substr(lastPos, pos - lastPos);
624
	}
625
 
625

626
		// move to next token
626
	*max = this->countToken(token);
627
		whichtok++;
627
628
		if ( whichtok &gt;= *max )
628
	if ( (*max) &lt;= 0 ) {
629
			break;
629
		*max = 0;
630
 
630
		return NULL;
631
		if ( pos >= this->length() )
631
	}
632
			break;
632
633
 
633
	String *newstr = (*max == 1) ? new String : new String[*max];
634
		// skip past token
634
635
		size_t i = 0;
635
	int whichtok = 0;
636
		size_t max = strlen(token);
636
	// get first token
637
		lastPos = pos;
637
	std::string::size_type lastPos = 0;
638
		while ( (i < max) && (token[i] == this->at(lastPos)) ) {
638
	std::string::size_type pos     = this->_token_nextPos(token, 0);
639
			++i;
639
640
			++lastPos;
640
	while (std::string::npos != pos || std::string::npos != lastPos)
641
		}
641
	{
642
 
642
		// set token
643
		// get the next token
643
		if ( *max == 1 ) *newstr = this->substr(lastPos, pos - lastPos);
644
		pos = _token_nextPos(token, lastPos);
644
		else			  newstr[whichtok] = this->substr(lastPos, pos - lastPos);
645
	}
645
646
 
646
		// move to next token
647
	return newstr;
647
		whichtok++;
648
}
648
		if ( whichtok >= *max )
649
 
649
			break;
650
const String &String::removeChar(char c)
650
651
{
651
		if ( pos >= this->length() )
652
	std::string::size_type pos = this->find_first_of(c, 0);
652
			break;
653
	while(pos != std::string::npos) {
653
654
		this->erase(pos, 1);
654
		// skip past token
655
		pos = this->find_first_of(c, 0);
655
		size_t i = 0;
656
	}
656
		size_t max = strlen(token);
657
 
657
		lastPos = pos;
658
	return (*this);
658
		while ( (i < max) && (token[i] == this->at(lastPos)) ) {
659
}
659
			++i;
660
 
660
			++lastPos;
661
String String::remove(char c) const
661
		}
662
{
662
663
	String newStr = *this;
663
		// get the next token
664
 
664
		pos = _token_nextPos(token, lastPos);
665
	std::string::size_type pos = newStr.find_first_of(c, 0);
665
	}
666
	while(pos != std::string::npos) {
666
667
		newStr.erase(pos, 1);
667
	return newstr;
668
		pos = newStr.find_first_of(c, 0);
668
}
669
	}
669
670
 
670
const String &String::removeChar(char c)
671
	return newStr;
671
{
672
}
672
	std::string::size_type pos = this->find_first_of(c, 0);
673
 
673
	while(pos != std::string::npos) {
674
bool String::_isCharNumber(char c) const
674
		this->erase(pos, 1);
675
{
675
		pos = this->find_first_of(c, 0);
676
	return (c >= '0' && c <= '9') ? true : false;
676
	}
677
}
677
678
 
678
	return (*this);
679
bool String::isCharNumber(int c) const
679
}
680
{
680
681
	return _isCharNumber(this->at(c));
681
String String::remove(char c) const
682
}
682
{
683
 
683
	String newStr = *this;
684
bool String::isNumber(bool integer) const
684
685
{
685
	std::string::size_type pos = newStr.find_first_of(c, 0);
686
	bool foundpoint = integer;
686
	while(pos != std::string::npos) {
687
	for ( int i = 0; i < (int)this->length(); i++ )
687
		newStr.erase(pos, 1);
688
	{
688
		pos = newStr.find_first_of(c, 0);
689
		// check for a decimal point (floating point value)
689
	}
690
		// only allow 1 decimal point, or none if just checking for an integer
690
691
		if ( this->at(i) == '.' && !foundpoint ) foundpoint = true;
691
	return newStr;
692
		// check if it is a number, 0-9
692
}
693
		else if ( !this->isCharNumber(i) ) return false;
693
694
	}
694
bool String::_isCharNumber(char c) const
695
	return true;
695
{
696
}
696
	return (c >= '0' && c <= '9') ? true : false;
697
 
697
}
698
const String &String::removeFirstSpace()
698
699
{
699
bool String::isCharNumber(int c) const
700
	std::string::size_type pos = this->find_first_not_of(" \t\f\v\n\r", 0);
700
{
701
	if ( pos != std::string::npos ) {
701
	return _isCharNumber(this->at(c));
702
		this->erase(0, pos);
702
}
703
	}
703
704
	return (*this);
704
bool String::isNumber(bool integer) const
705
}
705
{
706
const String &;String::removeEndSpace()
706
	bool foundpoint = integer;
707
{
707
	for ( int i = 0; i < (int)this->length(); i++ )
708
	std::string::size_type pos = this->find_last_not_of(" \t\f\v\n\r");
708
	{
709
	if ( pos != std::string::npos ) {
709
		// check for a decimal point (floating point value)
710
		this->erase(pos + 1);
710
		// only allow 1 decimal point, or none if just checking for an integer
711
	}
711
		if ( this->at(i) == '.' && !foundpoint ) foundpoint = true;
712
	return (*this);
712
		// check if it is a number, 0-9
713
}
713
		else if ( !this->isCharNumber(i) ) return false;
714
 
714
	}
715
const String &;String::truncate(int iNum)
715
	return true;
716
{
716
}
717
	size_t pos = iNum;
717
718
	if ( iNum < 0 ) pos = this-&gt;length() + iNum;
718
const String &amp;String::removeFirstSpace()
719
	this->erase(pos, this->length() - pos);
719
{
720
	return (*this);
720
	std::string::size_type pos = this->find_first_not_of(" \t\f\v\n\r", 0);
721
}
721
	if ( pos != std::string::npos ) {
722
 
722
		this->erase(0, pos);
723
String String::lower() const
723
	}
724
{
724
	return (*this);
725
	Utils::String newStr(*this);
725
}
726
	std::transform(this->begin(), this->end(), newStr.begin(), tolower);
726
const String &String::removeEndSpace()
727
	return newStr;
727
{
728
}
728
	std::string::size_type pos = this->find_last_not_of(" \t\f\v\n\r");
729
 
729
	if ( pos != std::string::npos ) {
730
String String::upper() const
730
		this->erase(pos + 1);
731
{
731
	}
732
	Utils::String newStr(*this);
732
	return (*this);
733
	std::transform(this->begin(), this->end(), newStr.begin(), toupper);
733
}
734
	return newStr;
734
735
}
735
const String &String::truncate(int iNum)
736
const String &String::toLower()
736
{
737
{
737
	size_t pos = iNum;
738
	std::transform(this->;begin(), this->end(), this->begin(), tolower);
738
	if ( iNum <; 0 ) pos = this->length() + iNum;
739
	return (*this);
739
	this->erase(pos, this->length() - pos);
740
}
740
	return (*this);
741
 
741
}
742
const String &String::toUpper()
742
743
{
743
String String::lower() const
744
	std::transform(this->begin(), this->end(), this->begin(), toupper);
744
{
745
	return (*this);
745
	Utils::String newStr(*this);
746
}
746
	std::transform(this->begin(), this->end(), newStr.begin(), tolower);
747
 
747
	return newStr;
748
}//NAMESPACE
748
}
-
 
749

-
 
750
String String::upper() const
-
 
751
{
-
 
752
	Utils::String newStr(*this);
-
 
753
	std::transform(this->begin(), this->end(), newStr.begin(), toupper);
-
 
754
	return newStr;
-
 
755
}
-
 
756
const String &String::toLower()
-
 
757
{
-
 
758
	std::transform(this->begin(), this->end(), this->begin(), tolower);
-
 
759
	return (*this);
-
 
760
}
-
 
761

-
 
762
const String &String::toUpper()
-
 
763
{
-
 
764
	std::transform(this->begin(), this->end(), this->begin(), toupper);
-
 
765
	return (*this);
-
 
766
}
-
 
767

-
 
768
int String::compareVersion(const Utils::String &sV) const
-
 
769
{
-
 
770
	Utils::String thisStr = (*this);
-
 
771
	Utils::String checkStr = sV;
-
 
772

-
 
773
	int section = 1;
-
 
774

-
 
775
	// remove any rc/beta version
-
 
776
	int beta1 = 0;
-
 
777
	int beta2 = 0;
-
 
778

-
 
779
	int len = 2;
-
 
780
	int pos = thisStr.findPos("rc", 0);
-
 
781
	if ( pos == -1 ) { pos = thisStr.findPos("beta", 0); len = 4; }
-
 
782
//		if ( pos == -1 ) { pos = thisStr.findPos("²", 0); len = 1; }
-
 
783
	if ( pos != -1 ) {
-
 
784
		beta1 = -(long)thisStr.right(-(pos + len)).remove(' ');
-
 
785
		thisStr = thisStr.left(pos).removeEndSpace();
-
 
786
	}
-
 
787

-
 
788
	len = 2;
-
 
789
	pos = checkStr.findPos("rc", 0);
-
 
790
	if ( pos == -1 ) { pos = checkStr.findPos("beta", 0); len = 4;}
-
 
791
//		if ( pos == -1 ) { pos = v.findPos("²", 0); len = 1; }
-
 
792
	if ( pos != -1 ) {
-
 
793
		beta2 = checkStr.right(-(pos + len)).remove(' ');
-
 
794
		checkStr = checkStr.left(pos).removeEndSpace();
-
 
795
	}
-
 
796

-
 
797
	while ( true ) {
-
 
798
		Utils::String sNum1 = thisStr.token(".", section);
-
 
799
		Utils::String sNum2 = checkStr.token(".", section);
-
 
800

-
 
801
		// no number nubmers, must be the same
-
 
802
		if ( sNum1.empty() && sNum2.empty() ) {
-
 
803
			// compare the beta/rc version
-
 
804
			if ( beta1 == beta2 )
-
 
805
				return COMPARE_SAME;
-
 
806
			if ( beta1 && !beta2 ) // new isn't a beta, so it must be higher
-
 
807
				return COMPARE_NEWER;
-
 
808
			if ( beta2 && !beta1 ) // old isn't a beta, so it must be higher
-
 
809
				return COMPARE_OLDER;
-
 
810
			if ( beta1 < 0 && beta2 > 0 ) // old is an rc and new is only a beta
-
 
811
				return COMPARE_OLDER;
-
 
812
			if ( beta2 < 0 && beta1 > 0 ) // new is an rc and old is only a beta
-
 
813
				return COMPARE_NEWER;
-
 
814
			// otherwise they are the same
-
 
815
			if ( beta1 > 0 ) {
-
 
816
				if ( beta1 > beta2 )
-
 
817
					return COMPARE_OLDER;
-
 
818
				else
-
 
819
					return COMPARE_NEWER;
-
 
820
			}
-
 
821
			if ( beta1 < 0 ) {
-
 
822
				if ( beta1 < beta2 )
-
 
823
					return COMPARE_OLDER;
-
 
824
				else
-
 
825
					return COMPARE_NEWER;
-
 
826
			}
-
 
827
			// failsale, we should never get here
-
 
828
			return COMPARE_SAME;
-
 
829
		}
-
 
830

-
 
831
		// one has more sections, most likly its the newer ones, ie, 1.00 v 1.00.1, 1.00.1 will be newer
-
 
832
		if ( sNum1.empty() )
-
 
833
			return COMPARE_NEWER;
-
 
834
		else if ( sNum2.empty() )
-
 
835
			return COMPARE_OLDER;
-
 
836

-
 
837
		// check if we have any letters at the end
-
 
838
		char cNum1 = 0, cNum2 = 0;
-
 
839
		if ( !sNum1.isCharNumber((int)sNum1.length() - 1) )
-
 
840
		{
-
 
841
			cNum1 = toupper(sNum1[(int)sNum1.length() - 1]);
-
 
842
			sNum1.truncate(-1);
-
 
843
		}
-
 
844
		if ( !sNum2.isCharNumber((int)sNum2.length() - 1) )
-
 
845
		{
-
 
846
			cNum2 = toupper(sNum2[(int)sNum2.length() - 1]);
-
 
847
			sNum2.truncate(-1);
-
 
848
		}
-
 
849

-
 
850
		// now make sure each section is the correct length
-
 
851
		if ( section > 1 )
-
 
852
		{
-
 
853
			while ( sNum1.length() < sNum2.length() )
-
 
854
				sNum1 += "0";
-
 
855
			while ( sNum2.length() < sNum1.length() )
-
 
856
				sNum2 += "0";
-
 
857
		}
-
 
858

-
 
859
		// check the values of the current section
-
 
860
		int iNum1 = sNum1;
-
 
861
		int iNum2 = sNum2;
-
 
862

-
 
863
		if ( iNum1 > iNum2 )
-
 
864
			return COMPARE_OLDER;
-
 
865
		if ( iNum2 > iNum1 )
-
 
866
			return COMPARE_NEWER;
-
 
867

-
 
868
		// now compare the "letter" version, only test if one has a letter
-
 
869
		if ( cNum1 || cNum2 )
-
 
870
		{
-
 
871
			if ( !cNum1 )
-
 
872
				return COMPARE_NEWER;
-
 
873
			if ( !cNum2 )
-
 
874
				return COMPARE_OLDER;
-
 
875

-
 
876
			if ( cNum2 > cNum1 )
-
 
877
				return COMPARE_NEWER;
-
 
878
			else if ( cNum1 > cNum2 )
-
 
879
				return COMPARE_OLDER;
-
 
880
		}
-
 
881

-
 
882
		// move to the next section
-
 
883
		++section;
-
 
884
	}
-
 
885

-
 
886
	return COMPARE_SAME;
-
 
887
}
-
 
888

-
 
889
}//NAMESPACE
-
 
890