peiyongz    2002/08/12 14:38:22

  Modified:    c/src/xercesc/framework MemBufFormatTarget.hpp
                        MemBufFormatTarget.cpp
  Log:
  Bug#11462: MemBufFormatTarget issue(2) .., proposed patch from
                       Esmond Pitt ([EMAIL PROTECTED])
  
  Revision  Changes    Path
  1.4       +22 -6     xml-xerces/c/src/xercesc/framework/MemBufFormatTarget.hpp
  
  Index: MemBufFormatTarget.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/MemBufFormatTarget.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MemBufFormatTarget.hpp    22 Jul 2002 23:23:15 -0000      1.3
  +++ MemBufFormatTarget.hpp    12 Aug 2002 21:38:22 -0000      1.4
  @@ -57,6 +57,10 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.4  2002/08/12 21:38:22  peiyongz
  + * Bug#11462: MemBufFormatTarget issue(2) .., proposed patch from
  + *                      Esmond Pitt ([EMAIL PROTECTED])
  + *
    * Revision 1.3  2002/07/22 23:23:15  tng
    * DOM L3: MemBufFormatTarget stores fDataBuf as XMLByte directly, consistent 
design as MemBufInputSource
    *
  @@ -73,12 +77,29 @@
   
   #include <xercesc/framework/XMLFormatter.hpp>
   
  +     
  +/*
  + * The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code
  + * may plug into DOMWriter to retrieve the serialized XML stream (from DOM Tree)
  + * in a memory buffer.
  + *
  + * The MemBufFormatTarget is initalized to have a memory buffer of 1023 upon
  + * construction, which grows as needed. The buffer will be deleted when
  + * MemBufFormatTarget is destructed; or will be reset when the reset() function
  + * is called. 
  + *
  + * The MemBufFormatTarget returns a NULL terminated XMLByte stream upon request,
  + * through the method getRawBuffer(), and user should make its own copy of the 
  + * returned buffer if it intends to keep it independent on the state of the 
  + * MemBufFormatTarget.
  + */
  +
   class XMLPARSER_EXPORT MemBufFormatTarget : public XMLFormatTarget {
   public:
   
       /** @name constructors and destructor */
       //@{
  -    MemBufFormatTarget(int capacity = 1023) ;
  +    MemBufFormatTarget(int initCapacity = 1023) ;
       ~MemBufFormatTarget();
       //@}
   
  @@ -97,10 +118,6 @@
       /**
        * Returned the internal raw buffer.
        *
  -     * The MemBufFormatTarget object owns the buffer which will be deleted when
  -     * MemBufFormatTarget is destructed; or will be reset when the reset() function
  -     * is called.  User should make a copy of the returned buffer if intend to keep
  -     * it independent on the state of the MemBufFormatTarget.
        */
       //@}
       const XMLByte* getRawBuffer() const;
  
  
  
  1.4       +7 -12     xml-xerces/c/src/xercesc/framework/MemBufFormatTarget.cpp
  
  Index: MemBufFormatTarget.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/MemBufFormatTarget.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MemBufFormatTarget.cpp    22 Jul 2002 23:23:15 -0000      1.3
  +++ MemBufFormatTarget.cpp    12 Aug 2002 21:38:22 -0000      1.4
  @@ -57,6 +57,10 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.4  2002/08/12 21:38:22  peiyongz
  + * Bug#11462: MemBufFormatTarget issue(2) .., proposed patch from
  + *                      Esmond Pitt ([EMAIL PROTECTED])
  + *
    * Revision 1.3  2002/07/22 23:23:15  tng
    * DOM L3: MemBufFormatTarget stores fDataBuf as XMLByte directly, consistent 
design as MemBufInputSource
    *
  @@ -72,10 +76,10 @@
   #include <xercesc/util/XMLString.hpp>
   #include <string.h>
   
  -MemBufFormatTarget::MemBufFormatTarget(int capacity)
  +MemBufFormatTarget::MemBufFormatTarget(int initCapacity)
       : fDataBuf(0)
       , fIndex(0)
  -    , fCapacity(capacity)
  +    , fCapacity(initCapacity)
   {
       // Buffer is one larger than capacity, to allow for zero term
       fDataBuf = new XMLByte[fCapacity+4];
  @@ -93,13 +97,6 @@
                                     , const unsigned int   count
                                     , XMLFormatter * const formatter)
   {
  -    //
  -    // The toWrite may not be null terminated,
  -    // so we need to do some extra work here
  -    //
  -    XMLByte  lastChar = toWrite[count];   // preserve the last char
  -    XMLByte* tmpBuf   = (XMLByte *)toWrite;
  -    tmpBuf[count] = 0;
   
       if (count) {
           insureCapacity(count);
  @@ -107,7 +104,6 @@
           fIndex += count;
       }
   
  -    tmpBuf[count] = lastChar;             // restore the last char
   }
   
   const XMLByte* MemBufFormatTarget::getRawBuffer() const
  @@ -138,7 +134,7 @@
           return;
   
       // Oops, not enough room. Calc new capacity and allocate new buffer
  -    const unsigned int newCap = (unsigned int)((fIndex + extraNeeded) * 1.25);
  +    const unsigned int newCap = (unsigned int)((fIndex + extraNeeded) * 2);
       XMLByte* newBuf = new XMLByte[newCap+4];
   
       // Copy over the old stuff
  
  
  

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

Reply via email to