mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Added [Measure:EscapeRegExp] section variable for measures. This will escape any regular expression meta-characters for use with IfMatch.
This commit is contained in:
parent
ee281be0c7
commit
957e37fbf2
@ -230,12 +230,14 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
|
|||||||
// Percentual: [Measure:%], [Measure:%, dec]
|
// Percentual: [Measure:%], [Measure:%, dec]
|
||||||
// Scale: [Measure:/scale], [Measure:/scale, dec]
|
// Scale: [Measure:/scale], [Measure:/scale, dec]
|
||||||
// Max/Min: [Measure:MaxValue], [Measure:MaxValue:/scale, dec] ('%' cannot be used)
|
// Max/Min: [Measure:MaxValue], [Measure:MaxValue:/scale, dec] ('%' cannot be used)
|
||||||
|
// EscapeRegExp: [Measure:EscapeRegExp] (Escapes regular expression syntax, used for 'IfMatch')
|
||||||
enum VALUETYPE
|
enum VALUETYPE
|
||||||
{
|
{
|
||||||
RAW = 0,
|
RAW = 0,
|
||||||
PERCENTUAL = 1,
|
PERCENTUAL = 1,
|
||||||
MAX = 2,
|
MAX = 2,
|
||||||
MIN = 3
|
MIN = 3,
|
||||||
|
SPECIAL = 4
|
||||||
} valueType = RAW;
|
} valueType = RAW;
|
||||||
|
|
||||||
if (isKeySelector)
|
if (isKeySelector)
|
||||||
@ -248,6 +250,10 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
|
|||||||
{
|
{
|
||||||
valueType = MIN;
|
valueType = MIN;
|
||||||
}
|
}
|
||||||
|
else if (_wcsicmp(selectorSz, L"EscapeRegExp") == 0)
|
||||||
|
{
|
||||||
|
valueType = SPECIAL;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -287,6 +293,19 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
|
|||||||
Measure* measure = m_MeterWindow->GetMeasure(strVariable);
|
Measure* measure = m_MeterWindow->GetMeasure(strVariable);
|
||||||
if (measure)
|
if (measure)
|
||||||
{
|
{
|
||||||
|
if (valueType == SPECIAL) // "Special" functions: EscapeRegExp
|
||||||
|
{
|
||||||
|
if (_wcsicmp(selector.c_str(), L"EscapeRegExp") == 0)
|
||||||
|
{
|
||||||
|
std::wstring str = measure->GetStringValue();
|
||||||
|
EscapeRegExp(str);
|
||||||
|
strValue.assign(str);
|
||||||
|
}
|
||||||
|
//else if (_wcsicmp(selector.c_str(), L"") == 0)
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int scale = 1;
|
int scale = 1;
|
||||||
|
|
||||||
const WCHAR* decimalsSz = wcschr(selectorSz, L',');
|
const WCHAR* decimalsSz = wcschr(selectorSz, L',');
|
||||||
@ -364,6 +383,36 @@ bool ConfigParser::GetSectionVariable(std::wstring& strVariable, std::wstring& s
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Used to escape regular expression metacharacters for use in IfMatch
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
void ConfigParser::EscapeRegExp(std::wstring& str)
|
||||||
|
{
|
||||||
|
auto replace = [&str](WCHAR reservedChar)
|
||||||
|
{
|
||||||
|
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'?');
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigParser::ResetMonitorVariables(MeterWindow* meterWindow)
|
void ConfigParser::ResetMonitorVariables(MeterWindow* meterWindow)
|
||||||
{
|
{
|
||||||
// Set the SCREENAREA/WORKAREA variables
|
// Set the SCREENAREA/WORKAREA variables
|
||||||
|
@ -110,6 +110,8 @@ private:
|
|||||||
|
|
||||||
bool GetSectionVariable(std::wstring& strVariable, std::wstring& strValue);
|
bool GetSectionVariable(std::wstring& strVariable, std::wstring& strValue);
|
||||||
|
|
||||||
|
void EscapeRegex(std::wstring& str);
|
||||||
|
|
||||||
static void SetVariable(std::unordered_map<std::wstring, std::wstring>& variables, const std::wstring& strVariable, const std::wstring& strValue);
|
static void SetVariable(std::unordered_map<std::wstring, std::wstring>& variables, const std::wstring& strVariable, const std::wstring& strValue);
|
||||||
static void SetVariable(std::unordered_map<std::wstring, std::wstring>& variables, const WCHAR* strVariable, const WCHAR* strValue);
|
static void SetVariable(std::unordered_map<std::wstring, std::wstring>& variables, const WCHAR* strVariable, const WCHAR* strValue);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user