32 #ifndef TBX_STRINGUTILS_H_
33 #define TBX_STRINGUTILS_H_
44 template<
class T> std::string
to_string(
const T &value)
46 std::ostringstream ss;
52 inline std::string
to_string(
const std::string &value)
60 return std::string(value);
66 return std::string(value);
75 std::istringstream ss(str);
83 inline std::string
to_upper(
const std::string &value)
86 for (std::string::const_iterator i = value.begin(); i != value.end(); ++i)
88 result += std::toupper(*i);
96 inline std::string
to_lower(
const std::string &value)
99 for (std::string::const_iterator i = value.begin(); i != value.end(); ++i)
101 result += std::tolower(*i);
111 if (s1.length() != s2.length())
return false;
112 std::string::const_iterator i1, i2 = s2.begin();
113 for (i1 = s1.begin(); i1 != s1.end(); ++i1, ++i2)
114 if (std::tolower(*i1) != std::tolower(*i2))
return false;
123 return (stricmp(s1.c_str(), cs2) == 0);
139 return (stricmp(cs1, cs2) == 0);
151 return stricmp(cs1,cs2);
163 return stricmp(s1.c_str(),cs2);
175 return stricmp(cs1,s2.c_str());
186 return stricmp(s1.c_str(),s2.c_str());
198 inline std::string::size_type
find_ignore_case(
const std::string &s, std::string f, std::string::size_type start = 0)
200 if (f.empty())
return std::string::npos;
201 if (s.length() < f.length())
return std::string::npos;
203 std::string::size_type pos;
204 std::string::size_type max_pos = s.length() - f.length();
207 fchar[0] = std::tolower(f[0]);
208 fchar[1] = std::toupper(f[0]);
210 while ((pos = s.find_first_of(fchar, start))!=std::string::npos)
212 if (pos > max_pos)
return std::string::npos;
214 for (std::string::size_type i = 1; i < f.length() && found; i++)
215 found = (std::tolower(s[pos+i]) == std::tolower(f[i]));
216 if (found)
return pos;
220 return std::string::npos;