Tweak EscapeRegExp()

This commit is contained in:
Birunthan Mohanathas 2014-01-04 18:50:55 +02:00
parent c31ecbfc83
commit 61cbb81756

View File

@ -379,33 +379,17 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
}
/*
** Used to escape regular expression metacharacters for use in IfMatch
** Escapes reserved PCRE regex metacharacters.
**
*/
void ConfigParser::EscapeRegExp(std::wstring& str)
{
auto replace = [&str](WCHAR reservedChar)
{
size_t start = 0;
while ((start = str.find(reservedChar, start)) != std::wstring::npos)
while ((start = str.find_first_of(L"\\^$|()[{.+*?", start)) != std::wstring::npos)
{
str.insert(start, L"\\");
start += 2;
}
};
replace(L'\\');
replace(L'^');
replace(L'$');
replace(L'|');
replace(L'(');
replace(L')');
replace(L'[');
replace(L'{');
replace(L'.');
replace(L'+');
replace(L'*');
replace(L'?');
}
void ConfigParser::ResetMonitorVariables(MeterWindow* meterWindow)