--- trunk/src/utils/StringUtils.cpp 2005/05/27 04:41:34 544 +++ trunk/src/utils/StringUtils.cpp 2008/10/16 18:17:41 1305 @@ -38,7 +38,8 @@ * University of Notre Dame has been advised of the possibility of * such damages. */ - + +#include #include "utils/StringUtils.hpp" namespace oopse { @@ -90,7 +91,7 @@ namespace oopse { return (str); } - int findBegin(std::istream &theStream, char* startText ){ + int findBegin(std::istream &theStream, const char* startText ){ const int MAXLEN = 1024; char readLine[MAXLEN]; int foundText = 0; @@ -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(); +} + +}