diff --git a/HISTORY b/HISTORY index 44e268a..07d5dd0 100644 --- a/HISTORY +++ b/HISTORY @@ -156,3 +156,5 @@ Version 0.1.3 Version 0.1.4 - fixed token volpercent in nopacity and metrixhd +- added "empty" operator additionally to "isset" to check in a condition + if a string token is set diff --git a/libtemplate/parameter.c b/libtemplate/parameter.c index e3e48bd..b191d17 100644 --- a/libtemplate/parameter.c +++ b/libtemplate/parameter.c @@ -295,6 +295,19 @@ bool cConditionalParameter::Evaluate(map < string, int > *intTokens, map < strin tokenTrue = true; } } + } else if (cond->type == ctStringEmpty) { + if (stringTokens) { + map < string, string >::iterator hit = stringTokens->find(cond->tokenName); + if (hit != stringTokens->end()) { + string value = hit->second; + if (value.size() == 0) + tokenTrue = true; + } else { + tokenTrue = true; + } + } else { + tokenTrue = true; + } } else { int tokenValue = EvaluateParameter(cond->tokenName, intTokens, stringTokens); if (cond->type == ctBool) { @@ -387,6 +400,8 @@ void cConditionalParameter::InsertCondition(string cond) { sCond.isNegated = true; } else if (!rest.compare("isset")) { sCond.type = ctStringSet; + } else if (!rest.compare("empty")) { + sCond.type = ctStringEmpty; } else if (startswith(rest.c_str(), "gt(")) { string compVal = rest.substr(4, rest.size() - 5); sCond.compareValue = atoi(compVal.c_str()); diff --git a/libtemplate/parameter.h b/libtemplate/parameter.h index c055560..c92af28 100644 --- a/libtemplate/parameter.h +++ b/libtemplate/parameter.h @@ -109,6 +109,7 @@ enum eCondType { ctEquals, ctBool, ctStringSet, + ctStringEmpty, ctNone };