--- trunk/OOPSE-4/src/utils/StringUtils.hpp 2005/02/01 22:49:23 1962 +++ trunk/OOPSE-4/src/utils/StringUtils.hpp 2008/07/30 18:11:19 3437 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -49,13 +49,13 @@ #ifndef UTILS_STRINGUTILS_HPP #define UTILS_STRINGUTILS_HPP #include +#include #include #include #include namespace oopse { - /** * Converts a string to UPPER CASE * @param S @@ -103,38 +103,76 @@ namespace oopse { */ int isEndLine(char *line); + bool CaseInsensitiveEquals(char ch1, char ch2); + size_t CaseInsensitiveFind(const std::string& str1, const std::string& str2); + + /** * Convert a variable to a string * @param T data type * @param v data to be converted * @return a string */ - template - std::string toString(const T& v) { - std::ostringstream oss; - if (!oss << v) { - std::cerr << "toString Error" << std::endl; - } - return oss.str(); + template + std::string toString(const T& v) { + std::ostringstream oss; + if (!oss << v) { + std::cerr << "toString Error" << std::endl; } + return oss.str(); + } + + template + T lexi_cast(const std::string& str) { + T result; + std::istringstream iss(str); + if (!(iss >> result)) { + std::cerr << "lexi_cast Error" << std::endl; + } + return result; + } - template - T lexi_cast(const std::string& str) { - T result; - std::istringstream iss; - if (iss >> result) { - std::cerr << "lexi_cast Error" << std::endl; - } - return result; + + template + bool isType(const std::string& str) { + T result; + std::istringstream iss(str); + bool ret = true; + if (!(iss >> result)) { + ret = false; } + return ret; + } - /**@todo need implementation */ - std::string getPrefix(const std::string& str); + bool isInteger(const std::string& str); + + std::string OOPSE_itoa(int value, unsigned int base = 10); + + /**@todo need implementation */ + std::string getPrefix(const std::string& str); + + /**@todo need implementation */ + std::string getSuffix(const std::string& str); + - /**@todo need implementation */ - std::string getSuffix(const std::string& str); - -} +template +std::string containerToString(const ContainerType& cont) { + std::ostringstream oss; + oss << "("; + typename ContainerType::const_iterator i = cont.begin(); + if (i != cont.end()) { + oss << *i; + ++i; + } + for (; i != cont.end();++i) { + oss << ", "; + oss << *i; + } + oss << ")"; + return oss.str(); +} + +} #endif