Exemplo n.º 1
0
XObjectPtr
FunctionSubstringBefore::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				/* context */,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const LocatorType*		/* locator */) const
{
	assert(arg1.null() == false && arg2.null() == false);

	const XalanDOMString&				theFirstString = arg1->str();

	const XalanDOMString::size_type		theFirstStringLength = length(theFirstString);

	if (theFirstStringLength == 0)
	{
		return createEmptyString(executionContext);
	}
	else
	{
		const XalanDOMString&				theSecondString = arg2->str();

		const XalanDOMString::size_type		theSecondStringLength = length(theSecondString);

		if (theSecondStringLength == 0)
		{
			return createEmptyString(executionContext);
		}
		else
		{
			const XalanDOMString::size_type		theIndex = indexOf(theFirstString,
													   theSecondString);

			if (theIndex == theFirstStringLength)
			{
				return createEmptyString(executionContext);
			}
			else
			{
				XPathExecutionContext::GetAndReleaseCachedString	theResult(executionContext);

				XalanDOMString&		theString = theResult.get();

				theString.assign(
						toCharArray(theFirstString),
						theIndex);

				// Create a string of the appropriate length...
				return executionContext.getXObjectFactory().createString(theResult);
			}
		}
	}
}
Exemplo n.º 2
0
UCSChar* evalString_pe  (pathExpr *pe,VTDNav *vn){
	exception e;
	int size = vn->contextBuf2->size ,a = -1;
	push2(vn);
	Try {
		a = evalNodeSet_pe(pe,vn);
		if (a != -1) {
			if (getTokenType(vn,a) == TOKEN_ATTR_NAME) {
				a++;
			}
			if (getTokenType(vn,a) == TOKEN_STARTING_TAG) {
				a = getText(vn);
			}
		}
	} Catch (e) {
	}
	vn->contextBuf2->size = size;
	reset_pe(pe,vn);
	pop2(vn);
	Try {
		if (a != -1)
			return toString(vn,a);
	} Catch (e) {
		if (e.et ==out_of_mem){
			Throw e;
		}
	}
	return createEmptyString();

}
Exemplo n.º 3
0
cString::cString(const uint64 number,
                 uint        base   /* = DefaultStringBase*/,
                 uint        optMem /* = DefaultStringPage*/) :
    m_buffer(NULL),
    m_stringLength(0)
{
    ASSERT_MSG(base < cChar::getStrlen(m_baseStrip),
               XSTL_STRING("cString: There isn't engouth strip for conversion operation."));

    // Init members
    createEmptyString(optMem);

    uint digit = 0;  // The digit to convert
    uint64 x   = 0;  // The left number

    x = number;

    if (number == 0)
    {
        *this = cString(m_baseStrip[0]);
    }

    // Start with converting
    while (x > 0)
    {
        digit = x % base;
        x     = x / base;

        *this = cString(m_baseStrip[digit]) + *this;
    }
}
Exemplo n.º 4
0
cString::cString(const character ch,
                 uint            optMem /* = DefaultStringPage*/) :
    m_buffer(NULL),
    m_stringLength(0)
{
    // Init the object
    createEmptyString(optMem);
    // Create a minidump array
    character buf[2] = {ch, cChar::getNullCharacter()};
    // Use operator = to copy to data (Avoids code-duplication)
    *this = cString(buf, optMem); // Create a cString with one character
}
Exemplo n.º 5
0
cString::cString(const character* string /* = NULL*/,
                 uint             optMem /* = DefaultStringPage*/) :
    m_buffer(NULL),
    m_stringLength(0)
{
    if (string == NULL)
    {
        // Creates an empty string
        createEmptyString(optMem);
    } else
    {
        // Construct a string and copy data
        m_stringLength = cChar::getStrlen(string);
        m_buffer = new cSArray<character>(m_stringLength + 1, optMem);

        // Copy the string
        cOS::memcpy(m_buffer->getBuffer(), string, m_stringLength * sizeof(character));
        // Add the null terminate string
        (*m_buffer)[m_stringLength] = cChar::getNullCharacter();
    }
}
Exemplo n.º 6
0
cString::cString(const int64 number,
                 uint        base   /* = DefaultStringBase*/,
                 uint        optMem /* = DefaultStringPage*/) :
    m_buffer(NULL),
    m_stringLength(0)
{
    // Init the object
    createEmptyString(optMem);

    // Covert the number into positive value
    uint64 nm = t_abs(number);

    /* Check sign */
    if (number < 0)
    {
        concat(m_stringNegativeInteger);
    }

    /* Covert the number into a string */
    cString positiveString(nm, base);
    concat(positiveString);
}
Exemplo n.º 7
0
cString::cString(const char* string,
                 uint        optMem /* = DefaultStringPage*/) :
    m_buffer(NULL),
    m_stringLength(0)
{
    if (string == NULL)
    {
        // Creates an empty string
        createEmptyString(optMem);
    } else
    {
        // Construct a string and copy data
        m_stringLength = (uint)strlen(string);
        m_buffer = new cSArray<character>(m_stringLength + 1, optMem);

        // Copy the string
        for (uint i = 0; i < m_stringLength; i++)
        {
            m_buffer->getBuffer()[i] = (character) string[i];
        }
        // Add the null terminate string
        (*m_buffer)[m_stringLength] = cChar::getNullCharacter();
    }
}
Exemplo n.º 8
0
XObjectPtr
FunctionSubstring::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				/* context */,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const XObjectPtr		arg3,
			const LocatorType*		/* locator */) const
{
	assert(arg1.null() == false && arg2.null() == false);	

	const XalanDOMString&				theSourceString = arg1->str();
	const XalanDOMString::size_type		theSourceStringLength = length(theSourceString);

	if (theSourceStringLength == 0)
	{
		return createEmptyString(executionContext);
	}
	else
	{
		// Get the value of the second argument...
		const double	theSecondArgValue =
			DoubleSupport::round(arg2->num());

		// XPath indexes from 1, so this is the first XPath index....
		const XalanDOMString::size_type		theStartIndex = getStartIndex(theSecondArgValue, theSourceStringLength);

		if (theStartIndex >= theSourceStringLength)
		{
			return createEmptyString(executionContext);
		}
		else
		{
			const double	theTotal =
				getTotal(theSourceStringLength, theSecondArgValue, arg3);

			if (DoubleSupport::isNaN(theSecondArgValue) == true ||
				DoubleSupport::isNaN(theTotal) == true ||
				DoubleSupport::isNegativeInfinity(theTotal) == true ||
				theTotal == 0.0 ||
				theTotal < double(theStartIndex))
			{
				return createEmptyString(executionContext);
			}
			else
			{
				const XalanDOMString::size_type		theSubstringLength =
					getSubstringLength(
						theSourceStringLength,
						theStartIndex,
						theTotal);

				XPathExecutionContext::GetAndReleaseCachedString	theResult(executionContext);

				XalanDOMString&		theString = theResult.get();

				assign(
						theString,
						toCharArray(theSourceString) + theStartIndex,
						theSubstringLength);

				return executionContext.getXObjectFactory().createString(theResult);
			}
		}
	}
}
XObjectPtr
FunctionSubstringAfter::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,
            const XObjectPtr        arg1,
            const XObjectPtr        arg2,
            const LocatorType*      /* locator */) const
{
    assert(arg1.null() == false && arg2.null() == false);

    const XalanDOMString&               theFirstString = arg1->str();

    const XalanDOMString::size_type     theFirstStringLength = length(theFirstString);

    if (theFirstStringLength == 0)
    {
        return createEmptyString(executionContext);
    }
    else
    {
        const XalanDOMString&   theSecondString = arg2->str();

        const XalanDOMString::size_type     theSecondStringLength = length(theSecondString);

        if (theSecondStringLength == 0)
        {
            return arg1;
        }
        else
        {
            const XalanDOMString::size_type     theIndex = indexOf(theFirstString,
                                                       theSecondString);

            if (theIndex == theFirstStringLength)
            {
                return createEmptyString(executionContext);
            }
            else
            {
                const XalanDOMString::size_type     theSecondStringLength = length(theSecondString);

                // Find the first character, which will be the offset of the index of the
                // beginning of the second string, plus the length of the second string.
                const XalanDOMChar* const   theFirstCharacter =
                    toCharArray(theFirstString) + theIndex + theSecondStringLength;

                // The remaining length is just the opposite -- the length of the string,
                // minus the index, minus the length of the second string.
                const XalanDOMString::size_type     theSubstringLength =
                    theFirstStringLength  - theIndex - theSecondStringLength;

                XPathExecutionContext::GetAndReleaseCachedString    theResult(executionContext);

                XalanDOMString&     theString = theResult.get();

                assign(
                        theString,
                        theFirstCharacter,
                        theSubstringLength);

                return executionContext.getXObjectFactory().createString(theResult);
            }
        }
    }
}