mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Webparser plugin: Fix measure name case sensitivity comparing in URL option
This commit is contained in:
@ -20,8 +20,23 @@
|
||||
#define RM_COMMON_STRINGUTIL_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
** Helper class for case insensitive find function.
|
||||
*/
|
||||
template<typename CharT>
|
||||
struct Is_Equal
|
||||
{
|
||||
Is_Equal(const std::locale& loc) : locale(loc) { }
|
||||
bool operator()(CharT ch1, CharT ch2) { return std::toupper(ch1, locale) == std::toupper(ch2, locale); }
|
||||
|
||||
private:
|
||||
const std::locale& locale;
|
||||
};
|
||||
|
||||
namespace StringUtil {
|
||||
|
||||
std::string Narrow(const WCHAR* str, int strLen = -1, int cp = CP_ACP);
|
||||
@ -40,6 +55,25 @@ void EscapeRegExp(std::wstring& str);
|
||||
|
||||
void EncodeUrl(std::wstring& str);
|
||||
|
||||
|
||||
/*
|
||||
** Case insensitive find function for std::string and std::wstring.
|
||||
**
|
||||
** Modified from http://stackoverflow.com/questions/3152241/case-insensitive-stdstring-find#3152296
|
||||
*/
|
||||
template<typename T>
|
||||
std::size_t CaseInsensitiveFind(const T& str1, const T& str2, const std::locale& loc = std::locale())
|
||||
{
|
||||
T::const_iterator iter = std::search(str1.begin(), str1.end(),
|
||||
str2.begin(), str2.end(), Is_Equal<T::value_type>(loc));
|
||||
|
||||
if (iter != str1.end())
|
||||
{
|
||||
return (iter - str1.begin());
|
||||
}
|
||||
|
||||
return -1; // not found
|
||||
}
|
||||
} // namespace StringUtil
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user