Esempio n. 1
0
void XMLAbstractDoubleFloat::init(const XMLCh* const strValue)
{
    if ((!strValue) || (!*strValue))
        ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager);

    fRawData = XMLString::replicate(strValue, fMemoryManager);   // preserve the raw data form

    XMLCh* tmpStrValue = XMLString::replicate(strValue, fMemoryManager);
    ArrayJanitor<XMLCh> janTmpName(tmpStrValue, fMemoryManager);
    XMLString::trim(tmpStrValue);

    normalizeZero(tmpStrValue);

    if (XMLString::equals(tmpStrValue, XMLUni::fgNegINFString) )
    {
        fType = NegINF;
        fSign = -1;
    }
    else if (XMLString::equals(tmpStrValue, XMLUni::fgPosINFString) )
    {
        fType = PosINF;
        fSign = 1;
    }
    else if (XMLString::equals(tmpStrValue, XMLUni::fgNaNString) )
    {
        fType = NaN;
        fSign = 1;
    }
    else
        //
        // Normal case
        //
    {
        checkBoundary(tmpStrValue);
    }

}
void XMLAbstractDoubleFloat::init(const XMLCh* const strValue)
{
    if ((!strValue) || (!*strValue))
        ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager);

    fRawData = XMLString::replicate(strValue, fMemoryManager);   // preserve the raw data form

    XMLCh* tmpStrValue = XMLString::replicate(strValue, fMemoryManager);
    ArrayJanitor<XMLCh> janTmpName(tmpStrValue, fMemoryManager);
    XMLString::trim(tmpStrValue);

    if (!*tmpStrValue) 
        ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager);

    normalizeZero(tmpStrValue);

    if (XMLString::equals(tmpStrValue, XMLUni::fgNegINFString) )
    {
        fType = NegINF;
        fSign = -1;
    }
    else if (XMLString::equals(tmpStrValue, XMLUni::fgPosINFString) )
    {
        fType = PosINF;
        fSign = 1;
    }
    else if (XMLString::equals(tmpStrValue, XMLUni::fgNaNString) )
    {
        fType = NaN;
        fSign = 1;
    }
    else
        //
        // Normal case
        //
    {
        // Use a stack-based buffer when possible.  Since all
        // valid doubles or floats will only contain ASCII
        // digits, a decimal point,  or the exponent character,
        // they will all be single byte characters, and this will
        // work.
        static const unsigned int  maxStackSize = 100;

        const unsigned int  lenTempStrValue =
            XMLString::stringLen(tmpStrValue);

        if (lenTempStrValue < maxStackSize)
        {
            char    buffer[maxStackSize + 1];

            XMLString::transcode(
                tmpStrValue,
                buffer,
                sizeof(buffer) - 1,
                getMemoryManager());

            // Do this for safety, because we've
            // no guarantee we didn't overrun the
            // capacity of the buffer when transcoding
            // a bogus value.
            buffer[maxStackSize] = '\0';

            // If they aren't the same length, then some
            // non-ASCII multibyte character was present.
            // This will only happen in the case where the
            // string has a bogus character, and it's long
            // enough to overrun this buffer, but we need
            // to check, even if it's unlikely to happen.
            if (XMLString::stringLen(buffer) != lenTempStrValue)
            {
                ThrowXMLwithMemMgr(
                    NumberFormatException,
                    XMLExcepts::XMLNUM_Inv_chars,
                    getMemoryManager());
            }

            checkBoundary(buffer);
        }
        else
        {
            char *nptr = XMLString::transcode(tmpStrValue, getMemoryManager());
            const ArrayJanitor<char> janStr(nptr, fMemoryManager);

            checkBoundary(nptr);
        }
    }

}