From 61cbb8175621cb924b58889a4f9697cdac6b4331 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sat, 4 Jan 2014 18:50:55 +0200 Subject: [PATCH] Tweak EscapeRegExp() --- Library/ConfigParser.cpp | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 9ae50b8c..733644ae 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -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_first_of(L"\\^$|()[{.+*?", start)) != std::wstring::npos) { - size_t start = 0; - while ((start = str.find(reservedChar, 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'?'); + str.insert(start, L"\\"); + start += 2; + } } void ConfigParser::ResetMonitorVariables(MeterWindow* meterWindow)