2016-04-13 06:07:23 +00:00
|
|
|
#ifndef __URDE_CSTRINGEXTRAS_HPP__
|
|
|
|
#define __URDE_CSTRINGEXTRAS_HPP__
|
2015-08-23 06:42:29 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-23 06:42:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
class CStringExtras
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static int CompareCaseInsensitive(const char* a, const char* b)
|
|
|
|
{
|
|
|
|
#if _WIN32
|
|
|
|
return _stricmp(a, b);
|
|
|
|
#else
|
|
|
|
return strcasecmp(a, b);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
static int CompareCaseInsensitive(const std::string& a, const std::string& b)
|
|
|
|
{
|
|
|
|
return CompareCaseInsensitive(a.c_str(), b.c_str());
|
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
|
|
|
static int IndexOfSubstring(const std::string& haystack, const std::string& needle)
|
|
|
|
{
|
|
|
|
std::string str = haystack;
|
|
|
|
std::transform(str.begin(), str.end(), str.begin(), tolower);
|
|
|
|
std::string::size_type s = str.find(needle);
|
|
|
|
if (s == std::string::npos)
|
|
|
|
return -1;
|
|
|
|
return s;
|
|
|
|
}
|
2015-08-23 06:42:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-13 06:07:23 +00:00
|
|
|
#endif // __URDE_CSTRINGEXTRAS_HPP__
|