dbertoni 00/04/18 08:26:43
Modified: c/src/XPath FunctionContains.hpp
FunctionDefaultStringArgument.hpp
FunctionNormalize.hpp FunctionString.hpp
FunctionStringLength.hpp
Log:
Changed the way default string arguments are handled.
Revision Changes Path
1.6 +19 -6 xml-xalan/c/src/XPath/FunctionContains.hpp
Index: FunctionContains.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionContains.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FunctionContains.hpp 2000/04/12 19:40:53 1.5
+++ FunctionContains.hpp 2000/04/18 15:26:41 1.6
@@ -112,14 +112,27 @@
const XalanDOMString arg1 = args[0]->str();
const XalanDOMString arg2 = args[1]->str();
- // This is rather a moot point but conformance test str62
indicates the
- // answer should be true
- if (isEmpty(arg1) && isEmpty(arg2))
- return
executionContext.getXObjectFactory().createBoolean(true);
+ bool fResult = true;
- const int theIndex = indexOf(arg1, arg2);
+ // If arg2 is empty, then don't bother to check anything.
+ if (isEmpty(arg2) == false)
+ {
+ // Is arg1 empty?
+ if (isEmpty(arg1) == true)
+ {
+ fResult = false;
+ }
+ else
+ {
+ // OK, both strings have some data, so look for
+ // the index...
+ const unsigned int theIndex =
indexOf(arg1, arg2);
- return
executionContext.getXObjectFactory().createBoolean(theIndex >= 0 ? true :
false);
+ fResult = theIndex < length(arg1) ? true :
false;
+ }
+ }
+
+ return
executionContext.getXObjectFactory().createBoolean(fResult);
}
#if defined(XALAN_NO_COVARIANT_RETURN_TYPE)
1.5 +5 -26 xml-xalan/c/src/XPath/FunctionDefaultStringArgument.hpp
Index: FunctionDefaultStringArgument.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionDefaultStringArgument.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FunctionDefaultStringArgument.hpp 2000/04/11 14:46:05 1.4
+++ FunctionDefaultStringArgument.hpp 2000/04/18 15:26:41 1.5
@@ -69,7 +69,6 @@
-#include <XPath/FunctionString.hpp>
#include <XPath/XObject.hpp>
#include <XPath/XObjectFactory.hpp>
#include <XPath/XPathExecutionContext.hpp>
@@ -116,40 +115,20 @@
virtual XalanDOMString
getDefaultStringArgument(
XPathExecutionContext& executionContext,
- XalanNode& context,
- int
opPos)
+ XalanNode& context)
{
// This is complicated. The XPath standard says that if there
// are no arguments, the default is to turn the contextNode
- // into a string-value, which really means using FunctionString.
- //
- // So we have to create a context for calling FunctionString
- // with the context node. We shroud the temporary XObjects in
- // XString in FactoryObjectAutoPointers because they can be
returned
- // once we've converted the context node to an XObject.
+ // into a string-value, which really means using FunctionString,
+ // but we don't need to do that, since our XObject classes
+ // do the real work in turning themselves into strings.
- // A vector for the args. The size will always be one.
- XObjectArgVectorType theNewArgs(1);
-
// A node set that contains the context node.
FactoryObjectAutoPointer<XObject>
theArg(&executionContext.getXObjectFactory(),
executionContext.getXObjectFactory().createNodeSet(context));
- // Put the argument into the vector...
- theNewArgs[0] = theArg.get();
-
- // This is our string functor.
- FunctionString theStringFunctor;
-
- // Get the result...
- FactoryObjectAutoPointer<XObject>
theXString(&executionContext.getXObjectFactory(),
-
theStringFunctor.execute(executionContext,
-
&context,
-
opPos,
-
theNewArgs));
-
// Now, get the string from the XObject.
- return theXString->str();
+ return theArg->str();
}
private:
1.5 +3 -4 xml-xalan/c/src/XPath/FunctionNormalize.hpp
Index: FunctionNormalize.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionNormalize.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FunctionNormalize.hpp 2000/04/11 14:46:07 1.4
+++ FunctionNormalize.hpp 2000/04/18 15:26:41 1.5
@@ -95,7 +95,7 @@
execute(
XPathExecutionContext&
executionContext,
XalanNode*
context,
- int
opPos,
+ int
/* opPos */,
const XObjectArgVectorType& args)
{
XalanDOMString theSourceString;
@@ -116,9 +116,8 @@
}
else
{
- theSourceString =
getDefaultStringArgument(executionContext,
-
*context,
-
opPos);
+ theSourceString =
getDefaultStringArgument(executionContext,
+
*context);
}
const unsigned int theSourceStringLength =
length(theSourceString);
1.6 +27 -6 xml-xalan/c/src/XPath/FunctionString.hpp
Index: FunctionString.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionString.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FunctionString.hpp 2000/04/12 19:40:53 1.5
+++ FunctionString.hpp 2000/04/18 15:26:42 1.6
@@ -73,7 +73,7 @@
// Base class header file...
-#include <XPath/Function.hpp>
+#include <XPath/FunctionDefaultStringArgument.hpp>
@@ -90,7 +90,7 @@
// These are all inline, even though
// there are virtual functions, because we expect that they will only be
// needed by the XPath class.
-class XALAN_XPATH_EXPORT FunctionString : public Function
+class XALAN_XPATH_EXPORT FunctionString : public
FunctionDefaultStringArgument
{
public:
@@ -103,15 +103,36 @@
int
/* opPos */,
const XObjectArgVectorType& args)
{
- if(args.size() > 1)
+ XalanDOMString theResult;
+
+ const XObjectArgVectorType::size_type theSize = args.size();
+
+ if(theSize > 1)
{
executionContext.error("The string() function takes
zero or one argument!",
context);
+ }
+ else if(theSize == 0)
+ {
+ if (context == 0)
+ {
+ executionContext.error("The string() function
requires a non-null context node!",
+
context);
+ }
+ else
+ {
+ theResult =
getDefaultStringArgument(executionContext,
+
*context);
+ }
+ }
+ else
+ {
+ assert(args[0] != 0);
+
+ theResult = args[0]->str();
}
- if(args.size() == 0)
- return
executionContext.getXObjectFactory().createNodeSet(*context);
- return
executionContext.getXObjectFactory().createString(args[0]->str());
+ return
executionContext.getXObjectFactory().createString(theResult);
}
#if defined(XALAN_NO_COVARIANT_RETURN_TYPE)
1.5 +2 -3 xml-xalan/c/src/XPath/FunctionStringLength.hpp
Index: FunctionStringLength.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionStringLength.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FunctionStringLength.hpp 2000/04/11 14:46:08 1.4
+++ FunctionStringLength.hpp 2000/04/18 15:26:42 1.5
@@ -97,7 +97,7 @@
execute(
XPathExecutionContext&
executionContext,
XalanNode*
context,
- int
opPos,
+ int
/* opPos */,
const XObjectArgVectorType& args)
{
const XObjectArgVectorType::size_type theSize = args.size();
@@ -114,8 +114,7 @@
else
{
theResult =
getDefaultStringArgument(executionContext,
-
*context,
-
opPos);
+
*context);
}
}
else if (theSize == 1)