#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 const XMLCh FunctionCompare::name[] = { XERCES_CPP_NAMESPACE_QUALIFIER chLatin_c, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_o, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_m, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_p, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_a, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_r, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_e, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; /** * fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer? * fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer? **/ FunctionCompare::FunctionCompare(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : ConstantFoldingFunction(name,2, 3, "string?,string?,string", args, memMgr) { } Sequence FunctionCompare::collapseTreeInternal(DynamicContext* context, int flags) const { Sequence str1 = getParamNumber(1,context); Sequence str2 = getParamNumber(2,context); if(str1.isEmpty() || str2.isEmpty()) return Sequence(context->getMemoryManager()); Collation* collation = NULL; if(getNumArgs()>2) { Sequence collArg = getParamNumber(3,context); const XMLCh* collName = ((const ATStringOrDerived*)collArg.first())->asString(context); try { DatatypeFactory::STR2AT::createAnyURI(context->getMemoryManager(), collName, context); } catch(XPath2ErrorException &e) { DSLthrow(FunctionException, X("FunctionCompare::collapseTreeInternal"), X("Invalid argument to compare function")); } collation = context->getCollation(collName); if(collation == NULL) DSLthrow(FunctionException,X("FunctionCompare::collapseTreeInternal"),X("Collation object is not available")); } else collation = context->getDefaultCollation(); if(collation == NULL) collation = context->getCollation(CodepointCollation::getCodepointCollationName()); const XMLCh* string1 = ((const ATStringOrDerived*)str1.first())->asString(context); const XMLCh* string2 = ((const ATStringOrDerived*)str2.first())->asString(context); Sequence result(DatatypeFactory::POD2AT::createInteger(context->getMemoryManager(), collation->compare(string1,string2), context), context->getMemoryManager()); return result; }