Webparser plugin: Fix measure name case sensitivity comparing in URL option

This commit is contained in:
Brian Ferguson 2014-04-21 14:09:36 -06:00
parent 814098f0cd
commit 21fe43be63
2 changed files with 41 additions and 3 deletions

View File

@ -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

View File

@ -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;
}