From bab251a7a16d81854f3ce733d7bcc92adf826996 Mon Sep 17 00:00:00 2001 From: louis Date: Sun, 18 Jan 2015 15:54:41 +0100 Subject: added empty operator additionally to isset to check in a condition if a string token is set --- libtemplate/parameter.c | 15 +++++++++++++++ libtemplate/parameter.h | 1 + 2 files changed, 16 insertions(+) (limited to 'libtemplate') 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 }; -- cgit v1.2.3