metaforce/Runtime/CStringExtras.hpp

32 lines
711 B
C++
Raw Normal View History

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
2018-12-08 05:30:43 +00:00
namespace urde {
2015-08-23 06:42:29 +00:00
2018-12-08 05:30:43 +00:00
class CStringExtras {
2015-08-23 06:42:29 +00:00
public:
2018-12-08 05:30:43 +00:00
static int CompareCaseInsensitive(const char* a, const char* b) {
2015-08-23 06:42:29 +00:00
#if _WIN32
2018-12-08 05:30:43 +00:00
return _stricmp(a, b);
2015-08-23 06:42:29 +00:00
#else
2018-12-08 05:30:43 +00:00
return strcasecmp(a, b);
2015-08-23 06:42:29 +00:00
#endif
2018-12-08 05:30:43 +00:00
}
static int CompareCaseInsensitive(std::string_view a, std::string_view b) {
return CompareCaseInsensitive(a.data(), b.data());
}
2017-01-15 03:07:01 +00:00
2018-12-08 05:30:43 +00:00
static int IndexOfSubstring(std::string_view haystack, std::string_view 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
};
2018-12-08 05:30:43 +00:00
} // namespace urde