Subversion Repositories spk

Rev

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

Rev 186 Rev 188
Line 4... Line 4...
4
#include <stdarg.h>
4
#include <stdarg.h>
5
#include <algorithm>
5
#include <algorithm>
6
#include <iomanip>
6
#include <iomanip>
7
#include <locale>
7
#include <locale>
8
#include <codecvt>
8
#include <codecvt>
-
 
9

-
 
10
#include "WString.h"
9

11

10
namespace Utils {
12
namespace Utils {
11

13

12
	std::wstring s2ws(const std::string& str)
14
	std::wstring s2ws(const std::string& str)
13
	{
15
	{
Line 31... Line 33...
31

33

32
		return converterX.to_bytes(wstr);
34
		return converterX.to_bytes(wstr);
33
	}
35
	}
34

36

35

37

36
	String operator+(const char* str1, const String& str2)
38
	SString operator+(const char* str1, const SString& str2)
37
	{
39
	{
38
		return String(str1) + str2;
40
		return SString(str1) + str2;
39
	}
41
	}
40
	String operator+(const unsigned char* str1, const String& str2)
42
	SString operator+(const unsigned char* str1, const SString& str2)
41
	{
43
	{
42
		return String(str1) + str2;
44
		return SString(str1) + str2;
43
	}
45
	}
44

46

45
String::String(void)						{ this->assign(""); }
47
SString::SString(void)						{ this->assign(""); }
46
String::String(const char *str)				{ this->assign(str); }
48
SString::SString(const char *str)			{ this->assign(str); }
47
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
49
SString::SString(const unsigned char *str)	{ this->assign((const char *)str); }
48
String::String(const std::string &str)		{ this->assign(str);}
50
SString::SString(const std::string &str)	{ this->assign(str);}
49
String::String(const unsigned char c)		{ this->assign(1, c); }
51
SString::SString(const unsigned char c)		{ this->assign(1, c); }
50
String::String(const char c)				{ this->assign(1, c); }
52
SString::SString(const char c)				{ this->assign(1, c); }
51
String::String(const String &str)			{ this->assign(str); }
53
SString::SString(const SString &str)		{ this->assign(str); }
52
String::String(long l)						{ this->fromLong(l); }
54
SString::SString(long l)					{ this->fromLong(l); }
53
String::String(unsigned long l)				{ this->fromLong((long)l); }
55
SString::SString(unsigned long l)			{ this->fromLong((long)l); }
54
String::String(float f)						{ this->fromFloat(f); }
56
SString::SString(float f)					{ this->fromFloat(f); }
55
String::String(double f)					{ this->fromDouble(f); }
57
SString::SString(double f)					{ this->fromDouble(f); }
56

58

57
String::~String(void)
59
SString::~SString(void)
58
{
60
{
59
}
61
}
60

62

61
String String::PadNumber(long iNumber, int iAmount)
63
SString SString::PadNumber(long iNumber, int iAmount)
62
{
64
{
63
	String str(iNumber);
65
	SString str(iNumber);
64
	return str.padNumber(iAmount);
66
	return str.padNumber(iAmount);
65
}
67
}
66

68

67
const String &String::padNumber(int iAmount)
69
const SString &SString::padNumber(int iAmount)
68
{
70
{
69
	return this->pad(iAmount, '0');
71
	return this->pad(iAmount, '0');
70
}
72
}
71

73

72
const String &String::pad(int iAmount, char cWith)
74
const SString &SString::pad(int iAmount, char cWith)
73
{
75
{
74
	std::stringstream strm;
76
	std::stringstream strm;
75
	strm << std::setw(iAmount) << std::setfill(cWith) << *this;
77
	strm << std::setw(iAmount) << std::setfill(cWith) << *this;
76
	*this = strm.str();
78
	*this = strm.str();
77
	return (*this);
79
	return (*this);
Line 79... Line 81...
79

81

80

82

81
/////////////////////////////////////////////////////////////////
83
/////////////////////////////////////////////////////////////////
82
// Conversion functions
84
// Conversion functions
83

85

84
void String::fromLong(long l)
86
void SString::fromLong(long l)
85
{
87
{
86
	std::stringstream strstream;
88
	std::stringstream strstream;
87
	strstream << l;
89
	strstream << l;
88
	*this = strstream.str();
90
	*this = strstream.str();
89
}
91
}
90
92
91
const String &String::fromFloat(float f, int dp)
93
const SString &SString::fromFloat(float f, int dp)
92
{
94
{
93
	std::stringstream strstream;
95
	std::stringstream strstream;
94
	if ( dp != -1 ) {
96
	if ( dp != -1 ) {
95
		strstream.precision(dp);
97
		strstream.precision(dp);
96
		strstream << std::fixed << f;
98
		strstream << std::fixed << f;
97
	}
99
	}
98
	else
100
	else
99
		strstream << f;
101
		strstream << f;
100
	*this = strstream.str();
102
	*this = strstream.str();
101
	return (*this);
103
	return (*this);
102
}
104
}
103

105

104
void String::fromDouble(double f)
106
void SString::fromDouble(double f)
105
{
107
{
106
	std::stringstream strstream;
108
	std::stringstream strstream;
107
	strstream << f;
109
	strstream << f;
108
	*this = strstream.str();
110
	*this = strstream.str();
109
}
111
}
110

112

111
const String &String::fromDouble(double f, int dp)
113
const SString &SString::fromDouble(double f, int dp)
112
{
114
{
113
	std::stringstream strstream;
115
	std::stringstream strstream;
114
	if (dp != -1) {
116
	if (dp != -1) {
115
		strstream.precision(dp);
117
		strstream.precision(dp);
116
		strstream << std::fixed << f;
118
		strstream << std::fixed << f;
Line 119... Line 121...
119
		strstream << f;
121
		strstream << f;
120
	*this = strstream.str();
122
	*this = strstream.str();
121
	return (*this);
123
	return (*this);
122
}
124
}
123

125

124
const String &String::format(const char *sFormat, ...)
126
const SString &SString::format(const char *sFormat, ...)
125
{
127
{
126
	char buffer[1024];
128
	char buffer[1024];
127
	va_list args;
129
	va_list args;
128
	va_start (args, sFormat);
130
	va_start (args, sFormat);
129
	vsprintf (buffer, sFormat, args);
131
	vsprintf (buffer, sFormat, args);
Line 131... Line 133...
131

133

132
	this->assign(buffer);
134
	this->assign(buffer);
133
	return (*this);
135
	return (*this);
134
}
136
}
135

137

136
const String String::args(const String *args, int max) const
138
const SString SString::args(const SString *args, int max) const
137
{
139
{
138
	Utils::String str = (*this);
140
	Utils::SString str = (*this);
139
	for (int i = 0; i < max; i++)
141
	for (int i = 0; i < max; i++)
140
	{
142
	{
141
		Utils::String find("%");
143
		Utils::SString find("%");
142
		find += Utils::String::Number(i + 1);
144
		find += Utils::SString::Number(i + 1);
143

145

144
		str = str.findReplace(find, args[i]);
146
		str = str.findReplace(find, args[i]);
145
	}
147
	}
146

148

147
	return str;
149
	return str;
148
}
150
}
149
const String &String::arg(const String &s1)
151
const SString &SString::arg(const SString &s1)
150
{
152
{
151
	(*this) = this->findReplace("%1", s1);
153
	(*this) = this->findReplace("%1", s1);
152
	return (*this);
154
	return (*this);
153
}
155
}
154

156

155
const String &String::arg(const String &s1, const String &s2)
157
const SString &SString::arg(const SString &s1, const SString &s2)
156
{
158
{
157
	(*this) = this->arg(s1).findReplace("%2", s2);
159
	(*this) = this->arg(s1).findReplace("%2", s2);
158
	return (*this);
160
	return (*this);
159
}
161
}
160
const String &String::arg(const String &s1, const String &s2, const String &s3)
162
const SString &SString::arg(const SString &s1, const SString &s2, const SString &s3)
161
{
163
{
162
	(*this) = this->arg(s1, s1).findReplace("%3", s3);
164
	(*this) = this->arg(s1, s1).findReplace("%3", s3);
163
	return (*this);
165
	return (*this);
164
}
166
}
165
const String &String::arg(const String &s1, const String &s2, const String &s3, const String &s4)
167
const SString &SString::arg(const SString &s1, const SString &s2, const SString &s3, const SString &s4)
166
{
168
{
167
	(*this) = this->arg(s1, s2, s3).findReplace("%4", s4);
169
	(*this) = this->arg(s1, s2, s3).findReplace("%4", s4);
168
	return (*this);
170
	return (*this);
169
}
171
}
170
const String &String::arg(const String &s1, const String &s2, const String &s3, const String &s4, const String &s5)
172
const SString &SString::arg(const SString &s1, const SString &s2, const SString &s3, const SString &s4, const SString &s5)
171
{
173
{
172
	(*this) = this->arg(s1, s2, s3, s4).findReplace("%5", s5);
174
	(*this) = this->arg(s1, s2, s3, s4).findReplace("%5", s5);
173
	return (*this);
175
	return (*this);
174
}
176
}
175

177

176

178

177
String String::Null()
179
SString SString::Null()
178
{
180
{
179
	return Utils::String();
181
	return Utils::SString();
180
}
182
}
181

183

182
String String::FromFloat(float f, int dp)
184
SString SString::FromFloat(float f, int dp)
183
{ 
185
{ 
184
	String str;
186
	SString str;
185
	str.fromFloat(f, dp); 
187
	str.fromFloat(f, dp); 
186
	return str;
188
	return str;
187
}
189
}
188

190

189
String String::Format(const char *sFormat, ...)
191
SString SString::Format(const char *sFormat, ...)
190
{
192
{
191
	char buffer[1024];
193
	char buffer[1024];
192
	va_list args;
194
	va_list args;
193
	va_start (args, sFormat);
195
	va_start (args, sFormat);
194
	vsprintf (buffer, sFormat, args);
196
	vsprintf (buffer, sFormat, args);
195
	va_end (args);
197
	va_end (args);
196

198

197
	return String(buffer);
199
	return SString(buffer);
198
}
200
}
199

201

200
bool String::toBool() const
202
bool SString::toBool() const
201
{
203
{
202
	return atoi(this->c_str()) ? true : false;
204
	return atoi(this->c_str()) ? true : false;
203
}
205
}
204
long String::toLong() const
206
long SString::toLong() const
205
{
207
{
206
	return static_cast<long>(atoi(this->c_str()));
208
	return static_cast<long>(atoi(this->c_str()));
207
}
209
}
208
int String::toInt() const
210
int SString::toInt() const
209
{
211
{
210
	return static_cast<int>(atoi(this->c_str()));
212
	return static_cast<int>(atoi(this->c_str()));
211
}
213
}
212
double String::toDouble() const
214
double SString::toDouble() const
213
{
215
{
214
	return atof(this->c_str());
216
	return atof(this->c_str());
215
}
217
}
216
float String::toFloat() const
218
float SString::toFloat() const
217
{
219
{
218
	return (float)atof(this->c_str());
220
	return (float)atof(this->c_str());
-
 
221
}
-
 
222

-
 
223
const Utils::WString SString::toWString() const 
-
 
224
{ 
-
 
225
	return s2ws(*this); 
219
}
226
}
220

227

221

228

222
const String &String::operator= ( const char *str )				{ this->assign(str); return (*this); }
229
const SString &SString::operator= ( const char *str )				{ this->assign(str); return (*this); }
223
const String &String::operator= ( const unsigned char *str )	{ this->assign((const char *)str); return (*this); }
230
const SString &SString::operator= ( const unsigned char *str )		{ this->assign((const char *)str); return (*this); }
224
const String &String::operator= ( const String &str )			{ this->assign((std::string &)str); return (*this); }
231
const SString &SString::operator= ( const SString &str )			{ this->assign((std::string &)str); return (*this); }
225
const String &String::operator= ( const std::string &str )		{ this->assign(str); return (*this); }
232
const SString &SString::operator= ( const std::string &str )		{ this->assign(str); return (*this); }
226
const String &String::operator= ( unsigned char c )				{ this->assign(1, c); return (*this); }
233
const SString &SString::operator= ( unsigned char c )				{ this->assign(1, c); return (*this); }
227
const String &String::operator= ( char c )						{ this->assign(1, c); return (*this); }
234
const SString &SString::operator= ( char c )						{ this->assign(1, c); return (*this); }
228
const String &String::operator= ( long l )						{ this->fromLong(l); return (*this); }
235
const SString &SString::operator= ( long l )						{ this->fromLong(l); return (*this); }
229
const String &String::operator= ( unsigned long l )				{ this->fromLong(l); return (*this); }
236
const SString &SString::operator= ( unsigned long l )				{ this->fromLong(l); return (*this); }
230
const String &String::operator= ( float f )						{ this->fromFloat(f); return (*this); }
237
const SString &SString::operator= ( float f )						{ this->fromFloat(f); return (*this); }
231
const String &String::operator= ( double f )					{ this->fromDouble(f); return (*this); }
238
const SString &SString::operator= ( double f )						{ this->fromDouble(f); return (*this); }
232

239

233
const unsigned char String::operator[] ( int num ) const			{ return this->at(num); }
240
const unsigned char SString::operator[] ( int num ) const			{ return this->at(num); }
234
unsigned char &String::operator[] ( int num )						{ return (unsigned char &)this->at(num); }
241
unsigned char &SString::operator[] ( int num )						{ return (unsigned char &)this->at(num); }
235

242

236
const String &String::operator+= ( const char *str )			{ this->append(str); return (*this); }
243
const SString &SString::operator+= ( const char *str )				{ this->append(str); return (*this); }
237
const String &String::operator+= ( const unsigned char *str ) 	{ this->append((const char *)str); return (*this); }
244
const SString &SString::operator+= ( const unsigned char *str ) 	{ this->append((const char *)str); return (*this); }
238
const String &String::operator+= ( const std::string &str )		{ this->append(str); return (*this); }
245
const SString &SString::operator+= ( const std::string &str )		{ this->append(str); return (*this); }
239
const String &String::operator+= ( const String &str )		{ this->append(str); return (*this); }
246
const SString &SString::operator+= ( const SString &str )			{ this->append(str); return (*this); }
240
const String &String::operator+= ( const char c )				{ this->append(1, c); return (*this); }
247
const SString &SString::operator+= ( const char c )					{ this->append(1, c); return (*this); }
241
const String &String::operator+= ( const unsigned char c )		{ this->append(1, c); return (*this); }
248
const SString &SString::operator+= ( const unsigned char c )		{ this->append(1, c); return (*this); }
242
const String &String::operator+= ( const unsigned long l )		
249
const SString &SString::operator+= ( const unsigned long l )		
243
{ 
250
{ 
244
	std::stringstream strm;
251
	std::stringstream strm;
245
	strm << (*this) << l;
252
	strm << (*this) << l;
246
	strm >> (*this);
253
	strm >> (*this);
247
	return (*this); 
254
	return (*this); 
248
}
255
}
249
const String &String::operator+= ( const long l )		
256
const SString &SString::operator+= ( const long l )		
250
{ 
257
{ 
251
	std::stringstream strm;
258
	std::stringstream strm;
252
	strm << (*this) << l;
259
	strm << (*this) << l;
253
	*this = strm.str();
260
	*this = strm.str();
254
	return (*this); 
261
	return (*this); 
255
}
262
}
256
const String &String::operator+= ( const float f )		
263
const SString &SString::operator+= ( const float f )		
257
{ 
264
{ 
258
	std::stringstream strm;
265
	std::stringstream strm;
259
	strm << (*this) << f;
266
	strm << (*this) << f;
260
	*this = strm.str();
267
	*this = strm.str();
261
	return (*this); 
268
	return (*this); 
262
}
269
}
263
const String &String::operator+= ( const double f )		
270
const SString &SString::operator+= ( const double f )		
264
{ 
271
{ 
265
	std::stringstream strm;
272
	std::stringstream strm;
266
	strm << (*this) << f;
273
	strm << (*this) << f;
267
	*this = strm.str();
274
	*this = strm.str();
268
	return (*this); 
275
	return (*this); 
269
}
276
}
270

277

271

278

272
String String::operator+ ( const char *str ) const			{ return String(*this) += str; }
279
SString SString::operator+ ( const char *str ) const			{ return SString(*this) += str; }
273
String String::operator+ ( const unsigned char *str ) const	{ return String(*this) += str; }
280
SString SString::operator+ ( const unsigned char *str ) const	{ return SString(*this) += str; }
274
String String::operator+ ( const std::string &str ) const	{ return String(*this) += str; }
281
SString SString::operator+ ( const std::string &str ) const		{ return SString(*this) += str; }
275
String String::operator+ ( const String &str ) const		{ return String(*this) += str; }
282
SString SString::operator+ ( const SString &str ) const			{ return SString(*this) += str; }
276
String String::operator+ ( const char c ) const				{ return String(*this) += c; }
283
SString SString::operator+ ( const char c ) const				{ return SString(*this) += c; }
277
String String::operator+ ( const unsigned char c ) const	{ return String(*this) += c; }
284
SString SString::operator+ ( const unsigned char c ) const		{ return SString(*this) += c; }
278
String String::operator+ ( const long l ) const				{ return String(*this) += l; }
285
SString SString::operator+ ( const long l ) const				{ return SString(*this) += l; }
279
String String::operator+ ( const unsigned long l ) const	{ return String(*this) += l; }
286
SString SString::operator+ ( const unsigned long l ) const		{ return SString(*this) += l; }
280
String String::operator+ ( const float f ) const			{ return String(*this) += f; }
287
SString SString::operator+ ( const float f ) const				{ return SString(*this) += f; }
281
String String::operator+ ( const double f ) const			{ return String(*this) += f; }
288
SString SString::operator+ ( const double f ) const				{ return SString(*this) += f; }
282

289

283
bool String::operator== ( const char *str ) const				{ return (this->compare(str)) ? false : true; }
290
bool SString::operator== ( const char *str ) const				{ return (this->compare(str)) ? false : true; }
284
bool String::operator== ( const unsigned char *str ) const	{ return (this->compare((const char *)str)) ? false : true; }
291
bool SString::operator== ( const unsigned char *str ) const		{ return (this->compare((const char *)str)) ? false : true; }
285
bool String::operator== ( const std::string &str ) const		{ return (this->compare(str)) ? false : true; }
292
bool SString::operator== ( const std::string &str ) const		{ return (this->compare(str)) ? false : true; }
286
bool String::operator== ( const String &str ) const			{ return (this->compare(str)) ? false : true; }
293
bool SString::operator== ( const SString &str ) const			{ return (this->compare(str)) ? false : true; }
287

294

288
bool String::operator!= ( const char *str ) const				{ return (this->compare(str)) ? true : false; }
295
bool SString::operator!= ( const char *str ) const				{ return (this->compare(str)) ? true : false; }
289
bool String::operator!= ( const unsigned char *str ) const	{ return (this->compare((const char *)str)) ? true : false; }
296
bool SString::operator!= ( const unsigned char *str ) const		{ return (this->compare((const char *)str)) ? true : false; }
290
bool String::operator!= ( const std::string &str ) const		{ return (this->compare(str)) ? true : false; }
297
bool SString::operator!= ( const std::string &str ) const		{ return (this->compare(str)) ? true : false; }
291
bool String::operator!= ( const String &str ) const			{ return (this->compare(str)) ? true : false; }
298
bool SString::operator!= ( const SString &str ) const			{ return (this->compare(str)) ? true : false; }
292

299

293
bool String::operator !() const
300
bool SString::operator !() const
294
{
301
{
295
	return this->empty();
302
	return this->empty();
296
}
303
}
297

304

298
bool String::Compare(const String &str, bool bCaseSensative) const
305
bool SString::Compare(const SString &str, bool bCaseSensative) const
299
{
306
{
300
	if ( bCaseSensative ) {
307
	if ( bCaseSensative ) {
301
		return (this->compare(str) == 0) ? true : false;
308
		return (this->compare(str) == 0) ? true : false;
302
	}
309
	}
303

310

Line 308... Line 315...
308
		}
315
		}
309
	}
316
	}
310
	return true;
317
	return true;
311
}
318
}
312

319

313
bool String::Compare(const unsigned char *str, bool bCaseSensative) const
320
bool SString::Compare(const unsigned char *str, bool bCaseSensative) const
314
{
321
{
315
	return this->Compare((const char *)str, bCaseSensative);
322
	return this->Compare((const char *)str, bCaseSensative);
316
}
323
}
317

324

318
bool String::Compare(const char *str, bool bCaseSensative) const
325
bool SString::Compare(const char *str, bool bCaseSensative) const
319
{
326
{
320
	if ( bCaseSensative ) {
327
	if ( bCaseSensative ) {
321
		return (this->compare(str) == 0) ? true : false;
328
		return (this->compare(str) == 0) ? true : false;
322
	}
329
	}
323

330

Line 329... Line 336...
329
	}
336
	}
330

337

331
	return true;
338
	return true;
332
}
339
}
333

340

334
String String::token(const char *token, int tok) const
341
SString SString::token(const char *token, int tok) const
335
{
342
{
336
	return this->tokens(token, tok, tok);
343
	return this->tokens(token, tok, tok);
337
}
344
}
338

345

339
String String::tokens(const char *token, int from, int to) const
346
SString SString::tokens(const char *token, int from, int to) const
340
{
347
{
341
	if ( this->empty() ) return "";
348
	if ( this->empty() ) return "";
342

349

343
	int max = this->countToken(token);
350
	int max = this->countToken(token);
344

351

345
	Utils::String newstr;
352
	Utils::SString newstr;
346

353

347
	int whichtok = 1;
354
	int whichtok = 1;
348
	Utils::String::size_type lastPos = 0;
355
	Utils::SString::size_type lastPos = 0;
349
	Utils::String::size_type pos     = _token_nextPos(token, 0);
356
	Utils::SString::size_type pos     = _token_nextPos(token, 0);
350

357

351
	if ( from < 0 )
358
	if ( from < 0 )
352
		from = max + (from + 1);
359
		from = max + (from + 1);
353
	if ( to < 0 )
360
	if ( to < 0 )
354
		to = max + (to + 1);
361
		to = max + (to + 1);
355

362

356
	while (Utils::String::npos != pos || Utils::String::npos != lastPos)
363
	while (Utils::SString::npos != pos || Utils::SString::npos != lastPos)
357
	{
364
	{
358
		if ( to == 0 )
365
		if ( to == 0 )
359
		{
366
		{
360
			if ( whichtok >= from )
367
			if ( whichtok >= from )
361
			{
368
			{
362
				if ( newstr != "" ) newstr = newstr + token;
369
				if ( newstr != "" ) newstr = newstr + token;
363
				newstr = newstr + Utils::String(this->substr(lastPos, pos - lastPos));
370
				newstr = newstr + Utils::SString(this->substr(lastPos, pos - lastPos));
364
			}
371
			}
365
		}
372
		}
366
		else
373
		else
367
		{
374
		{
368
			if ( (whichtok >= from) && (whichtok <= to) )
375
			if ( (whichtok >= from) && (whichtok <= to) )
369
			{
376
			{
370
				if ( newstr != "" ) newstr = newstr + token;
377
				if ( newstr != "" ) newstr = newstr + token;
371
				newstr = newstr + Utils::String(this->substr(lastPos, pos - lastPos));
378
				newstr = newstr + Utils::SString(this->substr(lastPos, pos - lastPos));
372
			}
379
			}
373
			if ( whichtok > to )
380
			if ( whichtok > to )
374
				break;
381
				break;
375
		}
382
		}
376
		// Found a token, add it to the vector.
383
		// Found a token, add it to the vector.
Line 393... Line 400...
393
		pos = _token_nextPos(token, lastPos);
400
		pos = _token_nextPos(token, lastPos);
394
	}
401
	}
395
	return newstr;
402
	return newstr;
396
}
403
}
397

404

398
String String::remToken(const char* token, int from) const
405
SString SString::remToken(const char* token, int from) const
399
{
406
{
400
	Utils::String newstr;
407
	Utils::SString newstr;
401

408

402
	if (from < 0)
409
	if (from < 0)
403
	{
410
	{
404
		int maxT = this->countToken(token);
411
		int maxT = this->countToken(token);
405
		from = maxT + (from + 1);
412
		from = maxT + (from + 1);
406
	}
413
	}
407

414

408
	int whichtok = 1;
415
	int whichtok = 1;
409
	Utils::String::size_type lastPos = 0;
416
	Utils::SString::size_type lastPos = 0;
410
	Utils::String::size_type pos = _token_nextPos(token, 0);
417
	Utils::SString::size_type pos = _token_nextPos(token, 0);
411

418

412
	while (Utils::String::npos != pos || Utils::String::npos != lastPos)
419
	while (Utils::SString::npos != pos || Utils::SString::npos != lastPos)
413
	{
420
	{
414
		if (whichtok != from)
421
		if (whichtok != from)
415
		{
422
		{
416
			if (newstr != "") newstr = newstr + token;
423
			if (newstr != "") newstr = newstr + token;
417
			newstr = newstr + Utils::String(this->substr(lastPos, pos - lastPos));
424
			newstr = newstr + Utils::SString(this->substr(lastPos, pos - lastPos));
418
		}
425
		}
419

426

420
		// Found a token, add it to the vector.
427
		// Found a token, add it to the vector.
421
		whichtok++;
428
		whichtok++;
422

429

Line 437... Line 444...
437
		pos = _token_nextPos(token, lastPos);
444
		pos = _token_nextPos(token, lastPos);
438
	}
445
	}
439
	return newstr;
446
	return newstr;
440
}
447
}
441

448

442
String String::remTokens(const char* token, int from, int to) const
449
SString SString::remTokens(const char* token, int from, int to) const
443
{
450
{
444
	Utils::String newstr;
451
	Utils::SString newstr;
445

452

446
	if (from < 0)
453
	if (from < 0)
447
	{
454
	{
448
		int maxT = this->countToken(token);
455
		int maxT = this->countToken(token);
449
		from = maxT + (from + 1);
456
		from = maxT + (from + 1);
Line 453... Line 460...
453
		int maxT = this->countToken(token);
460
		int maxT = this->countToken(token);
454
		to = maxT + (to + 1);
461
		to = maxT + (to + 1);
455
	}
462
	}
456

463

457
	int whichtok = 1;
464
	int whichtok = 1;
458
	Utils::String::size_type lastPos = 0;
465
	Utils::SString::size_type lastPos = 0;
459
	Utils::String::size_type pos = _token_nextPos(token, 0);
466
	Utils::SString::size_type pos = _token_nextPos(token, 0);
460

467

461
	while (Utils::String::npos != pos || Utils::String::npos != lastPos)
468
	while (Utils::SString::npos != pos || Utils::SString::npos != lastPos)
462
	{
469
	{
463
		if (!(whichtok >= from && whichtok <= to))
470
		if (!(whichtok >= from && whichtok <= to))
464
		{
471
		{
465
			if (newstr != "") newstr = newstr + token;
472
			if (newstr != "") newstr = newstr + token;
466
			newstr = newstr + Utils::String(this->substr(lastPos, pos - lastPos));
473
			newstr = newstr + Utils::SString(this->substr(lastPos, pos - lastPos));
467
		}
474
		}
468

475

469
		// Found a token, add it to the vector.
476
		// Found a token, add it to the vector.
470
		whichtok++;
477
		whichtok++;
471

478

Line 486... Line 493...
486
		pos = _token_nextPos(token, lastPos);
493
		pos = _token_nextPos(token, lastPos);
487
	}
494
	}
488
	return newstr;
495
	return newstr;
489
}
496
}
490

497

491
String String::word(int word) const
498
SString SString::word(int word) const
492
{
499
{
493
	return this->token(" ", word);
500
	return this->token(" ", word);
494
}
501
}
495
String String::words(int from, int to) const
502
SString SString::words(int from, int to) const
496
{
503
{
497
	return this->tokens(" ", from, to);
504
	return this->tokens(" ", from, to);
498
}
505
}
499

506

500
String String::addToken(const char *token, const Utils::String &str) const
507
SString SString::addToken(const char *token, const Utils::SString &str) const
501
{
508
{
502
	if (this->empty())
509
	if (this->empty())
503
		return str;
510
		return str;
504

511

505
	Utils::String s = (*this);
512
	Utils::SString s = (*this);
506
	s += token;
513
	s += token;
507
	s += str;
514
	s += str;
508

515

509
	return s;
516
	return s;
510
}
517
}
511

518

512
int String::countToken(const char *token) const
519
int SString::countToken(const char *token) const
513
{
520
{
514
	if ( this->empty() )
521
	if ( this->empty() )
515
		return 0;
522
		return 0;
516

523

517
	// finds the number of tokens in a string
524
	// finds the number of tokens in a string
518
	int found = 1;
525
	int found = 1;
519

526

520
	Utils::String tmpstr = *this;
527
	Utils::SString tmpstr = *this;
521

528

522
	// ignore the initial spaces
529
	// ignore the initial spaces
523
	Utils::String::size_type pos = this->find_first_not_of(token, 0);
530
	Utils::SString::size_type pos = this->find_first_not_of(token, 0);
524

531

525
	// remove end spaces
532
	// remove end spaces
526
	size_t i = tmpstr.size() - 1;
533
	size_t i = tmpstr.size() - 1;
527
	while ( tmpstr[i] == ' ' && i > 0 )
534
	while ( tmpstr[i] == ' ' && i > 0 )
528
		i--;
535
		i--;
529
	if ( i <= 0 ) return 0;
536
	if ( i <= 0 ) return 0;
530
	tmpstr.erase ( i + 1, tmpstr.size() - i );
537
	tmpstr.erase ( i + 1, tmpstr.size() - i );
531

538

532
	// count tokens
539
	// count tokens
533
	pos = tmpstr.find (token,pos + 1);
540
	pos = tmpstr.find (token,pos + 1);
534
	while ( pos < Utils::String::npos )
541
	while ( pos < Utils::SString::npos )
535
	{
542
	{
536
		while (tmpstr[pos] == ' ')
543
		while (tmpstr[pos] == ' ')
537
			pos++;
544
			pos++;
538
		found++;
545
		found++;
539
		pos = tmpstr.find (token,pos + 1);
546
		pos = tmpstr.find (token,pos + 1);
Line 541... Line 548...
541

548

542
	// return number of tokens
549
	// return number of tokens
543
	return found;
550
	return found;
544
}
551
}
545

552

546
Utils::String::size_type String::_token_nextPos(const char *token, Utils::String::size_type curPos) const
553
Utils::SString::size_type SString::_token_nextPos(const char *token, Utils::SString::size_type curPos) const
547
{
554
{
548
	bool found = false;
555
	bool found = false;
549
	Utils::String::size_type startPos = 0;
556
	Utils::SString::size_type startPos = 0;
550
	size_t max = strlen(token);
557
	size_t max = strlen(token);
551
	while ( !found ) {
558
	while ( !found ) {
552
		found = true;
559
		found = true;
553
		startPos = this->find_first_of(token[0], curPos);
560
		startPos = this->find_first_of(token[0], curPos);
554
		if ( startPos == Utils::String::npos ) {
561
		if ( startPos == Utils::SString::npos ) {
555
			startPos = this->length();
562
			startPos = this->length();
556
			break;
563
			break;
557
		}
564
		}
558

565

559
		Utils::String::size_type pos = startPos;
566
		Utils::SString::size_type pos = startPos;
560
		size_t i = 1;
567
		size_t i = 1;
561
		while ( i < max )
568
		while ( i < max )
562
		{
569
		{
563
			++pos;
570
			++pos;
564
			if ( this->at(pos) != token[i] )
571
			if ( this->at(pos) != token[i] )
Line 571... Line 578...
571
		curPos = pos;
578
		curPos = pos;
572
	}
579
	}
573
	return startPos;
580
	return startPos;
574
}
581
}
575

582

576
String String::findReplace(const String &find, const String &replace ) const
583
SString SString::findReplace(const SString &find, const SString &replace ) const
577
{
584
{
578
	Utils::String newstr = *this;
585
	Utils::SString newstr = *this;
579
	Utils::String::size_type pos = newstr.find(find, 0);
586
	Utils::SString::size_type pos = newstr.find(find, 0);
580
	while ( pos < Utils::String::npos ) {
587
	while ( pos < Utils::SString::npos ) {
581
		newstr.replace(pos, find.length(), replace);
588
		newstr.replace(pos, find.length(), replace);
582
		pos = newstr.find(find, pos + replace.length());
589
		pos = newstr.find(find, pos + replace.length());
583
	}
590
	}
584

591

585
	return newstr;
592
	return newstr;
586
}
593
}
587

594

588
String String::findRemove(const String &find) const
595
SString SString::findRemove(const SString &find) const
589
{
596
{
590
	Utils::String replace = *this;
597
	Utils::SString replace = *this;
591

598

592
	Utils::String::size_type pos = replace.find(find, 0 );
599
	Utils::SString::size_type pos = replace.find(find, 0 );
593
	while ( pos != Utils::String::npos ) {
600
	while ( pos != Utils::SString::npos ) {
594
		replace.erase ( pos, find.length() );
601
		replace.erase ( pos, find.length() );
595
		pos = replace.find(find, pos);
602
		pos = replace.find(find, pos);
596
	}
603
	}
597

604

598
	return replace;
605
	return replace;
599
}
606
}
600

607

601
String String::removeIf(int iChar, char c) const
608
SString SString::removeIf(int iChar, char c) const
602
{
609
{
603
	Utils::String newStr = *this;
610
	Utils::SString newStr = *this;
604
	if ( newStr.empty() ) return newStr;
611
	if ( newStr.empty() ) return newStr;
605
	if ( this->at(iChar) == c ) newStr.erase(iChar, 1);
612
	if ( this->at(iChar) == c ) newStr.erase(iChar, 1);
606
	return newStr;
613
	return newStr;
607
}
614
}
608

615

609
String String::stripHtml() const
616
SString SString::stripHtml() const
610
{
617
{
611
	// if empty, theres no to strip
618
	// if empty, theres no to strip
612
	if ( this->empty() ) return "";
619
	if ( this->empty() ) return "";
613

620

614
	// replace break line with a new line
621
	// replace break line with a new line
615
	Utils::String newStr = (*this);
622
	Utils::SString newStr = (*this);
616
	newStr = newStr.findReplace("<br/>", "\n");
623
	newStr = newStr.findReplace("<br/>", "\n");
617
	newStr = newStr.findReplace("<br />", "\n");
624
	newStr = newStr.findReplace("<br />", "\n");
618
	newStr = newStr.findReplace("<p>", "\n\t");
625
	newStr = newStr.findReplace("<p>", "\n\t");
619
	newStr = newStr.findReplace("</p>", "\n");
626
	newStr = newStr.findReplace("</p>", "\n");
620

627

621
	// find any remaining tags and remove them
628
	// find any remaining tags and remove them
622
	Utils::String::size_type pos     = newStr.find_first_of('<', 0);
629
	Utils::SString::size_type pos     = newStr.find_first_of('<', 0);
623
	Utils::String::size_type lastPos = newStr.find_first_of('>', pos);
630
	Utils::SString::size_type lastPos = newStr.find_first_of('>', pos);
624

631

625
	while (Utils::String::npos != pos || Utils::String::npos != lastPos)
632
	while (Utils::SString::npos != pos || Utils::SString::npos != lastPos)
626
	{
633
	{
627
		if ( lastPos > newStr.length() ) break;
634
		if ( lastPos > newStr.length() ) break;
628
		// remove the tag
635
		// remove the tag
629
		newStr.erase(pos, lastPos + 1);
636
		newStr.erase(pos, lastPos + 1);
630

637

Line 636... Line 643...
636
	// now remove all the starting new lines
643
	// now remove all the starting new lines
637
	while ( newStr[0] == '\n' || newStr[0] == '\t' ) newStr.erase(0, 1);
644
	while ( newStr[0] == '\n' || newStr[0] == '\t' ) newStr.erase(0, 1);
638
	return newStr;
645
	return newStr;
639
}
646
}
640

647

641
bool String::contains(const String &str, bool bCaseSensative) const
648
bool SString::contains(const SString &str, bool bCaseSensative) const
642
{
649
{
643
	if (bCaseSensative) return (this->find(str, 0) == Utils::String::npos) ? false : true;
650
	if (bCaseSensative) return (this->find(str, 0) == Utils::SString::npos) ? false : true;
644

651

645
	String thisLower = this->lower();
652
	SString thisLower = this->lower();
646
	String strLower = str.lower();
653
	SString strLower = str.lower();
647
	return (thisLower.find(strLower, 0) == Utils::String::npos) ? false : true;
654
	return (thisLower.find(strLower, 0) == Utils::SString::npos) ? false : true;
648
}
655
}
649
bool String::containsAny(const String &str, bool bCaseSensative) const
656
bool SString::containsAny(const SString &str, bool bCaseSensative) const
650
{
657
{
651
	char *c = (char *)str.c_str();
658
	char *c = (char *)str.c_str();
652
	while (*c != 0)
659
	while (*c != 0)
653
	{
660
	{
654
		char c1 = *c;
661
		char c1 = *c;
Line 657... Line 664...
657
		c++;
664
		c++;
658
	}
665
	}
659

666

660
	return false;
667
	return false;
661
}
668
}
662
bool String::isin(const String &str, bool bCaseSensative) const
669
bool SString::isin(const SString &str, bool bCaseSensative) const
663
{
670
{
664
	return contains(str, bCaseSensative);
671
	return contains(str, bCaseSensative);
665
}
672
}
666

673

667
int String::findPos(const String &find, int iStartPos) const
674
int SString::findPos(const SString &find, int iStartPos) const
668
{
675
{
669
	Utils::String::size_type pos = this->find(find, iStartPos);
676
	Utils::SString::size_type pos = this->find(find, iStartPos);
670
	if ( pos == Utils::String::npos ) return -1;
677
	if ( pos == Utils::SString::npos ) return -1;
671
	return pos;
678
	return pos;
672
}
679
}
673

680

674
bool String::isin(char c, bool bCaseSensative) const
681
bool SString::isin(char c, bool bCaseSensative) const
675
{
682
{
676
	return contains(c, bCaseSensative);
683
	return contains(c, bCaseSensative);
677
}
684
}
678
bool String::contains(char c, bool bCaseSensative) const
685
bool SString::contains(char c, bool bCaseSensative) const
679
{
686
{
680
	bool f = false;
687
	bool f = false;
681
	for ( unsigned int i = 0; i < this->length(); i++ )
688
	for ( unsigned int i = 0; i < this->length(); i++ )
682
	{
689
	{
683
		bool bCheck = (bCaseSensative) ? (this->at(i) == c) : (tolower(this->at(i)) == tolower(c));
690
		bool bCheck = (bCaseSensative) ? (this->at(i) == c) : (tolower(this->at(i)) == tolower(c));
Line 687... Line 694...
687
		}
694
		}
688
	}
695
	}
689
	return f;
696
	return f;
690
}
697
}
691

698

692
String String::between(const String &before, const String &after) const
699
SString SString::between(const SString &before, const SString &after) const
693
{
700
{
694
	int pos = this->findPos(before);
701
	int pos = this->findPos(before);
695
	if ( pos >= 0 ) {
702
	if ( pos >= 0 ) {
696
		pos += before.length();
703
		pos += before.length();
697
		int end = this->findPos(after, pos);
704
		int end = this->findPos(after, pos);
Line 699... Line 706...
699
	}
706
	}
700

707

701
	return "";
708
	return "";
702
}
709
}
703

710

704
String String::mid(int start, int end) const
711
SString SString::mid(int start, int end) const
705
{
712
{
706
	if (end <= 0)
713
	if (end <= 0)
707
		end = this->length() + end;
714
		end = this->length() + end;
708
	return this->substr(start, end - start);
715
	return this->substr(start, end - start);
709
}
716
}
710
String String::left(long num) const
717
SString SString::left(long num) const
711
{
718
{
712
	if ( num < 0 )
719
	if ( num < 0 )
713
		num = (long)this->length() + num;
720
		num = (long)this->length() + num;
714
	if ( num > (long)this->length() )
721
	if ( num > (long)this->length() )
715
		num = (long)this->length();
722
		num = (long)this->length();
716

723

717
	return this->substr(0, num);
724
	return this->substr(0, num);
718
}
725
}
719

726

720
String String::right(int num) const
727
SString SString::right(int num) const
721
{
728
{
722
	if ( num > 0 ) num -= (int)this->length();
729
	if ( num > 0 ) num -= (int)this->length();
723
	if ( num < -(int)this->length() ) num = -(int)this->length();
730
	if ( num < -(int)this->length() ) num = -(int)this->length();
724

731

725
	return this->substr(-num);
732
	return this->substr(-num);
726
}
733
}
727

734

728
const String &String::readToEndOfLine(FILE *id, int *line, bool upper)
735
const SString &SString::readToEndOfLine(FILE *id, int *line, bool upper)
729
{
736
{
730
	(*this) = "";
737
	(*this) = "";
731
	char c = fgetc ( id );
738
	char c = fgetc ( id );
732
	if ( c == -1 )
739
	if ( c == -1 )
733
		return (*this);
740
		return (*this);
Line 745... Line 752...
745
	//	ToUpper ();
752
	//	ToUpper ();
746

753

747
	return (*this);
754
	return (*this);
748
}
755
}
749

756

750
char *String::readToEndOfLine(char *data)
757
char *SString::readToEndOfLine(char *data)
751
{
758
{
752
	return (char *)this->readToEndOfLine((unsigned char *)data);
759
	return (char *)this->readToEndOfLine((unsigned char *)data);
753
}
760
}
754
unsigned char *String::readToEndOfLine(unsigned char *data)
761
unsigned char *SString::readToEndOfLine(unsigned char *data)
755
{
762
{
756
	int pos = 0;
763
	int pos = 0;
757

764

758
	// do until we get a line break
765
	// do until we get a line break
759
	while ( (data[pos] != 13) && (data[pos] != 0) && (data[pos] != '\n') ) {
766
	while ( (data[pos] != 13) && (data[pos] != 0) && (data[pos] != '\n') ) {
Line 781... Line 788...
781

788

782
	if ( data[pos] == 0 ) return NULL;
789
	if ( data[pos] == 0 ) return NULL;
783
	return data + (pos + 1);
790
	return data + (pos + 1);
784
}
791
}
785

792

786
String String::replaceToken(const char *token, int from, const String &replace) const
793
SString SString::replaceToken(const char *token, int from, const SString &replace) const
787
{
794
{
788
	Utils::String newstr;
795
	Utils::SString newstr;
789

796

790
	int whichtok = 1;
797
	int whichtok = 1;
791
	Utils::String::size_type lastPos = 0;
798
	Utils::SString::size_type lastPos = 0;
792
	Utils::String::size_type pos     = _token_nextPos(token, 0);
799
	Utils::SString::size_type pos     = _token_nextPos(token, 0);
793

800

794
	while (Utils::String::npos != pos || Utils::String::npos != lastPos)
801
	while (Utils::SString::npos != pos || Utils::SString::npos != lastPos)
795
	{
802
	{
796
		if ( whichtok == from )
803
		if ( whichtok == from )
797
		{
804
		{
798
			if ( newstr != "" ) newstr = newstr + token;
805
			if ( newstr != "" ) newstr = newstr + token;
799
			newstr = newstr + replace;
806
			newstr = newstr + replace;
800
		}
807
		}
801
		else
808
		else
802
		{
809
		{
803
			if ( newstr != "" ) newstr = newstr + token;
810
			if ( newstr != "" ) newstr = newstr + token;
804
			newstr = newstr + Utils::String(this->substr(lastPos, pos - lastPos));
811
			newstr = newstr + Utils::SString(this->substr(lastPos, pos - lastPos));
805
		}
812
		}
806

813

807
		// Found a token, add it to the vector.
814
		// Found a token, add it to the vector.
808
		whichtok++;
815
		whichtok++;
809

816

Line 825... Line 832...
825
	}
832
	}
826
	return newstr;
833
	return newstr;
827
}
834
}
828

835

829

836

830
String *String::tokenise(const char *token, int *max) const
837
SString *SString::tokenise(const char *token, int *max) const
831
{
838
{
832
	if ( empty() ) {
839
	if ( empty() ) {
833
		*max = 0;
840
		*max = 0;
834
		return NULL;
841
		return NULL;
835
	}
842
	}
Line 839... Line 846...
839
	if ( (*max) <= 0 ) {
846
	if ( (*max) <= 0 ) {
840
		*max = 0;
847
		*max = 0;
841
		return NULL;
848
		return NULL;
842
	}
849
	}
843

850

844
	String *newstr = (*max == 1) ? new String : new String[*max];
851
	SString *newstr = (*max == 1) ? new SString : new SString[*max];
845

852

846
	int whichtok = 0;
853
	int whichtok = 0;
847
	// get first token
854
	// get first token
848
	Utils::String::size_type lastPos = 0;
855
	Utils::SString::size_type lastPos = 0;
849
	Utils::String::size_type pos     = this->_token_nextPos(token, 0);
856
	Utils::SString::size_type pos     = this->_token_nextPos(token, 0);
850

857

851
	while (Utils::String::npos != pos || Utils::String::npos != lastPos)
858
	while (Utils::SString::npos != pos || Utils::SString::npos != lastPos)
852
	{
859
	{
853
		// set token
860
		// set token
854
		if ( *max == 1 ) *newstr = this->substr(lastPos, pos - lastPos);
861
		if ( *max == 1 ) *newstr = this->substr(lastPos, pos - lastPos);
855
		else			  newstr[whichtok] = this->substr(lastPos, pos - lastPos);
862
		else			  newstr[whichtok] = this->substr(lastPos, pos - lastPos);
856

863

Line 876... Line 883...
876
	}
883
	}
877

884

878
	return newstr;
885
	return newstr;
879
}
886
}
880

887

881
const String &String::removeChar(const char *cs)
888
const SString &SString::removeChar(const char *cs)
882
{
889
{
883
	char *current = const_cast<char *>(cs);
890
	char *current = const_cast<char *>(cs);
884
	while ( current[0] != '\0' ) {
891
	while ( current[0] != '\0' ) {
885
		removeChar(current[0]);
892
		removeChar(current[0]);
886
		++current;
893
		++current;
887
	}
894
	}
888

895

889
	return (*this);
896
	return (*this);
890
}
897
}
891

898

892
const String &String::removeChar(char c)
899
const SString &SString::removeChar(char c)
893
{
900
{
894
	Utils::String::size_type pos = this->find_first_of(c, 0);
901
	Utils::SString::size_type pos = this->find_first_of(c, 0);
895
	while(pos != Utils::String::npos) {
902
	while(pos != Utils::SString::npos) {
896
		this->erase(pos, 1);
903
		this->erase(pos, 1);
897
		pos = this->find_first_of(c, 0);
904
		pos = this->find_first_of(c, 0);
898
	}
905
	}
899

906

900
	return (*this);
907
	return (*this);
901
}
908
}
902

909

903
String String::remove(char c) const
910
SString SString::remove(char c) const
904
{
911
{
905
	String newStr = *this;
912
	SString newStr = *this;
906

913

907
	Utils::String::size_type pos = newStr.find_first_of(c, 0);
914
	Utils::SString::size_type pos = newStr.find_first_of(c, 0);
908
	while(pos != Utils::String::npos) {
915
	while(pos != Utils::SString::npos) {
909
		newStr.erase(pos, 1);
916
		newStr.erase(pos, 1);
910
		pos = newStr.find_first_of(c, 0);
917
		pos = newStr.find_first_of(c, 0);
911
	}
918
	}
912

919

913
	return newStr;
920
	return newStr;
914
}
921
}
915

922

916
bool String::_isCharNumber(char c) const
923
bool SString::_isCharNumber(char c) const
917
{
924
{
918
	return (c >= '0' && c <= '9') ? true : false;
925
	return (c >= '0' && c <= '9') ? true : false;
919
}
926
}
920

927

921
bool String::isCharNumber(int c) const
928
bool SString::isCharNumber(int c) const
922
{
929
{
923
	return _isCharNumber(this->at(c));
930
	return _isCharNumber(this->at(c));
924
}
931
}
925

932

926
bool String::isNumber(bool integer) const
933
bool SString::isNumber(bool integer) const
927
{
934
{
928
	bool foundpoint = integer;
935
	bool foundpoint = integer;
929
	for ( int i = 0; i < (int)this->length(); i++ )
936
	for ( int i = 0; i < (int)this->length(); i++ )
930
	{
937
	{
931
		// check for a decimal point (floating point value)
938
		// check for a decimal point (floating point value)
Line 935... Line 942...
935
		else if ( !this->isCharNumber(i) ) return false;
942
		else if ( !this->isCharNumber(i) ) return false;
936
	}
943
	}
937
	return true;
944
	return true;
938
}
945
}
939

946

940
const String &String::removeFirstSpace()
947
const SString &SString::removeFirstSpace()
941
{
948
{
942
	Utils::String::size_type pos = this->find_first_not_of(" \t\f\v\n\r", 0);
949
	Utils::SString::size_type pos = this->find_first_not_of(" \t\f\v\n\r", 0);
943
	if ( pos != Utils::String::npos ) {
950
	if ( pos != Utils::SString::npos ) {
944
		this->erase(0, pos);
951
		this->erase(0, pos);
945
	}
952
	}
946
	else
953
	else
947
		this->clear();
954
		this->clear();
948
	return (*this);
955
	return (*this);
949
}
956
}
950
const String &String::removeEndSpace()
957
const SString &SString::removeEndSpace()
951
{
958
{
952
	Utils::String::size_type pos = this->find_last_not_of(" \t\f\v\n\r");
959
	Utils::SString::size_type pos = this->find_last_not_of(" \t\f\v\n\r");
953
	if ( pos != Utils::String::npos ) {
960
	if ( pos != Utils::SString::npos ) {
954
		this->erase(pos + 1);
961
		this->erase(pos + 1);
955
	}
962
	}
956
	else
963
	else
957
		this->clear();
964
		this->clear();
958
	return (*this);
965
	return (*this);
959
}
966
}
960

967

961
const String &String::truncate(int iNum)
968
const SString &SString::truncate(int iNum)
962
{
969
{
963
	size_t pos = iNum;
970
	size_t pos = iNum;
964
	if ( iNum < 0 ) pos = this->length() + iNum;
971
	if ( iNum < 0 ) pos = this->length() + iNum;
965
	this->erase(pos, this->length() - pos);
972
	this->erase(pos, this->length() - pos);
966
	return (*this);
973
	return (*this);
967
}
974
}
968

975

969
String String::lower() const
976
SString SString::lower() const
970
{
977
{
971
	Utils::String newStr(*this);
978
	Utils::SString newStr(*this);
972
	std::transform(this->begin(), this->end(), newStr.begin(), tolower);
979
	std::transform(this->begin(), this->end(), newStr.begin(), tolower);
973
	return newStr;
980
	return newStr;
974
}
981
}
975

982

976
String String::upper() const
983
SString SString::upper() const
977
{
984
{
978
	Utils::String newStr(*this);
985
	Utils::SString newStr(*this);
979
	std::transform(this->begin(), this->end(), newStr.begin(), toupper);
986
	std::transform(this->begin(), this->end(), newStr.begin(), toupper);
980
	return newStr;
987
	return newStr;
981
}
988
}
982
const String &String::toLower()
989
const SString &SString::toLower()
983
{
990
{
984
	std::transform(this->begin(), this->end(), this->begin(), tolower);
991
	std::transform(this->begin(), this->end(), this->begin(), tolower);
985
	return (*this);
992
	return (*this);
986
}
993
}
987

994

988
const String &String::toUpper()
995
const SString &SString::toUpper()
989
{
996
{
990
	std::transform(this->begin(), this->end(), this->begin(), toupper);
997
	std::transform(this->begin(), this->end(), this->begin(), toupper);
991
	return (*this);
998
	return (*this);
992
}
999
}
993

1000

994
const String &String::toFilename()
1001
const SString &SString::toFilename()
995
{
1002
{
996
	(*this) = (*this).findReplace("\\", "/").findReplace("//", "/");
1003
	(*this) = (*this).findReplace("\\", "/").findReplace("//", "/");
997
	return (*this);
1004
	return (*this);
998
}
1005
}
999
String String::asFilename() const
1006
SString SString::asFilename() const
1000
{
1007
{
1001
	Utils::String sFile(*this);
1008
	Utils::SString sFile(*this);
1002
	return sFile.toFilename();
1009
	return sFile.toFilename();
1003
}
1010
}
1004

1011

1005
int String::compareVersion(const Utils::String &sV) const
1012
int SString::compareVersion(const Utils::SString &sV) const
1006
{
1013
{
1007
	Utils::String thisStr = (*this);
1014
	Utils::SString thisStr = (*this);
1008
	Utils::String checkStr = sV;
1015
	Utils::SString checkStr = sV;
1009

1016

1010
	int section = 1;
1017
	int section = 1;
1011

1018

1012
	// remove any rc/beta version
1019
	// remove any rc/beta version
1013
	int beta1 = 0;
1020
	int beta1 = 0;
Line 1032... Line 1039...
1032
	}
1039
	}
1033

1040

1034
	bool isDecimal = thisStr.countToken(".") == 2 && checkStr.countToken(".") == 2;
1041
	bool isDecimal = thisStr.countToken(".") == 2 && checkStr.countToken(".") == 2;
1035

1042

1036
	while ( true ) {
1043
	while ( true ) {
1037
		Utils::String sNum1 = thisStr.token(".", section);
1044
		Utils::SString sNum1 = thisStr.token(".", section);
1038
		Utils::String sNum2 = checkStr.token(".", section);
1045
		Utils::SString sNum2 = checkStr.token(".", section);
1039

1046

1040
		// no number nubmers, must be the same
1047
		// no number nubmers, must be the same
1041
		if ( sNum1.empty() && sNum2.empty() ) {
1048
		if ( sNum1.empty() && sNum2.empty() ) {
1042
			// compare the beta/rc version
1049
			// compare the beta/rc version
1043
			if ( beta1 == beta2 )
1050
			if ( beta1 == beta2 )
Line 1123... Line 1130...
1123
	}
1130
	}
1124

1131

1125
	return COMPARE_SAME;
1132
	return COMPARE_SAME;
1126
}
1133
}
1127

1134

1128
bool String::match(const Utils::String &pattern) const
1135
bool SString::match(const Utils::SString &pattern) const
1129
{
1136
{
1130
	enum State {
1137
	enum State {
1131
		Exact,      // exact match
1138
		Exact,      // exact match
1132
		Any,		// ?
1139
		Any,		// ?
1133
		AnyRepeat   // *
1140
		AnyRepeat   // *