dbertoni 00/07/14 09:57:13
Modified: c/src/XPath XPathExecutionContext.hpp
XPathExecutionContextDefault.cpp
XPathExecutionContextDefault.hpp
Log:
Improved implementation of getContextNodeListPosition() and fixed
signed/unsigned mismatch on return types.
Revision Changes Path
1.16 +4 -2 xml-xalan/c/src/XPath/XPathExecutionContext.hpp
Index: XPathExecutionContext.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContext.hpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XPathExecutionContext.hpp 2000/07/06 20:16:28 1.15
+++ XPathExecutionContext.hpp 2000/07/14 16:57:13 1.16
@@ -279,15 +279,17 @@
*
* @return length of list
*/
- virtual int
+ virtual unsigned int
getContextNodeListLength() const = 0;
/*
* Get the position of the node in the current context node list.
+ * Note that this is 1-based indexing (XPath/XSLT-style), not 0-based.
+ * Thus, 0 will be returned if the node was not found.
*
* @return position in list
*/
- virtual int
+ virtual unsigned int
getContextNodeListPosition(const XalanNode& contextNode)
const = 0;
/**
1.12 +6 -16 xml-xalan/c/src/XPath/XPathExecutionContextDefault.cpp
Index: XPathExecutionContextDefault.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContextDefault.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- XPathExecutionContextDefault.cpp 2000/07/06 20:16:28 1.11
+++ XPathExecutionContextDefault.cpp 2000/07/14 16:57:13 1.12
@@ -196,7 +196,7 @@
-int
+unsigned int
XPathExecutionContextDefault::getContextNodeListLength() const
{
if (m_throwFoundIndex == true)
@@ -209,7 +209,7 @@
-int
+unsigned int
XPathExecutionContextDefault::getContextNodeListPosition(const XalanNode&
contextNode) const
{
if (m_throwFoundIndex == true)
@@ -217,21 +217,11 @@
throw FoundIndex();
}
- int pos = 0;
+ // Get the index of the node...
+ const unsigned int theIndex =
m_contextNodeList->indexOf(&contextNode);
- const unsigned int nNodes = m_contextNodeList->getLength();
-
- for(unsigned int i = 0; i < nNodes; i++)
- {
- if(m_contextNodeList->item(i) == &contextNode)
- {
- pos = i + 1; // for 1-based XSL count.
-
- break;
- }
- }
-
- return pos;
+ // If not found return 0. Otherwise, return the index + 1
+ return theIndex == NodeRefListBase::npos ? 0 : theIndex + 1;
}
1.14 +2 -2 xml-xalan/c/src/XPath/XPathExecutionContextDefault.hpp
Index: XPathExecutionContextDefault.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathExecutionContextDefault.hpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XPathExecutionContextDefault.hpp 2000/07/06 20:16:28 1.13
+++ XPathExecutionContextDefault.hpp 2000/07/14 16:57:13 1.14
@@ -154,10 +154,10 @@
virtual void
setContextNodeList(const NodeRefListBase& theList);
- virtual int
+ virtual unsigned int
getContextNodeListLength() const;
- virtual int
+ virtual unsigned int
getContextNodeListPosition(const XalanNode& contextNode)
const;
virtual bool