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:
parent
814098f0cd
commit
21fe43be63
@ -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
|
||||
|
@ -999,7 +999,8 @@ void ParseData(MeasureData* measure, LPCSTR parseData, DWORD dwSize)
|
||||
for ( ; i != g_Measures.end(); ++i)
|
||||
{
|
||||
if (measure->skin == (*i)->skin &&
|
||||
(*i)->url.find(compareStr) != std::wstring::npos)
|
||||
//(*i)->url.find(compareStr) != std::wstring::npos)
|
||||
StringUtil::CaseInsensitiveFind((*i)->url, compareStr) != std::wstring::npos)
|
||||
{
|
||||
if ((*i)->stringIndex < rc)
|
||||
{
|
||||
@ -1022,7 +1023,10 @@ void ParseData(MeasureData* measure, LPCSTR parseData, DWORD dwSize)
|
||||
// Substitude the [measure] with result
|
||||
std::wstring result = StringUtil::WidenUTF8(substring_start, substring_length);
|
||||
(*i)->resultString = (*i)->url;
|
||||
(*i)->resultString.replace((*i)->resultString.find(compareStr), compareStr.size(), result);
|
||||
(*i)->resultString.replace(
|
||||
StringUtil::CaseInsensitiveFind((*i)->resultString, compareStr),
|
||||
//(*i)->resultString.find(compareStr),
|
||||
compareStr.size(), result);
|
||||
DecodeReferences((*i)->resultString, (*i)->decodeCharacterReference);
|
||||
|
||||
// Start download threads for the references
|
||||
@ -1080,7 +1084,7 @@ void ParseData(MeasureData* measure, LPCSTR parseData, DWORD dwSize)
|
||||
compareStr += L']';
|
||||
for ( ; i != g_Measures.end(); ++i)
|
||||
{
|
||||
if (((*i)->url.find(compareStr) != std::wstring::npos) && (measure->skin == (*i)->skin))
|
||||
if ((/*(*i)->url.find(compareStr)*/StringUtil::CaseInsensitiveFind((*i)->url, compareStr) != std::wstring::npos) && (measure->skin == (*i)->skin))
|
||||
{
|
||||
(*i)->resultString = (*i)->errorString;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user