aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/FbTk/StringUtil.cc22
-rw-r--r--src/FbTk/StringUtil.hh6
-rw-r--r--src/Resources.cc28
3 files changed, 34 insertions, 22 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index 182233b..0a7ebd3 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -123,9 +123,27 @@ int extractNumber(const std::string& in, unsigned int& out) {
123 return ::extractUnsignedNumber<unsigned int>(in, out); 123 return ::extractUnsignedNumber<unsigned int>(in, out);
124} 124}
125 125
126std::string number2String(int num) { 126int extractNumber(const std::string& in, long& out) {
127 return ::extractSignedNumber<long>(in, out);
128}
129
130int extractNumber(const std::string& in, unsigned long& out) {
131 return ::extractUnsignedNumber<unsigned long>(in, out);
132}
133
134int extractNumber(const std::string& in, long long& out) {
135 return ::extractSignedNumber<long long>(in, out);
136}
137
138int extractNumber(const std::string& in, unsigned long long& out) {
139 return ::extractUnsignedNumber<unsigned long long>(in, out);
140}
141
142
143
144std::string number2String(long long num) {
127 char s[128]; 145 char s[128];
128 sprintf(s, "%d", num); 146 sprintf(s, "%lld", num);
129 return std::string(s); 147 return std::string(s);
130} 148}
131 149
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh
index a16e709..9e45460 100644
--- a/src/FbTk/StringUtil.hh
+++ b/src/FbTk/StringUtil.hh
@@ -36,10 +36,14 @@ namespace StringUtil {
36/// @return 1 - ok, result stored in 'out' 36/// @return 1 - ok, result stored in 'out'
37int extractNumber(const std::string& in, unsigned int& out); 37int extractNumber(const std::string& in, unsigned int& out);
38int extractNumber(const std::string& in, int& out); 38int extractNumber(const std::string& in, int& out);
39int extractNumber(const std::string& in, unsigned long& out);
40int extractNumber(const std::string& in, long& out);
41int extractNumber(const std::string& in, long long& out);
42int extractNumber(const std::string& in, unsigned long& out);
39/// \@} 43/// \@}
40 44
41/// creates a number to a string 45/// creates a number to a string
42std::string number2String(int num); 46std::string number2String(long long num);
43 47
44/// Similar to `strstr' but this function ignores the case of both strings 48/// Similar to `strstr' but this function ignores the case of both strings
45const char *strcasestr(const char *str, const char *ptn); 49const char *strcasestr(const char *str, const char *ptn);
diff --git a/src/Resources.cc b/src/Resources.cc
index 734cd75..0364477 100644
--- a/src/Resources.cc
+++ b/src/Resources.cc
@@ -51,17 +51,13 @@ namespace FbTk {
51template<> 51template<>
52string FbTk::Resource<int>:: 52string FbTk::Resource<int>::
53getString() const { 53getString() const {
54 char strval[256]; 54 return FbTk::StringUtil::number2String(**this);
55 sprintf(strval, "%d", **this);
56 return string(strval);
57} 55}
58 56
59template<> 57template<>
60void FbTk::Resource<int>:: 58void FbTk::Resource<int>::
61setFromString(const char* strval) { 59setFromString(const char* strval) {
62 int val; 60 FbTk::StringUtil::extractNumber(strval, get());
63 if (sscanf(strval, "%d", &val)==1)
64 *this = val;
65} 61}
66 62
67template<> 63template<>
@@ -142,7 +138,7 @@ setFromString(char const *strval) {
142 m_value.push_back(WinButton::SHADE); 138 m_value.push_back(WinButton::SHADE);
143 else if (v == "stick") 139 else if (v == "stick")
144 m_value.push_back(WinButton::STICK); 140 m_value.push_back(WinButton::STICK);
145 else if (v == "menuIcon") 141 else if (v == "menuicon")
146 m_value.push_back(WinButton::MENUICON); 142 m_value.push_back(WinButton::MENUICON);
147 else if (v == "close") 143 else if (v == "close")
148 m_value.push_back(WinButton::CLOSE); 144 m_value.push_back(WinButton::CLOSE);
@@ -170,15 +166,13 @@ setFromString(char const *strval) {
170template<> 166template<>
171string FbTk::Resource<unsigned int>:: 167string FbTk::Resource<unsigned int>::
172getString() const { 168getString() const {
173 char tmpstr[128]; 169 return FbTk::StringUtil::number2String(m_value);
174 sprintf(tmpstr, "%ul", m_value);
175 return string(tmpstr);
176} 170}
177 171
178template<> 172template<>
179void FbTk::Resource<unsigned int>:: 173void FbTk::Resource<unsigned int>::
180setFromString(const char *strval) { 174setFromString(const char *strval) {
181 if (sscanf(strval, "%ul", &m_value) != 1) 175 if (!FbTk::StringUtil::extractNumber(strval, m_value))
182 setDefaultValue(); 176 setDefaultValue();
183} 177}
184 178
@@ -186,15 +180,13 @@ setFromString(const char *strval) {
186template<> 180template<>
187string FbTk::Resource<long long>:: 181string FbTk::Resource<long long>::
188getString() const { 182getString() const {
189 char tmpstr[128]; 183 return FbTk::StringUtil::number2String(m_value);
190 sprintf(tmpstr, "%llu", (unsigned long long) m_value);
191 return string(tmpstr);
192} 184}
193 185
194template<> 186template<>
195void FbTk::Resource<long long>:: 187void FbTk::Resource<long long>::
196setFromString(const char *strval) { 188setFromString(const char *strval) {
197 if (sscanf(strval, "%lld", &m_value) != 1) 189 if (!FbTk::StringUtil::extractNumber(strval, m_value))
198 setDefaultValue(); 190 setDefaultValue();
199} 191}
200 192
@@ -219,15 +211,13 @@ setFromString(const char *strval) {
219template<> 211template<>
220string FbTk::Resource<long>:: 212string FbTk::Resource<long>::
221getString() const { 213getString() const {
222 char tmpstr[128]; 214 return FbTk::StringUtil::number2String(m_value);
223 sprintf(tmpstr, "%ld", m_value);
224 return string(tmpstr);
225} 215}
226 216
227template<> 217template<>
228void FbTk::Resource<long>:: 218void FbTk::Resource<long>::
229setFromString(const char *strval) { 219setFromString(const char *strval) {
230 if (sscanf(strval, "%ld", &m_value) != 1) 220 if (!FbTk::StringUtil::extractNumber(strval, m_value))
231 setDefaultValue(); 221 setDefaultValue();
232} 222}
233 223