--- trunk/src/utils/StringUtils.cpp 2005/03/08 21:07:34 406 +++ trunk/src/utils/StringUtils.cpp 2006/08/30 18:42:29 1024 @@ -38,7 +38,8 @@ * University of Notre Dame has been advised of the possibility of * such damages. */ - + +#include #include "utils/StringUtils.hpp" namespace oopse { @@ -178,7 +179,7 @@ namespace oopse { return 0; } - std::string OOPSE_itoa(int value, unsigned int base = 10) { + std::string OOPSE_itoa(int value, unsigned int base) { const char digitMap[] = "0123456789abcdef"; std::string buf; @@ -217,4 +218,32 @@ namespace oopse { return str.substr(0, str.find('.')); } +bool isInteger(const std::string& str) { + + bool result = false; + + std::string::const_iterator i = str.begin(); + if (i != str.end() && (*i == '+' || *i == '-' || std::isdigit(*i) )) { + ++i; + while (i != str.end() && std::isdigit(*i)) + ++i; + if (i == str.end()) + result = true; + } + + return result; } + +bool CaseInsensitiveEquals(const char ch1, const char ch2) { + return std::toupper((unsigned char)ch1) == std::toupper((unsigned char)ch2); +} + +size_t CaseInsensitiveFind(const std::string& str1, const std::string& str2) { + std::string::const_iterator pos = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), CaseInsensitiveEquals); + if (pos == str1.end()) + return std::string::npos; + else + return pos - str1.begin(); +} + +}