Subversion Repositories spk

Rev

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

Rev 121 Rev 126
Line 45... Line 45...
45
	std::stringstream strm;
45
	std::stringstream strm;
46
	strm << std::setw(iAmount) << std::setfill(cWith) << *this;
46
	strm << std::setw(iAmount) << std::setfill(cWith) << *this;
47
	*this = strm.str();
47
	*this = strm.str();
48
	return (*this);
48
	return (*this);
49
}
49
}
-
 
50

50

51

51
/////////////////////////////////////////////////////////////////
52
/////////////////////////////////////////////////////////////////
52
// Conversion functions
53
// Conversion functions
53

54

54
void String::fromLong(long l)
55
void String::fromLong(long l)
55
{
56
{
56
	std::stringstream strstream;
57
	std::stringstream strstream;
57
	strstream << l;
58
	strstream << l;
58
	*this = strstream.str();
59
	*this = strstream.str();
59
}
60
}
60

61

61
void String::fromFloat(float f, int dp)
62
const String &String::fromFloat(float f, int dp)
62
{
63
{
63
	std::stringstream strstream;
64
	std::stringstream strstream;
64
	if ( dp != -1 ) {
65
	if ( dp != -1 ) {
65
		strstream.precision(dp);
66
		strstream.precision(dp);
66
		strstream << std::fixed << f;
67
		strstream << std::fixed << f;
67
	}
68
	}
68
	else
69
	else
69
		strstream << f;
70
		strstream << f;
70
	*this = strstream.str();
71
	*this = strstream.str();
-
 
72
	return (*this);
71
}
73
}
72

74

73
void String::fromDouble(double f)
75
void String::fromDouble(double f)
74
{
76
{
75
	std::stringstream strstream;
77
	std::stringstream strstream;
76
	strstream << f;
78
	strstream << f;
77
	*this = strstream.str();
79
	*this = strstream.str();
78
}
80
}
79

81

80
const String &String::format(const char *sFormat, ...)
82
const String &String::format(const char *sFormat, ...)
81
{
83
{
82
	char buffer[1024];
84
	char buffer[1024];
83
	va_list args;
85
	va_list args;
84
	va_start (args, sFormat);
86
	va_start (args, sFormat);
85
	vsprintf (buffer, sFormat, args);
87
	vsprintf (buffer, sFormat, args);
86
	va_end (args);
88
	va_end (args);
87

89

88
	this->assign(buffer);
90
	this->assign(buffer);
89
	return (*this);
91
	return (*this);
90
}
92
}
91

93

92
const String &String::arg(const String &s1)
94
const String &String::arg(const String &s1)
93
{
95
{
94
	(*this) = this->findReplace("%1", s1);
96
	(*this) = this->findReplace("%1", s1);
95
	return (*this);
97
	return (*this);
96
}
98
}
97

99

98
const String &String::arg(const String &s1, const String &s2)
100
const String &String::arg(const String &s1, const String &s2)
99
{
101
{
100
	(*this) = this->arg(s1).findReplace("%2", s2);
102
	(*this) = this->arg(s1).findReplace("%2", s2);
101
	return (*this);
103
	return (*this);
102
}
104
}
103
const String &String::arg(const String &s1, const String &s2, const String &s3)
105
const String &String::arg(const String &s1, const String &s2, const String &s3)
104
{
106
{
105
	(*this) = this->arg(s1, s1).findReplace("%3", s3);
107
	(*this) = this->arg(s1, s1).findReplace("%3", s3);
106
	return (*this);
108
	return (*this);
107
}
109
}
108
const String &String::arg(const String &s1, const String &s2, const String &s3, const String &s4)
110
const String &String::arg(const String &s1, const String &s2, const String &s3, const String &s4)
109
{
111
{
110
	(*this) = this->arg(s1, s2, s3).findReplace("%4", s4);
112
	(*this) = this->arg(s1, s2, s3).findReplace("%4", s4);
111
	return (*this);
113
	return (*this);
112
}
114
}
113
const String &String::arg(const String &s1, const String &s2, const String &s3, const String &s4, const String &s5)
115
const String &String::arg(const String &s1, const String &s2, const String &s3, const String &s4, const String &s5)
114
{
116
{
115
	(*this) = this->arg(s1, s2, s3, s4).findReplace("%5", s5);
117
	(*this) = this->arg(s1, s2, s3, s4).findReplace("%5", s5);
116
	return (*this);
118
	return (*this);
Line 278... Line 280...
278
{
280
{
279
	return this->tokens(token, tok, tok);
281
	return this->tokens(token, tok, tok);
280
}
282
}
281

283

282
String String::tokens(const char *token, int from, int to) const
284
String String::tokens(const char *token, int from, int to) const
283
{
285
{
284
	if ( this->empty() ) return "";
286
	if ( this->empty() ) return "";
285
287
286
	int max = this->countToken(token);
288
	int max = this->countToken(token);
287
289
288
	Utils::String newstr;
290
	Utils::String newstr;
289
291
290
	int whichtok = 1;
292
	int whichtok = 1;
291
	Utils::String::size_type lastPos = 0;
293
	Utils::String::size_type lastPos = 0;
292
	Utils::String::size_type pos     = _token_nextPos(token, 0);
294
	Utils::String::size_type pos     = _token_nextPos(token, 0);
293

295

294
	if ( from < 0 )
296
	if ( from < 0 )
295
		from = max + (from + 1);
297
		from = max + (from + 1);
296
	if ( to < 0 )
298
	if ( to < 0 )
Line 382... Line 384...
382
}
384
}
383
String String::words(int from, int to) const
385
String String::words(int from, int to) const
384
{
386
{
385
	return this->tokens(" ", from, to);
387
	return this->tokens(" ", from, to);
386
}
388
}
-
 
389

-
 
390
String String::addToken(const char *token, const Utils::String &str) const
-
 
391
{
-
 
392
	if (this->empty())
-
 
393
		return str;
-
 
394

-
 
395
	Utils::String s = (*this);
-
 
396
	s += token;
-
 
397
	s += str;
-
 
398

-
 
399
	return s;
-
 
400
}
-
 
401

387
int String::countToken(const char *token) const
402
int String::countToken(const char *token) const
388
{
403
{
389
	if ( this->empty() )
404
	if ( this->empty() )
390
		return 0;
405
		return 0;
391

406

Line 466... Line 481...
466

481

467
	Utils::String::size_type pos = replace.find(find, 0 );
482
	Utils::String::size_type pos = replace.find(find, 0 );
468
	while ( pos != Utils::String::npos ) {
483
	while ( pos != Utils::String::npos ) {
469
		replace.erase ( pos, find.length() );
484
		replace.erase ( pos, find.length() );
470
		pos = replace.find(find, pos);
485
		pos = replace.find(find, pos);
471
	}
486
	}
472

487

473
	return replace;
488
	return replace;
474
}
489
}
475

490

476
String String::removeIf(int iChar, char c) const
491
String String::removeIf(int iChar, char c) const
Line 509... Line 524...
509
	}
524
	}
510

525

511
	// now remove all the starting new lines
526
	// now remove all the starting new lines
512
	while ( newStr[0] == '\n' || newStr[0] == '\t' ) newStr.erase(0, 1);
527
	while ( newStr[0] == '\n' || newStr[0] == '\t' ) newStr.erase(0, 1);
513
	return newStr;
528
	return newStr;
514
}
529
}
515
530
516
bool String::isin(const String &str, bool bCaseSensative) const
531
bool String::contains(const String &str, bool bCaseSensative) const
517
{
532
{
518
	if ( bCaseSensative ) return (this->find(str, 0) == Utils::String::npos) ? false : true;
533
	if (bCaseSensative) return (this->find(str, 0) == Utils::String::npos) ? false : true;
519
	
534
520
	String thisLower = this->lower();
535
	String thisLower = this->lower();
521
	String strLower = str.lower();
536
	String strLower = str.lower();
522
	return (thisLower.find(strLower, 0) == Utils::String::npos) ? false : true;
537
	return (thisLower.find(strLower, 0) == Utils::String::npos) ? false : true;
-
 
538
}
-
 
539
bool String::isin(const String &str, bool bCaseSensative) const
-
 
540
{
-
 
541
	return contains(str, bCaseSensative);
523
}
542
}
524

543

525
int String::findPos(const String &find, int iStartPos) const
544
int String::findPos(const String &find, int iStartPos) const
526
{
545
{
527
	Utils::String::size_type pos = this->find(find, iStartPos);
546
	Utils::String::size_type pos = this->find(find, iStartPos);
528
	if ( pos == Utils::String::npos ) return -1;
547
	if ( pos == Utils::String::npos ) return -1;
529
	return pos;
548
	return pos;
530
}
549
}
531

550

532
bool String::isin(char c, bool bCaseSensative) const
551
bool String::isin(char c, bool bCaseSensative) const
-
 
552
{
-
 
553
	return contains(c, bCaseSensative);
-
 
554
}
-
 
555
bool String::contains(char c, bool bCaseSensative) const
533
{
556
{
534
	bool f = false;
557
	bool f = false;
535
	for ( unsigned int i = 0; i < this->length(); i++ )
558
	for ( unsigned int i = 0; i < this->length(); i++ )
536
	{
559
	{
537
		bool bCheck = (bCaseSensative) ? (this->at(i) == c) : (tolower(this->at(i)) == tolower(c));
560
		bool bCheck = (bCaseSensative) ? (this->at(i) == c) : (tolower(this->at(i)) == tolower(c));