Subversion Repositories spk

Rev

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

Rev 10 Rev 13
Line 2... Line 2...
2
 
2
 
3
#include <sstream>
3
#include <sstream>
4
#include <stdarg.h>
4
#include <stdarg.h>
5
 
5
 
6
namespace Utils {
6
namespace Utils {
-
 
7
 
-
 
8
String operator+(const char *str1, const String &str2)
-
 
9
{
-
 
10
	return String(str1) + str2;
-
 
11
}
-
 
12
 
7
 
13
 
8
String::String(void)						{ this->assign(""); }
14
String::String(void)						{ this->assign(""); }
9
String::String(const char *str)				{ this->assign(str); }
15
String::String(const char *str)				{ this->assign(str); }
10
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
16
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
11
String::String(const std::string &str)		{ this->assign(str);}
17
String::String(const std::string &str)		{ this->assign(str);}
Line 121... Line 127...
121
	strm << (*this) << l;
127
	strm << (*this) << l;
122
	strm >> (*this);
128
	strm >> (*this);
123
	return (*this); 
129
	return (*this); 
124
}
130
}
125
const String &String::operator+= ( const float f )		
131
const String &String::operator+= ( const float f )		
126
{ 
132
{ 
127
	std::stringstream strm;
133
	std::stringstream strm;
128
	strm << (*this) << f;
134
	strm << (*this) << f;
129
	strm >> (*this);
135
	strm >> (*this);
130
	return (*this); 
136
	return (*this); 
131
}
137
}
132
const String &String::operator+= ( const double f )		
138
const String &String::operator+= ( const double f )		
133
{ 
139
{ 
134
	std::stringstream strm;
140
	std::stringstream strm;
135
	strm << (*this) << f;
141
	strm << (*this) << f;
136
	strm >> (*this);
142
	strm >> (*this);
137
	return (*this); 
143
	return (*this); 
138
}
144
}
139
 
145
 
140
 
146
 
141
String String::operator+ ( const char *str ) const			{ return String(*this) += str; }
147
String String::operator+ ( const char *str ) const			{ return String(*this) += str; }
142
String String::operator+ ( const unsigned char *str ) const	{ return String(*this) += str; }
148
String String::operator+ ( const unsigned char *str ) const	{ return String(*this) += str; }
143
String String::operator+ ( const std::string &str ) const	{ return String(*this) += str; }
149
String String::operator+ ( const std::string &str ) const	{ return String(*this) += str; }
144
String String::operator+ ( const String &str ) const		{ return String(*this) += str; }
150
String String::operator+ ( const String &str ) const		{ return String(*this) += str; }
145
String String::operator+ ( const char c ) const				{ return String(*this) += c; }
151
String String::operator+ ( const char c ) const				{ return String(*this) += c; }
Line 156... Line 162...
156
 
162
 
157
bool String::operator!= ( const char *str ) const				{ return (this->compare(str)) ? true : false; }
163
bool String::operator!= ( const char *str ) const				{ return (this->compare(str)) ? true : false; }
158
bool String::operator!= ( const unsigned char *str ) const	{ return (this->compare((const char *)str)) ? true : false; }
164
bool String::operator!= ( const unsigned char *str ) const	{ return (this->compare((const char *)str)) ? true : false; }
159
bool String::operator!= ( const std::string &str ) const		{ return (this->compare(str)) ? true : false; }
165
bool String::operator!= ( const std::string &str ) const		{ return (this->compare(str)) ? true : false; }
160
bool String::operator!= ( const String &str ) const			{ return (this->compare(str)) ? true : false; }
166
bool String::operator!= ( const String &str ) const			{ return (this->compare(str)) ? true : false; }
161
 
-
 
162
String operator+(const char *str1, const String &str2)
-
 
163
{
-
 
164
	return String(str1) + str2;
-
 
165
}
-
 
166
 
167
 
167
bool String::Compare(const String &str, bool bCaseSensative) const
168
bool String::Compare(const String &str, bool bCaseSensative) const
168
{
169
{
169
	if ( bCaseSensative ) {
170
	if ( bCaseSensative ) {
170
		return (this->compare(str) == 0) ? true : false;
171
		return (this->compare(str) == 0) ? true : false;
Line 435... Line 436...
435
	*max = this->countToken(token);
436
	*max = this->countToken(token);
436
 
437
 
437
	if ( (*max) <= 0 ) {
438
	if ( (*max) <= 0 ) {
438
		*max = 0;
439
		*max = 0;
439
		return NULL;
440
		return NULL;
440
	}
441
	}
441
 
442
 
442
	String *newstr = (*max == 1) ? new String : new String[*max];
443
	String *newstr = (*max == 1) ? new String : new String[*max];
443
 
444
 
444
	int whichtok = 0;
445
	int whichtok = 0;
445
	// get first token
446
	// get first token
446
	std::string::size_type lastPos = 0;
447
	std::string::size_type lastPos = 0;
Line 475... Line 476...
475
 
476
 
476
	return newstr;
477
	return newstr;
477
}
478
}
478
 
479
 
479
const String &String::remove(char c)
480
const String &String::remove(char c)
480
{
481
{
481
	std::string::size_type pos = this->find_first_of(c, 0);
482
	std::string::size_type pos = this->find_first_of(c, 0);
482
	while(pos != std::string::npos) {
483
	while(pos != std::string::npos) {
483
		this->erase(pos, 1);
484
		this->erase(pos, 1);
484
		pos = this->find_first_of(c, 0);
485
		pos = this->find_first_of(c, 0);
485
	}
486
	}
Line 498... Line 499...
498
	}
499
	}
499
 
500
 
500
	return newStr;
501
	return newStr;
501
}
502
}
502
 
503
 
-
 
504
bool String::_isCharNumber(char c) const
-
 
505
{
-
 
506
	return (c >= '0' && c <= '9') ? true : false;
-
 
507
}
-
 
508
 
-
 
509
bool String::isCharNumber(int c) const
-
 
510
{
-
 
511
	return _isCharNumber(this->at(c));
-
 
512
}
-
 
513
 
-
 
514
bool String::isNumber(bool integer) const
-
 
515
{
-
 
516
	bool foundpoint = integer;
-
 
517
	for ( int i = 0; i < (int)this->length(); i++ )
-
 
518
	{
-
 
519
		// check for a decimal point (floating point value)
-
 
520
		// only allow 1 decimal point, or none if just checking for an integer
-
 
521
		if ( this->at(i) == '.' && !foundpoint ) foundpoint = true;
-
 
522
		// check if it is a number, 0-9
-
 
523
		else if ( !this->isCharNumber(i) ) return false;
-
 
524
	}
-
 
525
	return true;
-
 
526
}
503
}//NAMESPACE
527
}//NAMESPACE