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