#include "../config/pathan_config.h" /* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #include #include #include #include #include #include #include #include #include #include #include /*static*/ const XMLCh Equals::name[]={ XERCES_CPP_NAMESPACE_QUALIFIER chLatin_e, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_q, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; Equals::Equals(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : DataItemOperator(name, args, memMgr) { } /*static*/ bool Equals::equals(const Item* arg1, const Item* arg2, DynamicContext* context) { assert(arg1->isAtomicValue() && arg2->isAtomicValue()); const AnyAtomicType* atom1 = (const AnyAtomicType*)arg1; const AnyAtomicType* atom2 = (const AnyAtomicType*)arg2; // take care of the special case first if(atom1->getPrimitiveTypeIndex() == AnyAtomicType::STRING) { if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::STRING) { DSLthrow(XPath2ErrorException,X("Equals::equals"), X("An attempt to compare a string type to a non string type has occurred")); } Collation* collation=context->getDefaultCollation(); if(collation==NULL) collation=context->getCollation(CodepointCollation::getCodepointCollationName()); // if the function returns 0, then they are equal return (collation->compare(atom1->asString(context),atom2->asString(context))==0); } return atom1->equals(atom2, context); } Sequence Equals::collapseTreeInternal(DynamicContext* context, int flags) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Sequence newArgs = getComparisonOperatorArguments(context); if(newArgs.getLength() < 2) return Sequence(memMgr); bool result = equals(newArgs.first(), newArgs.second(), context); return Sequence(DatatypeFactory::POD2AT::createBoolean(memMgr, result, context), memMgr); }