Subversion Repositories spk

Rev

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

Rev 127 Rev 130
Line 9... Line 9...
9

9

10
String operator+(const char *str1, const String &str2)
10
String operator+(const char *str1, const String &str2)
11
{
11
{
12
	return String(str1) + str2;
12
	return String(str1) + str2;
13
}
13
}
14

-
 
15

14

16
String::String(void)						{ this->assign(""); }
15
String::String(void)						{ this->assign(""); }
17
String::String(const char *str)				{ this->assign(str); }
16
String::String(const char *str)				{ this->assign(str); }
18
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
17
String::String(const unsigned char *str)	{ this->assign((const char *)str); }
19
String::String(const std::string &str)		{ this->assign(str);}
18
String::String(const std::string &str)		{ this->assign(str);}
Line 39... Line 38...
39
{
38
{
40
	return this->pad(iAmount, '0');
39
	return this->pad(iAmount, '0');
41
}
40
}
42

41

43
const String &String::pad(int iAmount, char cWith)
42
const String &String::pad(int iAmount, char cWith)
44
{
43
{
45
	std::stringstream strm;
44
	std::stringstream strm;
46
	strm << std::setw(iAmount) << std::setfill(cWith) << *this;
45
	strm << std::setw(iAmount) << std::setfill(cWith) << *this;
47
	*this = strm.str();
46
	*this = strm.str();
48
	return (*this);
47
	return (*this);
49
}
48
}
50

49

51
50
52
/////////////////////////////////////////////////////////////////
51
/////////////////////////////////////////////////////////////////
53
// Conversion functions
52
// Conversion functions
54
53
55
void String::fromLong(long l)
54
void String::fromLong(long l)
56
{
55
{
57
	std::stringstream strstream;
56
	std::stringstream strstream;
58
	strstream << l;
57
	strstream << l;
59
	*this = strstream.str();
58
	*this = strstream.str();
60
}
59
}
61

60

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

-
 
81
const String &String::fromDouble(double f, int dp)
-
 
82
{
-
 
83
	std::stringstream strstream;
-
 
84
	if (dp != -1) {
-
 
85
		strstream.precision(dp);
-
 
86
		strstream << std::fixed << f;
-
 
87
	}
-
 
88
	else
-
 
89
		strstream << f;
79
	*this = strstream.str();
90
	*this = strstream.str();
-
 
91
	return (*this);
80
}
92
}
81

93

82
const String &String::format(const char *sFormat, ...)
94
const String &String::format(const char *sFormat, ...)
83
{
95
{
84
	char buffer[1024];
96
	char buffer[1024];
Line 89... Line 101...
89

101

90
	this->assign(buffer);
102
	this->assign(buffer);
91
	return (*this);
103
	return (*this);
92
}
104
}
93

105

-
 
106
const String String::args(const String *args, int max) const
-
 
107
{
-
 
108
	Utils::String str = (*this);
-
 
109
	for (int i = 0; i < max; i++)
-
 
110
	{
-
 
111
		Utils::String find("%");
-
 
112
		find += Utils::String::Number(i + 1);
-
 
113

-
 
114
		str = str.findReplace(find, args[i]);
-
 
115
	}
-
 
116

-
 
117
	return str;
-
 
118
}
94
const String &String::arg(const String &s1)
119
const String &String::arg(const String &s1)
95
{
120
{
96
	(*this) = this->findReplace("%1", s1);
121
	(*this) = this->findReplace("%1", s1);
97
	return (*this);
122
	return (*this);
98
}
123
}