not part of build, code by sicking, r=peterv,me,sr=shaver, fixing 75304, and 70865, whitespace and locationstep

This commit is contained in:
axel%pike.org 2001-04-11 15:01:05 +00:00
Родитель 5517cd85ae
Коммит 3cef4dfea8
6 изменённых файлов: 82 добавлений и 46 удалений

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

@ -21,14 +21,14 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: BasicNodeExpr.cpp,v 1.2 2001-01-12 20:06:31 axel%pike.org Exp $
* $Id: BasicNodeExpr.cpp,v 1.3 2001-04-11 15:00:57 axel%pike.org Exp $
*/
#include "Expr.h"
/**
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.2 $ $Date: 2001-01-12 20:06:31 $
* @version $Revision: 1.3 $ $Date: 2001-04-11 15:00:57 $
**/
//- Constructors -/
@ -108,6 +108,9 @@ MBool BasicNodeExpr::matches(Node* node, Node* context, ContextState* cs) {
case NodeExpr::PI_EXPR :
return (MBool) (node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE);
default: //-- node()
if(node->getNodeType() == Node::TEXT_NODE)
return !cs->isStripSpaceAllowed(node);
return MB_TRUE;
break;
}
return MB_TRUE;

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

@ -25,7 +25,7 @@
* - changed constant short declarations in many of the classes
* with enumerations, commented with //--LF
*
* $Id: Expr.h,v 1.10 2001-04-08 14:33:45 peterv%netscape.com Exp $
* $Id: Expr.h,v 1.11 2001-04-11 15:00:57 axel%pike.org Exp $
*/
@ -46,7 +46,7 @@
/*
XPath class definitions.
Much of this code was ported from XSL:P.
@version $Revision: 1.10 $ $Date: 2001-04-08 14:33:45 $
@version $Revision: 1.11 $ $Date: 2001-04-11 15:00:57 $
*/
//necessary prototypes
@ -930,6 +930,7 @@ private:
short axisIdentifier;
void fromDescendants(Node* context, ContextState* cs, NodeSet* nodes);
void fromDescendantsRev(Node* context, ContextState* cs, NodeSet* nodes);
}; //-- LocationStep

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

@ -21,12 +21,12 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: LocationStep.cpp,v 1.4 2001-01-22 09:36:17 kvisco%ziplink.net Exp $
* $Id: LocationStep.cpp,v 1.5 2001-04-11 15:00:58 axel%pike.org Exp $
*/
/*
Implementation of an XPath LocationStep
@version $Revision: 1.4 $ $Date: 2001-01-22 09:36:17 $
@version $Revision: 1.5 $ $Date: 2001-04-11 15:00:58 $
*/
#include "Expr.h"
@ -109,14 +109,14 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
Node* node = context;
switch (axisIdentifier) {
case ANCESTOR_AXIS :
if (node) node = context->getParentNode();
node = cs->getParentNode(context);
//-- do not break here
case ANCESTOR_OR_SELF_AXIS :
while (node) {
if (nodeExpr->matches(node, context, cs)) {
nodes->add(node);
}
node = node->getParentNode();
node = cs->getParentNode(node);
}
break;
case ATTRIBUTE_AXIS :
@ -124,7 +124,7 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
NamedNodeMap* atts = context->getAttributes();
if ( atts ) {
for ( UInt32 i = 0; i < atts->getLength(); i++ ) {
Attr* attr = (Attr*)atts->item(i);
Node* attr = atts->item(i);
if ( nodeExpr->matches(attr, context, cs) ) nodes->add(attr);
}
}
@ -139,21 +139,25 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
break;
case FOLLOWING_AXIS :
{
node = context->getNextSibling();
if ( node->getNodeType() == Node::ATTRIBUTE_NODE) {
node = cs->getParentNode(node);
fromDescendants(node, cs, nodes);
}
while (node && !node->getNextSibling()) {
node = cs->getParentNode(node);
}
while (node) {
node = node->getNextSibling();
if (nodeExpr->matches(node, context, cs))
nodes->add(node);
if (node->hasChildNodes())
fromDescendants(node, cs, nodes);
Node* tmpNode = node->getNextSibling();
if (!tmpNode) {
while (node && !node->getNextSibling()) {
node = node->getParentNode();
if ((node) && (node->getNodeType() != Node::DOCUMENT_NODE))
node = node->getNextSibling();
}
else node = tmpNode;
}
break;
}
@ -170,21 +174,27 @@ ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
break;
case PARENT_AXIS :
{
Node* parent = context->getParentNode();
Node* parent = cs->getParentNode(context);
if ( nodeExpr->matches(parent, context, cs) )
nodes->add(parent);
break;
}
case PRECEDING_AXIS :
node = context->getPreviousSibling();
if ( !node ) node = context->getParentNode();
while (node && !node->getPreviousSibling()) {
node = cs->getParentNode(node);
}
while (node) {
node = node->getPreviousSibling();
if (node->hasChildNodes())
fromDescendantsRev(node, cs, nodes);
if (nodeExpr->matches(node, context, cs))
nodes->add(node);
Node* temp = node->getPreviousSibling();
if (!temp) node = node->getParentNode();
else node = temp;
while (node && !node->getPreviousSibling()) {
node = node->getParentNode();
}
}
break;
case PRECEDING_SIBLING_AXIS:
@ -237,19 +247,39 @@ double LocationStep::getDefaultPriority(Node* node, Node* context, ContextState*
void LocationStep::fromDescendants(Node* context, ContextState* cs, NodeSet* nodes) {
if (( !context ) || (! nodeExpr )) return;
if ( !context || !nodeExpr ) return;
NodeList* nl = context->getChildNodes();
for (UInt32 i = 0; i < nl->getLength(); i++) {
Node* child = nl->item(i);
Node* child = context->getFirstChild();
while (child) {
if (nodeExpr->matches(child, context, cs))
nodes->add(child);
//-- check childs descendants
if (child->hasChildNodes()) fromDescendants(child, cs, nodes);
if (child->hasChildNodes())
fromDescendants(child, cs, nodes);
child = child->getNextSibling();
}
} //-- fromDescendants
void LocationStep::fromDescendantsRev(Node* context, ContextState* cs, NodeSet* nodes) {
if ( !context || !nodeExpr ) return;
Node* child = context->getLastChild();
while (child) {
//-- check childs descendants
if (child->hasChildNodes())
fromDescendantsRev(child, cs, nodes);
if (nodeExpr->matches(child, context, cs))
nodes->add(child);
child = child->getPreviousSibling();
}
} //-- fromDescendantsRev
/**
* Determines whether this PatternExpr matches the given node within
* the given context
@ -260,11 +290,18 @@ MBool LocationStep::matches(Node* node, Node* context, ContextState* cs) {
if ( !nodeExpr->matches(node, context, cs) ) return MB_FALSE;
NodeSet nodes;
nodes.add(node);
evaluatePredicates(&nodes, cs);
MBool result = MB_TRUE;
if ( !isEmpty() ) {
NodeSet* nodes = (NodeSet*)evaluate(cs->getParentNode(node),cs);
result = nodes->contains(node);
delete nodes;
}
else if (axisIdentifier == CHILD_AXIS ) {
if (!node->getParentNode())
result = MB_FALSE;
}
return (MBool)(nodes.size() > 0);
return result;
} //-- matches

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

@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: TextExpr.cpp,v 1.2 2001-01-12 20:06:37 axel%pike.org Exp $
* $Id: TextExpr.cpp,v 1.3 2001-04-11 15:01:03 axel%pike.org Exp $
*/
#include "Expr.h"
@ -74,7 +74,8 @@ short TextExpr::getType() {
**/
MBool TextExpr::matches(Node* node, Node* context, ContextState* cs) {
if ( node ) {
return (MBool) (node->getNodeType() == Node::TEXT_NODE);
if(node->getNodeType() == Node::TEXT_NODE)
return !cs->isStripSpaceAllowed(node);
}
return MB_FALSE;
} //-- matches

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

@ -25,13 +25,13 @@
* -- added code in ::resolveFunctionCall to support the
* document() function.
*
* $Id: ProcessorState.cpp,v 1.23 2001-04-08 14:32:37 peterv%netscape.com Exp $
* $Id: ProcessorState.cpp,v 1.24 2001-04-11 15:01:05 axel%pike.org Exp $
*/
/**
* Implementation of ProcessorState
* Much of this code was ported from XSL:P
* @version $Revision: 1.23 $ $Date: 2001-04-08 14:32:37 $
* @version $Revision: 1.24 $ $Date: 2001-04-11 15:01:05 $
**/
#include "ProcessorState.h"
@ -792,7 +792,11 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) {
break;
}
case Node::TEXT_NODE:
if (!XMLUtils::shouldStripTextnode(node->getNodeValue()))
return MB_FALSE;
return isStripSpaceAllowed(node->getParentNode());
case Node::DOCUMENT_NODE:
return MB_TRUE;
default:
break;
}

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

@ -38,7 +38,7 @@
* Olivier Gerardin
* -- Changed behavior of passing parameters to templates
*
* $Id: XSLTProcessor.cpp,v 1.39 2001-04-08 14:32:16 peterv%netscape.com Exp $
* $Id: XSLTProcessor.cpp,v 1.40 2001-04-11 15:01:05 axel%pike.org Exp $
*/
#include "XSLTProcessor.h"
@ -66,7 +66,7 @@
/**
* XSLTProcessor is a class for Processing XSL stylesheets
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.39 $ $Date: 2001-04-08 14:32:16 $
* @version $Revision: 1.40 $ $Date: 2001-04-11 15:01:05 $
**/
/**
@ -1295,16 +1295,6 @@ void XSLTProcessor::processAction
break;
}
exprResult->stringValue(value);
//-- handle whitespace stripping
if ( exprResult->getResultType() == ExprResult::NODESET) {
NodeSet* nodes = (NodeSet*)exprResult;
if ( nodes->size() > 0) {
Node* node = nodes->get(0);
if ( ps->isStripSpaceAllowed(node) &&
XMLUtils::shouldStripTextnode(value))
value.clear();
}
}
if (value.length()>0)
ps->addToResultTree(resultDoc->createTextNode(value));
delete exprResult;