peiyongz    2002/08/13 15:11:23

  Modified:    c/src/xercesc/util XMLBigInteger.hpp XMLBigInteger.cpp
                        XMLBigDecimal.hpp XMLBigDecimal.cpp
  Log:
  Fix to Bug#9442
  
  Revision  Changes    Path
  1.3       +15 -2     xml-xerces/c/src/xercesc/util/XMLBigInteger.hpp
  
  Index: XMLBigInteger.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLBigInteger.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLBigInteger.hpp 20 Feb 2002 18:17:02 -0000      1.2
  +++ XMLBigInteger.hpp 13 Aug 2002 22:11:23 -0000      1.3
  @@ -104,7 +104,7 @@
        *  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 @@
        //  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;
   
   };
   
  @@ -170,6 +175,14 @@
   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
  
  
  
  1.2       +15 -28    xml-xerces/c/src/xercesc/util/XMLBigInteger.cpp
  
  Index: XMLBigInteger.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLBigInteger.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLBigInteger.cpp 1 Feb 2002 22:22:14 -0000       1.1
  +++ XMLBigInteger.cpp 13 Aug 2002 22:11:23 -0000      1.2
  @@ -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 @@
         * 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 @@
           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);
   }
   
   /**
  @@ -324,33 +338,6 @@
   
       delete[] fMagnitude;
       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;
   }
   
   //
  
  
  
  1.3       +8 -2      xml-xerces/c/src/xercesc/util/XMLBigDecimal.hpp
  
  Index: XMLBigDecimal.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLBigDecimal.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLBigDecimal.hpp 20 Feb 2002 18:17:02 -0000      1.2
  +++ XMLBigDecimal.hpp 13 Aug 2002 22:11:23 -0000      1.3
  @@ -139,16 +139,22 @@
        //  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
  
  
  
  1.2       +20 -34    xml-xerces/c/src/xercesc/util/XMLBigDecimal.cpp
  
  Index: XMLBigDecimal.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLBigDecimal.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLBigDecimal.cpp 1 Feb 2002 22:22:14 -0000       1.1
  +++ XMLBigDecimal.cpp 13 Aug 2002 22:11:23 -0000      1.2
  @@ -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 @@
   
       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 @@
           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 @@
   }
   
   //
  -// 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);
   }
  -
  -//
  -//
  -//
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to