#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 #include #include const XMLCh FunctionIndexOf::name[] = { XERCES_CPP_NAMESPACE_QUALIFIER chLatin_i, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_n, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_d, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_e, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_x, XERCES_CPP_NAMESPACE_QUALIFIER chDash, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_o, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_f, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; /** * fn:index-of($seqParam as xdt:anyAtomicType*, $srchParam as xdt:anyAtomicType) as xs:integer* * fn:index-of($seqParam as xdt:anyAtomicType*, $srchParam as xdt:anyAtomicType, $collation as xs:string) as xs:integer* **/ FunctionIndexOf::FunctionIndexOf(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : ConstantFoldingFunction(name,2, 3, "anyAtomicType*, anyAtomicType, string", args, memMgr) { } Sequence FunctionIndexOf::stringIndexOf(Sequence &list, const AnyAtomicType* atom, Collation* collation, const DynamicContext* context) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Sequence result = Sequence(list.getLength(),memMgr); const XMLCh* atomString = atom->asString(context); int count = 0; Sequence::iterator end = list.end(); for(Sequence::iterator i = list.begin(); i != end; ++i, ++count) { const AnyAtomicType* current = (const AnyAtomicType*)*i; const XMLCh* currString = current->asString(context); if (collation->compare(currString, atomString) == 0) { int index = count + 1; result.addItem(DatatypeFactory::POD2AT::createInteger(memMgr, index, context)); } } return result; } Sequence FunctionIndexOf::simpleIndexOf(Sequence &list, const AnyAtomicType* atom, const DynamicContext* context) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Sequence result = Sequence(list.getLength(),memMgr); int count = 0; Sequence::iterator end = list.end(); for(Sequence::iterator i = list.begin(); i != end; ++i,++count) { const AnyAtomicType* current = (const AnyAtomicType*)*i; if (current->equals(atom, context)) { int index = count + 1; result.addItem(DatatypeFactory::POD2AT::createInteger(memMgr, index, context)); } } return result; } Sequence FunctionIndexOf::indexOf(Sequence &list, const Item* item, Collation* collation, const DynamicContext* context) const { const AnyAtomicType* atom = (const AnyAtomicType*)item; if (atom->isOfType(XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgURI_SCHEMAFORSCHEMA, XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgDT_STRING, context)) { return stringIndexOf(list, atom, collation, context); } else { return simpleIndexOf(list, atom, context); } } Sequence FunctionIndexOf::collapseTreeInternal(DynamicContext* context, int flags) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Sequence list=getParamNumber(1,context); if(list.isEmpty()) return Sequence(memMgr); const Item* srchparam = (const Item*)getParamNumber(2,context).first(); Collation* collation=NULL; if (getNumArgs() > 2) { Sequence collArg = getParamNumber(3,context); const XMLCh* collName=((const ATStringOrDerived*)collArg.first())->asString(context); try { DatatypeFactory::STR2AT::createAnyURI(memMgr, collName, context); } catch(XPath2ErrorException &e) { DSLthrow(FunctionException, X("FunctionIndexOf::collapseTreeInternal"), X("Invalid collationURI")); } collation=context->getCollation(collName); if (collation==NULL) DSLthrow(FunctionException, X("FunctionIndexOf::collapseTreeInternal"), X("Collation object is not available")); } else collation = context->getDefaultCollation(); if(collation==NULL) collation = context->getCollation(CodepointCollation::getCodepointCollationName()); return indexOf(list, srchparam, collation, context); }