#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 const XMLCh FunctionSubstring::name[] = { XERCES_CPP_NAMESPACE_QUALIFIER chLatin_s, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_u, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_b, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_s, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_t, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_r, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_i, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_n, XERCES_CPP_NAMESPACE_QUALIFIER chLatin_g, XERCES_CPP_NAMESPACE_QUALIFIER chNull }; /** * fn:substring($sourceString as xs:string?, $startingLoc as xs:double) as xs:string * fn:substring($sourceString as xs:string?, $startingLoc as xs:double, $length as xs:double) as xs:string **/ FunctionSubstring::FunctionSubstring(const VectorOfDataItems &args, XPath2MemoryManager* memMgr) : ConstantFoldingFunction(name,2, 3, "string?, double, double", args, memMgr) { } Sequence FunctionSubstring::collapseTreeInternal(DynamicContext* context, int flags) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Sequence string=getParamNumber(1, context); if(string.isEmpty()) return Sequence(DatatypeFactory::STR2AT::createString(memMgr, XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgZeroLenString, context), memMgr); const ATStringOrDerived* str = (const ATStringOrDerived*)string.first(); Sequence startingLoc=getParamNumber(2,context); const ATDoubleOrDerived* one = DatatypeFactory::POD2AT::createDouble(memMgr, 1, context); // The first character of a string is located at position 1 (not position 0). const ATDoubleOrDerived* index = (const ATDoubleOrDerived*)startingLoc.first(); if (index->lessThan(one, context)) index = one; const ATDoubleOrDerived* subStrLength; if(getNumArgs()>2) { Sequence length=getParamNumber(3,context); subStrLength=(const ATDoubleOrDerived*)length.first(); } else { subStrLength=(const ATDoubleOrDerived*)DatatypeFactory::POD2AT::createDouble(memMgr, (long)str->getLength(), context)->subtract(index, context)->add(one, context); } return Sequence(str->substring(index, subStrLength, context), memMgr); }