dbertoni 2004/04/05 17:15:27
Modified: c/src/xalanc/XPath XPath.cpp XPath.hpp
XPathConstructionContext.hpp
XPathConstructionContextDefault.cpp
XPathConstructionContextDefault.hpp
Log:
New code for improved preserve/strip space handling.
Revision Changes Path
1.15 +164 -18 xml-xalan/c/src/xalanc/XPath/XPath.cpp
Index: XPath.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XPath/XPath.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- XPath.cpp 4 Apr 2004 08:50:26 -0000 1.14
+++ XPath.cpp 6 Apr 2004 00:15:27 -0000 1.15
@@ -47,6 +47,7 @@
#include "XalanQNameByReference.hpp"
#include "XObject.hpp"
#include "XObjectFactory.hpp"
+#include "XPathConstructionContext.hpp"
#include "XPathEnvSupport.hpp"
@@ -4768,6 +4769,17 @@
+XPath::NodeTester::NodeTester(const NodeTester& theSource) :
+ m_executionContext(theSource.m_executionContext),
+ m_targetNamespace(theSource.m_targetNamespace),
+ m_targetLocalName(theSource.m_targetLocalName),
+ m_testFunction(theSource.m_testFunction),
+ m_testFunction2(theSource.m_testFunction2)
+{
+}
+
+
+
XPath::NodeTester::NodeTester(
const XPath& xpath,
XPathExecutionContext& executionContext,
@@ -4929,15 +4941,141 @@
XPath::NodeTester::NodeTester(
+ XPathConstructionContext& theConstructionContext,
+ const XalanDOMString& theNameTest,
+ const PrefixResolver& thePrefixResolver,
+ const LocatorType* theLocator,
+ eMatchScore* theMatchScore) :
+ m_executionContext(0),
+ m_targetNamespace(0),
+ m_targetLocalName(0),
+ m_testFunction(&NodeTester::testDefault),
+ m_testFunction2(&NodeTester::testDefault2)
+{
+ const XalanDOMString::size_type theLength =
+ length(theNameTest);
+
+ if (theLength == 1 && theNameTest[0] == XPath::PSEUDONAME_ANY[0])
+ {
+ initialize(s_emptyString, s_emptyString, theMatchScore);
+ }
+ else
+ {
+ const XalanDOMString::size_type theIndex =
+ indexOf(theNameTest, XalanUnicode::charColon);
+
+ // If there's no ':', it's an NCName...
+ if (theIndex == theLength)
+ {
+ if (XalanQName::isValidNCName(theNameTest) == false)
+ {
+ theConstructionContext.error(
+ XalanMessageLoader::getMessage(
+ XalanMessages::IsNotValidQName_1Param,
+ theNameTest),
+ 0,
+ theLocator);
+ }
+ else
+ {
+ initialize(
+ s_emptyString,
+
theConstructionContext.getPooledString(theNameTest),
+ theMatchScore);
+ }
+ }
+ else
+ {
+ XPathConstructionContext::GetAndReleaseCachedString
scratchGuard(theConstructionContext);
+
+ XalanDOMString& theScratchString = scratchGuard.get();
+
+ theScratchString.assign(theNameTest, 0, theIndex);
+
+ // Get the namespace URI for the prefix...
+ const XalanDOMString* const theNamespaceURI =
+ thePrefixResolver.getNamespaceForPrefix(theScratchString);
+
+ if (theNamespaceURI == 0)
+ {
+ theConstructionContext.error(
+ XalanMessageLoader::getMessage(
+ XalanMessages::UndeclaredNamespacePrefix_1Param,
+ theScratchString),
+ 0,
+ theLocator);
+ }
+ else
+ {
+ // OK, now we have a namespace URI...
+ if (XalanQName::isValidNCName(theScratchString) == false)
+ {
+ theConstructionContext.error(
+ XalanMessageLoader::getMessage(
+ XalanMessages::IsNotValidQName_1Param,
+ theNameTest),
+ 0,
+ theLocator);
+ }
+ else if (theIndex == theLength - 2 &&
+ theNameTest[theIndex + 1] ==
XPath::PSEUDONAME_ANY[0])
+ {
+ // It's of the form "NCName:*"
+ initialize(
+
theConstructionContext.getPooledString(*theNamespaceURI),
+ s_emptyString,
+ theMatchScore);
+ }
+ else
+ {
+ theScratchString.assign(theNameTest, theIndex + 1,
theLength - theIndex - 1);
+
+ if (XalanQName::isValidNCName(theScratchString) == false)
+ {
+ theConstructionContext.error(
+ XalanMessageLoader::getMessage(
+ XalanMessages::IsNotValidQName_1Param,
+ theNameTest),
+ 0,
+ theLocator);
+ }
+ else
+ {
+ // It's of the form "NCName:NCName"
+ initialize(
+
theConstructionContext.getPooledString(*theNamespaceURI),
+
theConstructionContext.getPooledString(theScratchString),
+ theMatchScore);
+ }
+ }
+ }
+ }
+ }
+}
+
+
+
+XPath::NodeTester::NodeTester(
const XalanDOMString& theNamespaceURI,
const XalanDOMString& theLocalName,
- eMatchScore& theMatchScore) :
+ eMatchScore* theMatchScore) :
m_executionContext(0),
m_targetNamespace(0),
m_targetLocalName(0),
m_testFunction(&NodeTester::testDefault),
m_testFunction2(0)
{
+ initialize(theNamespaceURI, theLocalName, theMatchScore);
+}
+
+
+
+void
+XPath::NodeTester::initialize(
+ const XalanDOMString& theNamespaceURI,
+ const XalanDOMString& theLocalName,
+ eMatchScore* theMatchScore)
+{
if (theNamespaceURI.empty() == false)
{
m_targetNamespace = &theNamespaceURI;
@@ -4946,7 +5084,10 @@
{
m_testFunction2 = &NodeTester::testElementNamespaceOnly2;
- theMatchScore = eMatchScoreNSWild;
+ if (theMatchScore != 0)
+ {
+ *theMatchScore = eMatchScoreNSWild;
+ }
}
else
{
@@ -4954,7 +5095,10 @@
m_targetLocalName = &theLocalName;
- theMatchScore = eMatchScoreQName;
+ if (theMatchScore != 0)
+ {
+ *theMatchScore = eMatchScoreQName;
+ }
}
}
else if (theLocalName.empty() == false)
@@ -4963,13 +5107,19 @@
m_targetLocalName = &theLocalName;
- theMatchScore = eMatchScoreQName;
+ if (theMatchScore != 0)
+ {
+ *theMatchScore = eMatchScoreQName;
+ }
}
else
{
m_testFunction2 = &NodeTester::testElementTotallyWild2;
- theMatchScore = eMatchScoreNodeTest;
+ if (theMatchScore != 0)
+ {
+ *theMatchScore = eMatchScoreNodeTest;
+ }
}
}
@@ -5271,12 +5421,11 @@
XPath::eMatchScore
-XPath::NodeTester::testElementNCName2(const XalanNode& context) const
+XPath::NodeTester::testElementNCName2(const XalanElement& context) const
{
assert(
m_targetNamespace == 0 &&
- m_targetLocalName != 0 &&
- XalanNode::ELEMENT_NODE == context.getNodeType());
+ m_targetLocalName != 0);
if (matchLocalName(context) == false)
{
@@ -5291,12 +5440,11 @@
XPath::eMatchScore
-XPath::NodeTester::testElementQName2(const XalanNode& context) const
+XPath::NodeTester::testElementQName2(const XalanElement& context) const
{
assert(
m_targetNamespace != 0 &&
- m_targetLocalName != 0 &&
- XalanNode::ELEMENT_NODE == context.getNodeType());
+ m_targetLocalName != 0);
if (matchLocalNameAndNamespaceURI(context) == false)
{
@@ -5311,12 +5459,11 @@
XPath::eMatchScore
-XPath::NodeTester::testElementNamespaceOnly2(const XalanNode& context)
const
+XPath::NodeTester::testElementNamespaceOnly2(const XalanElement&
context) const
{
assert(
m_targetNamespace != 0 &&
- m_targetLocalName == 0 &&
- XalanNode::ELEMENT_NODE == context.getNodeType());
+ m_targetLocalName == 0);
if (matchNamespaceURI(context) == false)
{
@@ -5331,12 +5478,11 @@
XPath::eMatchScore
-XPath::NodeTester::testElementTotallyWild2(const XalanNode& context)
const
+XPath::NodeTester::testElementTotallyWild2(const XalanElement& /*
context */) const
{
assert(
m_targetNamespace == 0 &&
- m_targetLocalName == 0 &&
- XalanNode::ELEMENT_NODE == context.getNodeType());
+ m_targetLocalName == 0);
return eMatchScoreNodeTest;
}
@@ -5395,7 +5541,7 @@
XPath::eMatchScore
-XPath::NodeTester::testDefault2(const XalanNode& /* context */) const
+XPath::NodeTester::testDefault2(const XalanElement& /* context */)
const
{
return eMatchScoreNone;
}
1.9 +41 -9 xml-xalan/c/src/xalanc/XPath/XPath.hpp
Index: XPath.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/XPath/XPath.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XPath.hpp 2 Apr 2004 02:45:28 -0000 1.8
+++ XPath.hpp 6 Apr 2004 00:15:27 -0000 1.9
@@ -53,7 +53,9 @@
class PrefixResolver;
class XObject;
+class XalanElement;
class XalanNode;
+class XPathConstructionContext;
@@ -1030,6 +1032,10 @@
{
public:
+ NodeTester();
+
+ NodeTester(const NodeTester& theSource);
+
NodeTester(
const XPath& xpath,
XPathExecutionContext& executionContext,
@@ -1037,12 +1043,17 @@
OpCodeMapValueType argLen,
OpCodeMapValueType stepType);
- NodeTester();
+ NodeTester(
+ XPathConstructionContext& theContext,
+ const XalanDOMString& theNameTest,
+ const PrefixResolver& thePrefixResolver,
+ const LocatorType* theLocator = 0,
+ eMatchScore* theMatchScore = 0);
NodeTester(
const XalanDOMString& theNamespaceURI,
const XalanDOMString& theLocalName,
- eMatchScore& theMatchScore);
+ eMatchScore* theMatchScore = 0);
eMatchScore
operator()(
@@ -1055,15 +1066,34 @@
}
eMatchScore
- operator()(const XalanNode& context) const
+ operator()(const XalanElement& context) const
{
return (this->*m_testFunction2)(context);
}
+ NodeTester&
+ operator=(const NodeTester& theRHS)
+ {
+ m_executionContext = theRHS.m_executionContext;
+ m_targetNamespace = theRHS.m_targetNamespace;
+ m_targetLocalName = theRHS.m_targetLocalName;
+ m_testFunction = theRHS.m_testFunction;
+ m_testFunction2 = theRHS.m_testFunction2;
+
+ return *this;
+ }
+
private:
+ void
+ initialize(
+ const XalanDOMString& theNamespaceURI,
+ const XalanDOMString& theLocalName,
+ eMatchScore* theMatchScore = 0);
+
+
typedef eMatchScore (NodeTester::*TestFunctionPtr)(const
XalanNode&, XalanNode::NodeType) const;
- typedef eMatchScore (NodeTester::*TestFunctionPtr2)(const
XalanNode&) const;
+ typedef eMatchScore (NodeTester::*TestFunctionPtr2)(const
XalanElement&) const;
eMatchScore
@@ -1137,16 +1167,16 @@
XalanNode::NodeType nodeType) const;
eMatchScore
- testElementNCName2(const XalanNode& context) const;
+ testElementNCName2(const XalanElement& context) const;
eMatchScore
- testElementQName2(const XalanNode& context) const;
+ testElementQName2(const XalanElement& context) const;
eMatchScore
- testElementNamespaceOnly2(const XalanNode& context) const;
+ testElementNamespaceOnly2(const XalanElement& context) const;
eMatchScore
- testElementTotallyWild2(const XalanNode& context) const;
+ testElementTotallyWild2(const XalanElement&
context) const;
eMatchScore
testNamespaceNCName(
@@ -1164,7 +1194,7 @@
XalanNode::NodeType nodeType) const;
eMatchScore
- testDefault2(const XalanNode& context) const;
+ testDefault2(const XalanElement& context) const;
bool
matchLocalName(const XalanNode& context) const;
@@ -1192,6 +1222,8 @@
TestFunctionPtr2 m_testFunction2;
};
+
+ friend class NodeTester;
protected:
1.5 +23 -0 xml-xalan/c/src/xalanc/XPath/XPathConstructionContext.hpp
Index: XPathConstructionContext.hpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/xalanc/XPath/XPathConstructionContext.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XPathConstructionContext.hpp 26 Feb 2004 22:40:34 -0000 1.4
+++ XPathConstructionContext.hpp 6 Apr 2004 00:15:27 -0000 1.5
@@ -27,10 +27,22 @@
+XALAN_DECLARE_XERCES_CLASS(Locator)
+
+
+
XALAN_CPP_NAMESPACE_BEGIN
+typedef XERCES_CPP_NAMESPACE_QUALIFIER Locator LocatorType;
+
+
+
+class XalanNode;
+
+
+
//
/**
* @author <a href="mailto:[email protected]">David N. Bertoni</a>
@@ -153,6 +165,17 @@
XalanDOMString* m_string;
};
+ virtual void
+ error(
+ const XalanDOMString& msg,
+ const XalanNode* sourceNode,
+ const LocatorType* locator) const = 0;
+
+ virtual void
+ warn(
+ const XalanDOMString& msg,
+ const XalanNode* sourceNode,
+ const LocatorType* locator) const = 0;
};
1.5 +31 -0
xml-xalan/c/src/xalanc/XPath/XPathConstructionContextDefault.cpp
Index: XPathConstructionContextDefault.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/xalanc/XPath/XPathConstructionContextDefault.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XPathConstructionContextDefault.cpp 26 Feb 2004 22:40:34 -0000
1.4
+++ XPathConstructionContextDefault.cpp 6 Apr 2004 00:15:27 -0000
1.5
@@ -18,6 +18,10 @@
+#include "xalanc/PlatformSupport/XSLException.hpp"
+
+
+
XALAN_CPP_NAMESPACE_BEGIN
@@ -76,6 +80,33 @@
XPathConstructionContextDefault::releaseCachedString(XalanDOMString&
theString)
{
return m_stringCache.release(theString);
+}
+
+
+
+void
+XPathConstructionContextDefault::error(
+ const XalanDOMString& msg,
+ const XalanNode* /* sourceNode */,
+ const LocatorType* locator) const
+{
+ if (locator != 0)
+ {
+ throw XSLException(*locator, msg);
+ }
+ else
+ {
+ throw XSLException(msg);
+ }
+}
+
+
+void
+XPathConstructionContextDefault::warn(
+ const XalanDOMString& /* msg */,
+ const XalanNode* /* sourceNode */,
+ const LocatorType* /* locator */) const
+{
}
1.5 +12 -0
xml-xalan/c/src/xalanc/XPath/XPathConstructionContextDefault.hpp
Index: XPathConstructionContextDefault.hpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/xalanc/XPath/XPathConstructionContextDefault.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XPathConstructionContextDefault.hpp 26 Feb 2004 22:40:34 -0000
1.4
+++ XPathConstructionContextDefault.hpp 6 Apr 2004 00:15:27 -0000
1.5
@@ -75,6 +75,18 @@
virtual bool
releaseCachedString(XalanDOMString& theString);
+ virtual void
+ error(
+ const XalanDOMString& msg,
+ const XalanNode* sourceNode,
+ const LocatorType* locator) const;
+
+ virtual void
+ warn(
+ const XalanDOMString& msg,
+ const XalanNode* sourceNode,
+ const LocatorType* locator) const;
+
private:
XalanDOMStringPool m_stringPool;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]