Subversion Repositories spk

Rev

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

Rev 13 Rev 14
Line 14... Line 14...
14
String::String(void)						{ this->assign(""); }
14
String::String(void)						{ this->assign(""); }
15
String::String(const char *str)				{ this->assign(str); }
15
String::String(const char *str)				{ this->assign(str); }
16
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
16
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
17
String::String(const std::string &str)		{ this->assign(str);}
17
String::String(const std::string &str)		{ this->assign(str);}
18
String::String(const unsigned char c)		{ this->assign(1, c); }
18
String::String(const unsigned char c)		{ this->assign(1, c); }
-
 
19
String::String(const char c)				{ this->assign(1, c); }
19
String::String(const String &str)			{ this->assign(str); }
20
String::String(const String &str)			{ this->assign(str); }
20
String::String(long l)						{ this->fromLong(l); }
21
String::String(long l)						{ this->fromLong(l); }
21
String::String(unsigned long l)				{ this->fromLong((long)l); }
22
String::String(unsigned long l)				{ this->fromLong((long)l); }
22
String::String(float f)						{ this->fromFloat(f); }
23
String::String(float f)						{ this->fromFloat(f); }
23
String::String(double f)					{ this->fromDouble(f); }
24
String::String(double f)					{ this->fromDouble(f); }
Line 31... Line 32...
31
 
32
 
32
void String::fromLong(long l)
33
void String::fromLong(long l)
33
{
34
{
34
	std::stringstream strstream;
35
	std::stringstream strstream;
35
	strstream << l;
36
	strstream << l;
36
	strstream >> *this;
37
	*this = strstream.str();
37
}
38
}
38
 
39
 
39
void String::fromFloat(float f, int dp)
40
void String::fromFloat(float f, int dp)
40
{
41
{
41
	std::stringstream strstream;
42
	std::stringstream strstream;
42
	strstream.precision(dp);
43
	strstream.precision(dp);
43
	strstream << std::fixed << f;
44
	strstream << std::fixed << f;
44
	strstream >> *this;
45
	*this = strstream.str();
45
}
46
}
46
 
47
 
47
void String::fromFloat(float f)
48
void String::fromFloat(float f)
48
{
49
{
49
	std::stringstream strstream;
50
	std::stringstream strstream;
50
	strstream << f;
51
	strstream << f;
51
	strstream >> *this;
52
	*this = strstream.str();
52
}
53
}
53
void String::fromDouble(double f)
54
void String::fromDouble(double f)
54
{
55
{
55
	std::stringstream strstream;
56
	std::stringstream strstream;
56
	strstream << f;
57
	strstream << f;
57
	strstream >> *this;
58
	*this = strstream.str();
58
}
59
}
59
 
60
 
60
const String &String::format(const char *sFormat, ...)
61
const String &String::format(const char *sFormat, ...)
61
{
62
{
62
	char buffer[1024];
63
	char buffer[1024];
Line 123... Line 124...
123
}
124
}
124
const String &String::operator+= ( const long l )		
125
const String &String::operator+= ( const long l )		
125
{ 
126
{ 
126
	std::stringstream strm;
127
	std::stringstream strm;
127
	strm << (*this) << l;
128
	strm << (*this) << l;
128
	strm >> (*this);
129
	*this = strm.str();
129
	return (*this); 
130
	return (*this); 
130
}
131
}
131
const String &String::operator+= ( const float f )		
132
const String &String::operator+= ( const float f )		
132
{ 
133
{ 
133
	std::stringstream strm;
134
	std::stringstream strm;
134
	strm << (*this) << f;
135
	strm << (*this) << f;
135
	strm >> (*this);
136
	*this = strm.str();
136
	return (*this); 
137
	return (*this); 
137
}
138
}
138
const String &String::operator+= ( const double f )		
139
const String &String::operator+= ( const double f )		
139
{ 
140
{ 
140
	std::stringstream strm;
141
	std::stringstream strm;
141
	strm << (*this) << f;
142
	strm << (*this) << f;
142
	strm >> (*this);
143
	*this = strm.str();
143
	return (*this); 
144
	return (*this); 
144
}
145
}
145
 
146
 
146
 
147
 
147
String String::operator+ ( const char *str ) const			{ return String(*this) += str; }
148
String String::operator+ ( const char *str ) const			{ return String(*this) += str; }
Line 424... Line 425...
424
 
425
 
425
	if ( data[pos] == 0 ) return NULL;
426
	if ( data[pos] == 0 ) return NULL;
426
	return data + (pos + 1);
427
	return data + (pos + 1);
427
}
428
}
428
 
429
 
-
 
430
String String::replaceToken(const char *token, int from, const String &replace) const
-
 
431
{
-
 
432
	std::string newstr;
-
 
433
 
-
 
434
	int whichtok = 1;
-
 
435
	std::string::size_type lastPos = 0;
-
 
436
	std::string::size_type pos     = _token_nextPos(token, 0);
-
 
437
 
-
 
438
	while (std::string::npos != pos || std::string::npos != lastPos)
-
 
439
	{
-
 
440
		if ( whichtok == from )
-
 
441
		{
-
 
442
			if ( newstr != "" ) newstr = newstr + token;
-
 
443
			newstr = newstr + replace;
-
 
444
		}
-
 
445
		else
-
 
446
		{
-
 
447
			if ( newstr != "" ) newstr = newstr + token;
-
 
448
			newstr = newstr + this->substr(lastPos, pos - lastPos);
-
 
449
		}
-
 
450
 
-
 
451
		// Found a token, add it to the vector.
-
 
452
		whichtok++;
-
 
453
 
-
 
454
		if ( pos >= this->length() )
-
 
455
			break;
-
 
456
 
-
 
457
		// skip past token
-
 
458
		size_t i = 0;
-
 
459
		size_t max = strlen(token);
-
 
460
		lastPos = pos;
-
 
461
		while ( (i < max) && (token[i] == this->at(lastPos)) )
-
 
462
		{
-
 
463
			++i;
-
 
464
			++lastPos;
-
 
465
		}
-
 
466
 
-
 
467
		// get the next token
-
 
468
		pos = _token_nextPos(token, lastPos);
-
 
469
	}
-
 
470
	return newstr;
-
 
471
}
-
 
472
 
-
 
473
 
429
String *String::tokenise(const char *token, int *max) const
474
String *String::tokenise(const char *token, int *max) const
430
{
475
{
431
	if ( empty() ) {
476
	if ( empty() ) {
432
		*max = 0;
477
		*max = 0;
433
		return NULL;
478
		return NULL;
Line 522... Line 567...
522
		// check if it is a number, 0-9
567
		// check if it is a number, 0-9
523
		else if ( !this->isCharNumber(i) ) return false;
568
		else if ( !this->isCharNumber(i) ) return false;
524
	}
569
	}
525
	return true;
570
	return true;
526
}
571
}
-
 
572
 
-
 
573
const String &String::removeFirstSpace()
-
 
574
{
-
 
575
	std::string::size_type pos = this->find_first_not_of(" ", 0);
-
 
576
	if ( pos != std::string::npos ) {
-
 
577
		this->erase(0, pos);
-
 
578
	}
-
 
579
	return (*this);
-
 
580
}
-
 
581
 
527
}//NAMESPACE
582
}//NAMESPACE