diff options
-rw-r--r-- | src/FbTk/StringUtil.cc | 22 | ||||
-rw-r--r-- | src/FbTk/StringUtil.hh | 6 | ||||
-rw-r--r-- | src/Resources.cc | 28 |
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 | ||
126 | std::string number2String(int num) { | 126 | int extractNumber(const std::string& in, long& out) { |
127 | return ::extractSignedNumber<long>(in, out); | ||
128 | } | ||
129 | |||
130 | int extractNumber(const std::string& in, unsigned long& out) { | ||
131 | return ::extractUnsignedNumber<unsigned long>(in, out); | ||
132 | } | ||
133 | |||
134 | int extractNumber(const std::string& in, long long& out) { | ||
135 | return ::extractSignedNumber<long long>(in, out); | ||
136 | } | ||
137 | |||
138 | int extractNumber(const std::string& in, unsigned long long& out) { | ||
139 | return ::extractUnsignedNumber<unsigned long long>(in, out); | ||
140 | } | ||
141 | |||
142 | |||
143 | |||
144 | std::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' |
37 | int extractNumber(const std::string& in, unsigned int& out); | 37 | int extractNumber(const std::string& in, unsigned int& out); |
38 | int extractNumber(const std::string& in, int& out); | 38 | int extractNumber(const std::string& in, int& out); |
39 | int extractNumber(const std::string& in, unsigned long& out); | ||
40 | int extractNumber(const std::string& in, long& out); | ||
41 | int extractNumber(const std::string& in, long long& out); | ||
42 | int 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 |
42 | std::string number2String(int num); | 46 | std::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 |
45 | const char *strcasestr(const char *str, const char *ptn); | 49 | const 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 { | |||
51 | template<> | 51 | template<> |
52 | string FbTk::Resource<int>:: | 52 | string FbTk::Resource<int>:: |
53 | getString() const { | 53 | getString() const { |
54 | char strval[256]; | 54 | return FbTk::StringUtil::number2String(**this); |
55 | sprintf(strval, "%d", **this); | ||
56 | return string(strval); | ||
57 | } | 55 | } |
58 | 56 | ||
59 | template<> | 57 | template<> |
60 | void FbTk::Resource<int>:: | 58 | void FbTk::Resource<int>:: |
61 | setFromString(const char* strval) { | 59 | setFromString(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 | ||
67 | template<> | 63 | template<> |
@@ -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) { | |||
170 | template<> | 166 | template<> |
171 | string FbTk::Resource<unsigned int>:: | 167 | string FbTk::Resource<unsigned int>:: |
172 | getString() const { | 168 | getString() 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 | ||
178 | template<> | 172 | template<> |
179 | void FbTk::Resource<unsigned int>:: | 173 | void FbTk::Resource<unsigned int>:: |
180 | setFromString(const char *strval) { | 174 | setFromString(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) { | |||
186 | template<> | 180 | template<> |
187 | string FbTk::Resource<long long>:: | 181 | string FbTk::Resource<long long>:: |
188 | getString() const { | 182 | getString() 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 | ||
194 | template<> | 186 | template<> |
195 | void FbTk::Resource<long long>:: | 187 | void FbTk::Resource<long long>:: |
196 | setFromString(const char *strval) { | 188 | setFromString(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) { | |||
219 | template<> | 211 | template<> |
220 | string FbTk::Resource<long>:: | 212 | string FbTk::Resource<long>:: |
221 | getString() const { | 213 | getString() 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 | ||
227 | template<> | 217 | template<> |
228 | void FbTk::Resource<long>:: | 218 | void FbTk::Resource<long>:: |
229 | setFromString(const char *strval) { | 219 | setFromString(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 | ||