2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2015-08-23 06:42:29 +00:00
|
|
|
|
|
|
|
#include <string>
|
2017-12-29 08:08:12 +00:00
|
|
|
#include <cstring>
|
2015-08-23 06:42:29 +00:00
|
|
|
|
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
|
|
|
|
}
|
2017-11-13 06:19:18 +00:00
|
|
|
static int CompareCaseInsensitive(std::string_view a, std::string_view b)
|
2015-08-23 06:42:29 +00:00
|
|
|
{
|
2017-11-13 06:19:18 +00:00
|
|
|
return CompareCaseInsensitive(a.data(), b.data());
|
2015-08-23 06:42:29 +00:00
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
static int IndexOfSubstring(std::string_view haystack, std::string_view needle)
|
2017-01-15 03:07:01 +00:00
|
|
|
{
|
2017-11-13 06:19:18 +00:00
|
|
|
std::string str(haystack);
|
2017-01-15 03:07:01 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|