diff options
Diffstat (limited to 'src/FbTk/StringUtil.hh')
-rw-r--r-- | src/FbTk/StringUtil.hh | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh index 2f7c6fc..bfa3a5c 100644 --- a/src/FbTk/StringUtil.hh +++ b/src/FbTk/StringUtil.hh | |||
@@ -24,6 +24,12 @@ | |||
24 | 24 | ||
25 | #include <string> | 25 | #include <string> |
26 | 26 | ||
27 | #ifdef HAVE_CSTDLIB | ||
28 | #include <cstdlib> | ||
29 | #else | ||
30 | #include <stdlib.h> | ||
31 | #endif | ||
32 | |||
27 | namespace FbTk { | 33 | namespace FbTk { |
28 | 34 | ||
29 | namespace StringUtil { | 35 | namespace StringUtil { |
@@ -61,12 +67,12 @@ std::string findExtension(const std::string &filename); | |||
61 | /// @param found - position of found char in alphabet (optional) | 67 | /// @param found - position of found char in alphabet (optional) |
62 | /// @return position of trigger if found | 68 | /// @return position of trigger if found |
63 | /// @return std::string::npos if nothing found | 69 | /// @return std::string::npos if nothing found |
64 | std::string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, | 70 | std::string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, |
65 | char trigger, | 71 | char trigger, |
66 | const char alphabet[], size_t len_alphabet, size_t* found); | 72 | const char alphabet[], size_t len_alphabet, size_t* found); |
67 | 73 | ||
68 | /// @return copy of original with find_string replaced with "replace" | 74 | /// @return copy of original with find_string replaced with "replace" |
69 | std::string replaceString(const std::string &original, | 75 | std::string replaceString(const std::string &original, |
70 | const char *find_string, | 76 | const char *find_string, |
71 | const char *replace); | 77 | const char *replace); |
72 | 78 | ||
@@ -143,6 +149,31 @@ stringtok (Container &container, std::string const &in, | |||
143 | } | 149 | } |
144 | } | 150 | } |
145 | 151 | ||
152 | /// Parse token, which might be in formats as follows: <int>, <int>% or *. | ||
153 | /// @param relative - parsed relative value (percentage suffix) | ||
154 | /// @param ignore - this token should be ignored (asterisk) | ||
155 | /// @return parsed integer value or 0 if not applicable | ||
156 | template <typename Container> | ||
157 | static int | ||
158 | parseSizeToken(Container &container, bool &relative, bool &ignore) { | ||
159 | |||
160 | if (container.empty()) | ||
161 | return 0; | ||
162 | |||
163 | relative = false; | ||
164 | ignore = false; | ||
165 | |||
166 | if (container[0] == '*') { | ||
167 | ignore = true; | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | if (container[container.size() - 1] == '%') | ||
172 | relative = true; | ||
173 | |||
174 | return atoi(container.c_str()); | ||
175 | } | ||
176 | |||
146 | } // end namespace StringUtil | 177 | } // end namespace StringUtil |
147 | 178 | ||
148 | } // end namespace FbTk | 179 | } // end namespace FbTk |