зеркало из https://github.com/mozilla/pjs.git
not part of default build; PathExpr did wrong for //; code by sicking, r=me, sr=shaver, bug 75307
This commit is contained in:
Родитель
b5d880087c
Коммит
b8afba4946
|
@ -25,7 +25,7 @@
|
||||||
* - changed constant short declarations in many of the classes
|
* - changed constant short declarations in many of the classes
|
||||||
* with enumerations, commented with //--LF
|
* 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.
|
XPath class definitions.
|
||||||
Much of this code was ported from XSL:P.
|
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
|
//necessary prototypes
|
||||||
|
@ -1430,7 +1430,7 @@ private:
|
||||||
* all nodes that match the PatternExpr
|
* all nodes that match the PatternExpr
|
||||||
* -- this will be moving to a Utility class
|
* -- this will be moving to a Utility class
|
||||||
**/
|
**/
|
||||||
void fromDescendants(PatternExpr* pExpr,
|
void evalDescendants(PatternExpr* pExpr,
|
||||||
Node* context,
|
Node* context,
|
||||||
ContextState* cs,
|
ContextState* cs,
|
||||||
NodeSet* nodes);
|
NodeSet* nodes);
|
||||||
|
|
|
@ -29,10 +29,11 @@
|
||||||
* - foo//bar would not match properly if there was more than
|
* - foo//bar would not match properly if there was more than
|
||||||
* one node in the NodeSet (nodes) on the final iteration
|
* 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 "Expr.h"
|
||||||
|
#include "XMLUtils.h"
|
||||||
|
|
||||||
//------------/
|
//------------/
|
||||||
//- PathExpr -/
|
//- PathExpr -/
|
||||||
|
@ -124,33 +125,37 @@ ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) {
|
||||||
|
|
||||||
ListIterator* iter = expressions.iterator();
|
ListIterator* iter = expressions.iterator();
|
||||||
|
|
||||||
MBool ancestorMode = MB_FALSE;
|
|
||||||
while ( iter->hasNext() ) {
|
while ( iter->hasNext() ) {
|
||||||
|
|
||||||
PathExprItem* pxi = (PathExprItem*)iter->next();
|
PathExprItem* pxi = (PathExprItem*)iter->next();
|
||||||
ancestorMode = (ancestorMode || (pxi->ancestryOp == ANCESTOR_OP));
|
|
||||||
NodeSet* tmpNodes = 0;
|
NodeSet* tmpNodes = 0;
|
||||||
cs->getNodeSetStack()->push(nodes);
|
cs->getNodeSetStack()->push(nodes);
|
||||||
for (int i = 0; i < nodes->size(); i++) {
|
for (int i = 0; i < nodes->size(); i++) {
|
||||||
Node* node = nodes->get(i);
|
Node* node = nodes->get(i);
|
||||||
#if 0
|
|
||||||
NodeSet* xNodes = (NodeSet*) pxi->pExpr->evaluate(node, cs);
|
NodeSet* resNodes;
|
||||||
#else
|
if ( pxi->ancestryOp == ANCESTOR_OP) {
|
||||||
ExprResult *res = pxi->pExpr->evaluate(node, cs);
|
resNodes = new NodeSet;
|
||||||
if (!res || res->getResultType() != ExprResult::NODESET)
|
evalDescendants(pxi->pExpr, node, cs, resNodes);
|
||||||
continue;
|
|
||||||
NodeSet* xNodes = (NodeSet *) res;
|
|
||||||
#endif
|
|
||||||
if ( tmpNodes ) {
|
|
||||||
xNodes->copyInto(*tmpNodes);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tmpNodes = xNodes;
|
ExprResult *res = pxi->pExpr->evaluate(node, cs);
|
||||||
xNodes = 0;
|
if (!res || res->getResultType() != ExprResult::NODESET) {
|
||||||
|
//XXX ErrorReport: report nonnodeset error
|
||||||
|
delete res;
|
||||||
|
res = new NodeSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
resNodes = (NodeSet*)res;
|
||||||
}
|
}
|
||||||
delete xNodes;
|
|
||||||
//-- handle ancestorMode
|
if ( tmpNodes ) {
|
||||||
if ( ancestorMode ) fromDescendants(pxi->pExpr, node, cs, tmpNodes);
|
resNodes->copyInto(*tmpNodes);
|
||||||
|
delete resNodes;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tmpNodes = resNodes;
|
||||||
|
|
||||||
}
|
}
|
||||||
delete (NodeSet*) cs->getNodeSetStack()->pop();
|
delete (NodeSet*) cs->getNodeSetStack()->pop();
|
||||||
nodes = tmpNodes;
|
nodes = tmpNodes;
|
||||||
|
@ -166,22 +171,27 @@ ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) {
|
||||||
* all nodes that match the PatternExpr
|
* all nodes that match the PatternExpr
|
||||||
* -- this will be moving to a Utility class
|
* -- this will be moving to a Utility class
|
||||||
**/
|
**/
|
||||||
void PathExpr::fromDescendants
|
void PathExpr::evalDescendants
|
||||||
(PatternExpr* pExpr, Node* context, ContextState* cs, NodeSet* nodes)
|
(PatternExpr* pExpr, Node* context, ContextState* cs, NodeSet* resNodes)
|
||||||
{
|
{
|
||||||
|
ExprResult *res = pExpr->evaluate(context, cs);
|
||||||
if (( !context ) || (! pExpr )) return;
|
if (!res || res->getResultType() != ExprResult::NODESET) {
|
||||||
|
//XXX ErrorReport: report nonnodeset error
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
} //-- 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,
|
* Returns the default priority of this Pattern based on the given Node,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче