From 854278e04a1343fd515caa0e4d007bc75ca6984b Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Wed, 22 Dec 2010 15:37:46 +0000 Subject: 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 --- .../kvs/kvi_kvs_treenode_specialcommandforeach.cpp | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src') 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 -- cgit v1.3.1-10-gc9f91