diff --git a/src/xercesc/util/XMLBigDecimal.cpp b/src/xercesc/util/XMLBigDecimal.cpp index 16b422cb01e17999191ebd30d35ebe0da1db5c7b..49696270add54b1460f5fbff07a86e8cba66c968 100644 --- a/src/xercesc/util/XMLBigDecimal.cpp +++ b/src/xercesc/util/XMLBigDecimal.cpp @@ -56,8 +56,11 @@ /* * $Log$ - * Revision 1.1 2002/02/01 22:22:14 peiyongz - * Initial revision + * Revision 1.2 2002/08/13 22:11:23 peiyongz + * Fix to Bug#9442 + * + * Revision 1.1.1.1 2002/02/01 22:22:14 peiyongz + * sane_include * * Revision 1.8 2001/08/08 18:33:44 peiyongz * fix: unresolved symbol warning for 'pow'. @@ -115,6 +118,7 @@ XMLBigDecimal::XMLBigDecimal(const XMLCh* const strValue) :fIntVal(0) ,fScale(0) +,fRawData(0) { if (!strValue) ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString); @@ -124,19 +128,23 @@ XMLBigDecimal::XMLBigDecimal(const XMLCh* const strValue) parseBigDecimal(strValue, ret_value, fScale); fIntVal = new XMLBigInteger(ret_value); + fRawData = XMLString::replicate(strValue); } XMLBigDecimal::XMLBigDecimal(const XMLBigDecimal& toCopy) :fIntVal(0) ,fScale(toCopy.getScale()) +,fRawData(0) { //invoke XMLBigInteger' copy ctor fIntVal = new XMLBigInteger(*(toCopy.getValue())); + fRawData = XMLString::replicate(toCopy.fRawData); } XMLBigDecimal::XMLBigDecimal(const XMLBigDecimal& toCopy, const int addExponent) :fIntVal(0) ,fScale(toCopy.getScale()) +,fRawData(0) { //invoke XMLBigInteger' copy ctor fIntVal = new XMLBigInteger(*(toCopy.getValue())); @@ -160,6 +168,17 @@ XMLBigDecimal::XMLBigDecimal(const XMLBigDecimal& toCopy, const int addExponent) fScale -= addExponent; //increase scale } + + // KNOWN defect + // We need to adjust the decimal point with respect to the addExponent. + // + // REVISIT: + // Since this ctor is only invoked by AbstractDoubleFloat::compareValues() + // to generate temporaries for comparison and destructed after that, + // no toString() would be applied to these temporaries, and therefore + // this defect does NOT matter, for now. + // + fRawData = XMLString::replicate(toCopy.fRawData); } /*** @@ -333,43 +352,10 @@ void XMLBigDecimal::reScale(unsigned int newScale) } // -// Add the decimal point as necessary // The caller needs to de-allocate the memory allocated by this function -// Deallocate the memory allocated by XMLBigInteger // XMLCh* XMLBigDecimal::toString() const { - // Retrieve a string (representing the value) from XMLBigInteger - // the returned buffer --ALWAYS-- contain a leading sign (+|-) - XMLCh* tmpBuf = fIntVal->toString(); - - // if no decimal point - if ( fScale == 0 ) - return tmpBuf; - - unsigned int strLen = XMLString::stringLen(tmpBuf); - - // - // Sanity check here, internal error - // fScale = strLen -> .(+|-)1234 invalid - // for now, do not insert decimal point and return - // - if ( fScale >= strLen ) - return tmpBuf; - - // Add decimal point as needed - XMLCh* retBuf = new XMLCh[strLen+2]; - XMLString::moveChars(&(retBuf[0]), &(tmpBuf[0]), strLen - fScale); - retBuf[strLen-fScale] = chPeriod; - XMLString::moveChars(&(retBuf[strLen-fScale+1]), &(tmpBuf[strLen-fScale]), fScale); - retBuf[strLen+1] = chNull; - - // De-allocate the memory allocated by XMLBigInteger - delete[] tmpBuf; - return retBuf; + return XMLString::replicate(fRawData); } -// -// -// - diff --git a/src/xercesc/util/XMLBigDecimal.hpp b/src/xercesc/util/XMLBigDecimal.hpp index 1dda2809693462e61482c880725d8b45dee07875..0e0d75dc84e90c592c56361a53a2189be52612e9 100644 --- a/src/xercesc/util/XMLBigDecimal.hpp +++ b/src/xercesc/util/XMLBigDecimal.hpp @@ -139,16 +139,22 @@ private: // fScale // the number of digits to the right of the decimal point // + // fRawData + // to preserve the original string used to construct this object, + // needed for pattern matching. + // // ----------------------------------------------------------------------- XMLBigInteger* fIntVal; unsigned int fScale; - + XMLCh* fRawData; }; inline XMLBigDecimal::~XMLBigDecimal() { delete fIntVal; + if (fRawData) + delete [] fRawData; } inline int XMLBigDecimal::getSign() const diff --git a/src/xercesc/util/XMLBigInteger.cpp b/src/xercesc/util/XMLBigInteger.cpp index db718916dddafae7385019aa02988750d7d3d07d..fcfc79a9ba761606faaec5c293f2b8c35073c0de 100644 --- a/src/xercesc/util/XMLBigInteger.cpp +++ b/src/xercesc/util/XMLBigInteger.cpp @@ -56,8 +56,11 @@ /* * $Log$ - * Revision 1.1 2002/02/01 22:22:14 peiyongz - * Initial revision + * Revision 1.2 2002/08/13 22:11:23 peiyongz + * Fix to Bug#9442 + * + * Revision 1.1.1.1 2002/02/01 22:22:14 peiyongz + * sane_include * * Revision 1.7 2001/08/23 11:54:26 tng * Add newline at the end and various typo fixes. @@ -200,7 +203,11 @@ void XMLBigInteger::parseBigInteger(const XMLCh* const toConvert * Any extraneous characters (including whitespace), * inclusive, will result in a NumberFormatException. */ + XMLBigInteger::XMLBigInteger(const XMLCh* const strValue) +:fSign(0) +,fMagnitude(0) +,fRawData(0) { if (!strValue) ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString); @@ -214,18 +221,25 @@ XMLBigInteger::XMLBigInteger(const XMLCh* const strValue) fMagnitude = XMLString::replicate(XMLUni::fgZeroLenString); else fMagnitude = XMLString::replicate(ret_value); + + fRawData = XMLString::replicate(strValue); } XMLBigInteger::~XMLBigInteger() { delete[] fMagnitude; + if (fRawData) + delete[] fRawData; } XMLBigInteger::XMLBigInteger(const XMLBigInteger& toCopy) +:fSign(toCopy.fSign) +,fMagnitude(0) +,fRawData(0) { - setSign(toCopy.getSign()); fMagnitude = XMLString::replicate(toCopy.fMagnitude); + fRawData = XMLString::replicate(toCopy.fRawData); } /** @@ -326,33 +340,6 @@ void XMLBigInteger::divide(const unsigned int byteToShift) fMagnitude = tmp; } -// -// The caller needs to de-allocate the memory allocated by this function -// return buffer ALWAYS has a leading sign -// -XMLCh* XMLBigInteger::toString() const -{ - - if ( fSign == 0 ) - { - XMLCh* retBuf = new XMLCh[3]; - retBuf[0] = chPlus; - retBuf[1] = chDigit_0; - retBuf[2] = chNull; - return retBuf; - } - - // Add the leading sign here - int strLen = XMLString::stringLen(fMagnitude); - XMLCh* retBuf = new XMLCh[strLen+2]; - - retBuf[0] = (fSign == 1) ? chPlus : chDash; - XMLString::moveChars(&(retBuf[1]), &(fMagnitude[0]), strLen); - retBuf[strLen+1] = chNull; - - return retBuf; -} - // // // diff --git a/src/xercesc/util/XMLBigInteger.hpp b/src/xercesc/util/XMLBigInteger.hpp index 8611c999971d940cf2582b7c2ad75867af460320..8d66bc1807d24cbc08c57526d4e100637f523f2a 100644 --- a/src/xercesc/util/XMLBigInteger.hpp +++ b/src/xercesc/util/XMLBigInteger.hpp @@ -104,7 +104,7 @@ public: * A leading sign is ALWAYS in place and the caller of this method * is responsible for the de-allocation of the memory. */ - XMLCh* toString() const; + inline XMLCh* toString() const; /** * Compares this object to the specified object. @@ -145,10 +145,15 @@ private: // fMagnitude // the buffer holding the number. // + // fRawData + // to preserve the original string used to construct this object, + // needed for pattern matching. + // // ----------------------------------------------------------------------- int fSign; XMLCh* fMagnitude; //null terminated + XMLCh* fRawData; }; @@ -172,4 +177,12 @@ inline void XMLBigInteger::setSign(int newSign) fSign = newSign; } +// +// The caller needs to de-allocate the memory allocated by this function +// +inline XMLCh* XMLBigInteger::toString() const +{ + return XMLString::replicate(fRawData); +} + #endif