# | Line 40 | Line 40 | |
---|---|---|
40 | */ | |
41 | ||
42 | #include <algorithm> | |
43 | + | #include <stdlib.h> |
44 | #include "utils/StringUtils.hpp" | |
45 | ||
46 | namespace OpenMD { | |
# | Line 217 | Line 218 | namespace OpenMD { | |
218 | std::string getSuffix(const std::string& str) { | |
219 | return str.substr(0, str.find('.')); | |
220 | } | |
221 | < | |
222 | < | bool isInteger(const std::string& str) { |
223 | < | |
221 | > | |
222 | > | bool isInteger(const std::string& str) { |
223 | > | |
224 | bool result = false; | |
225 | < | |
225 | > | |
226 | std::string::const_iterator i = str.begin(); | |
227 | if (i != str.end() && (*i == '+' || *i == '-' || std::isdigit(*i) )) { | |
228 | < | ++i; |
229 | < | while (i != str.end() && std::isdigit(*i)) |
230 | < | ++i; |
231 | < | if (i == str.end()) |
232 | < | result = true; |
228 | > | ++i; |
229 | > | while (i != str.end() && std::isdigit(*i)) |
230 | > | ++i; |
231 | > | if (i == str.end()) |
232 | > | result = true; |
233 | } | |
234 | ||
235 | return result; | |
236 | < | } |
236 | > | } |
237 | ||
238 | < | bool CaseInsensitiveEquals(const char ch1, const char ch2) { |
239 | < | return std::toupper((unsigned char)ch1) == std::toupper((unsigned char)ch2); |
240 | < | } |
241 | < | |
242 | < | size_t CaseInsensitiveFind(const std::string& str1, const std::string& str2) { |
243 | < | std::string::const_iterator pos = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), CaseInsensitiveEquals); |
244 | < | if (pos == str1.end()) |
245 | < | return std::string::npos; |
246 | < | else |
247 | < | return pos - str1.begin(); |
248 | < | } |
249 | < | |
238 | > | bool CaseInsensitiveEquals(const char ch1, const char ch2) { |
239 | > | return std::toupper((unsigned char)ch1) == std::toupper((unsigned char)ch2); |
240 | > | } |
241 | > | |
242 | > | size_t CaseInsensitiveFind(const std::string& str1, const std::string& str2) { |
243 | > | std::string::const_iterator pos = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), CaseInsensitiveEquals); |
244 | > | if (pos == str1.end()) |
245 | > | return std::string::npos; |
246 | > | else |
247 | > | return pos - str1.begin(); |
248 | > | } |
249 | > | |
250 | > | /** |
251 | > | * memparse - parse a string with mem suffixes into a number |
252 | > | * @ptr: Where parse begins |
253 | > | * @retptr: (output) Pointer to next char after parse completes |
254 | > | * |
255 | > | * Parses a string into a number. The number stored at @ptr is |
256 | > | * potentially suffixed with %K (for kilobytes, or 1024 bytes), |
257 | > | * %M (for megabytes, or 1048576 bytes), or %G (for gigabytes, or |
258 | > | * 1073741824). If the number is suffixed with K, M, or G, then |
259 | > | * the return value is the number multiplied by one kilobyte, one |
260 | > | * megabyte, or one gigabyte, respectively. |
261 | > | */ |
262 | > | unsigned long long memparse (char *ptr, char **retptr) { |
263 | > | unsigned long long ret = strtoull (ptr, retptr, 0); |
264 | > | |
265 | > | switch (**retptr) { |
266 | > | case 'G': |
267 | > | case 'g': |
268 | > | ret <<= 10; |
269 | > | case 'M': |
270 | > | case 'm': |
271 | > | ret <<= 10; |
272 | > | case 'K': |
273 | > | case 'k': |
274 | > | ret <<= 10; |
275 | > | (*retptr)++; |
276 | > | default: |
277 | > | break; |
278 | > | } |
279 | > | return ret; |
280 | > | } |
281 | > | |
282 | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |