aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Fabio Bas2010-12-22 15:37:46 +0000
committerGravatar Fabio Bas2010-12-22 15:37:46 +0000
commit854278e04a1343fd515caa0e4d007bc75ca6984b (patch)
tree753dfbb0d39c9a24fe882d24213bbb1e7da0d1cf
parentadded proper localization for the logging button; regenrated translation files (diff)
downloadKVIrc-854278e04a1343fd515caa0e4d007bc75ca6984b.tar.gz
KVIrc-854278e04a1343fd515caa0e4d007bc75ca6984b.tar.bz2
KVIrc-854278e04a1343fd515caa0e4d007bc75ca6984b.zip
fixed "foreach": it was returning empty variables also when the "-a" switch was not present
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5220 17fca916-40b9-46aa-a4ea-0a15b648b75c
-rw-r--r--src/kvirc/kvs/kvi_kvs_treenode_specialcommandforeach.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/kvirc/kvs/kvi_kvs_treenode_specialcommandforeach.cpp b/src/kvirc/kvs/kvi_kvs_treenode_specialcommandforeach.cpp
index d5043c734..e317e71e9 100644
--- a/src/kvirc/kvs/kvi_kvs_treenode_specialcommandforeach.cpp
+++ b/src/kvirc/kvs/kvi_kvs_treenode_specialcommandforeach.cpp
@@ -97,9 +97,26 @@ bool KviKvsTreeNodeSpecialCommandForeach::execute(KviKvsRunTimeContext * c)
return false;
KviKvsVariant * pOne = pArg->array()->at(idx);
if(pOne)
- v->result()->copyFrom(*pOne);
- else
- v->result()->setNothing();
+ {
+ if(bIncludeEmptyScalars || (!pOne->isEqualToNothing()))
+ {
+ v->result()->copyFrom(*pOne);
+ } else {
+ delete v; // we're done with it for this iteration
+ idx++;
+ continue;
+ }
+ } else {
+ if(bIncludeEmptyScalars)
+ {
+ v->result()->setNothing();
+ } else {
+ delete v; // we're done with it for this iteration
+ idx++;
+ continue;
+ }
+
+ }
delete v; // we're done with it for this iteration
if(!m_pLoop->execute(c))
@@ -139,7 +156,15 @@ bool KviKvsTreeNodeSpecialCommandForeach::execute(KviKvsRunTimeContext * c)
KviKvsRWEvaluationResult * v = m_pIterationVariable->evaluateReadWrite(c);
if(!v)
return false;
- v->result()->copyFrom(*pOne);
+
+ if(bIncludeEmptyScalars || (!pOne->isEqualToNothing()))
+ {
+ v->result()->copyFrom(*pOne);
+ } else {
+ delete v; // we're done with it for this iteration
+ ++it;
+ continue;
+ }
delete v; // we're done with it for this iteration
if(!m_pLoop->execute(c))
@@ -169,7 +194,7 @@ bool KviKvsTreeNodeSpecialCommandForeach::execute(KviKvsRunTimeContext * c)
}
break;
default:
- if(bIncludeEmptyScalars || (!pArg->isNothing()))
+ if(bIncludeEmptyScalars || (!pArg->isEqualToNothing()))
{
// we evaluate this each time (as it may actually be killed at each iteration)
// FIXME: maybe some kind of reference counting or a observer pattern might be a bit more efficient here