not part of default build; PathExpr did wrong for //; code by sicking, r=me, sr=shaver, bug 75307

This commit is contained in:
axel%pike.org 2001-04-14 17:24:59 +00:00
Родитель b5d880087c
Коммит b8afba4946
2 изменённых файлов: 45 добавлений и 35 удалений

Просмотреть файл

@ -25,7 +25,7 @@
* - changed constant short declarations in many of the classes
* with enumerations, commented with //--LF
*
* $Id: Expr.h,v 1.11 2001-04-11 15:00:57 axel%pike.org Exp $
* $Id: Expr.h,v 1.12 2001-04-14 17:24:59 axel%pike.org Exp $
*/
@ -46,7 +46,7 @@
/*
XPath class definitions.
Much of this code was ported from XSL:P.
@version $Revision: 1.11 $ $Date: 2001-04-11 15:00:57 $
@version $Revision: 1.12 $ $Date: 2001-04-14 17:24:59 $
*/
//necessary prototypes
@ -1430,7 +1430,7 @@ private:
* all nodes that match the PatternExpr
* -- this will be moving to a Utility class
**/
void fromDescendants(PatternExpr* pExpr,
void evalDescendants(PatternExpr* pExpr,
Node* context,
ContextState* cs,
NodeSet* nodes);

Просмотреть файл

@ -29,10 +29,11 @@
* - foo//bar would not match properly if there was more than
* one node in the NodeSet (nodes) on the final iteration
*
* $Id: PathExpr.cpp,v 1.5 2001-01-12 20:06:36 axel%pike.org Exp $
* $Id: PathExpr.cpp,v 1.6 2001-04-14 17:24:59 axel%pike.org Exp $
*/
#include "Expr.h"
#include "XMLUtils.h"
//------------/
//- PathExpr -/
@ -124,33 +125,37 @@ ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) {
ListIterator* iter = expressions.iterator();
MBool ancestorMode = MB_FALSE;
while ( iter->hasNext() ) {
PathExprItem* pxi = (PathExprItem*)iter->next();
ancestorMode = (ancestorMode || (pxi->ancestryOp == ANCESTOR_OP));
NodeSet* tmpNodes = 0;
cs->getNodeSetStack()->push(nodes);
for (int i = 0; i < nodes->size(); i++) {
Node* node = nodes->get(i);
#if 0
NodeSet* xNodes = (NodeSet*) pxi->pExpr->evaluate(node, cs);
#else
ExprResult *res = pxi->pExpr->evaluate(node, cs);
if (!res || res->getResultType() != ExprResult::NODESET)
continue;
NodeSet* xNodes = (NodeSet *) res;
#endif
if ( tmpNodes ) {
xNodes->copyInto(*tmpNodes);
NodeSet* resNodes;
if ( pxi->ancestryOp == ANCESTOR_OP) {
resNodes = new NodeSet;
evalDescendants(pxi->pExpr, node, cs, resNodes);
}
else {
tmpNodes = xNodes;
xNodes = 0;
ExprResult *res = pxi->pExpr->evaluate(node, cs);
if (!res || res->getResultType() != ExprResult::NODESET) {
//XXX ErrorReport: report nonnodeset error
delete res;
res = new NodeSet;
}
resNodes = (NodeSet*)res;
}
delete xNodes;
//-- handle ancestorMode
if ( ancestorMode ) fromDescendants(pxi->pExpr, node, cs, tmpNodes);
if ( tmpNodes ) {
resNodes->copyInto(*tmpNodes);
delete resNodes;
}
else
tmpNodes = resNodes;
}
delete (NodeSet*) cs->getNodeSetStack()->pop();
nodes = tmpNodes;
@ -166,22 +171,27 @@ ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) {
* all nodes that match the PatternExpr
* -- this will be moving to a Utility class
**/
void PathExpr::fromDescendants
(PatternExpr* pExpr, Node* context, ContextState* cs, NodeSet* nodes)
void PathExpr::evalDescendants
(PatternExpr* pExpr, Node* context, ContextState* cs, NodeSet* resNodes)
{
if (( !context ) || (! pExpr )) return;
NodeList* nl = context->getChildNodes();
for (UInt32 i = 0; i < nl->getLength(); i++) {
Node* child = nl->item(i);
if (pExpr->matches(child, context, cs))
nodes->add(child);
//-- check childs descendants
if (child->hasChildNodes())
fromDescendants(pExpr, child, cs, nodes);
ExprResult *res = pExpr->evaluate(context, cs);
if (!res || res->getResultType() != ExprResult::NODESET) {
//XXX ErrorReport: report nonnodeset error
}
} //-- fromDescendants
else
((NodeSet*)res)->copyInto(*resNodes);
delete res;
MBool filterWS = cs->isStripSpaceAllowed(context);
Node* child = context->getFirstChild();
while(child) {
if(!(filterWS && child->getNodeType() == Node::TEXT_NODE &&
XMLUtils::shouldStripTextnode(child->getNodeValue())))
evalDescendants(pExpr, child, cs, resNodes);
child = child->getNextSibling();
}
} //-- evalDescendants
/**
* Returns the default priority of this Pattern based on the given Node,