diff --git a/src/xercesc/framework/MemBufFormatTarget.cpp b/src/xercesc/framework/MemBufFormatTarget.cpp index 697e1197cdb5f0255abed6e0435e3b836cf0c17f..863267350bf97af2c34ac9a0f1c29e850afeffc7 100644 --- a/src/xercesc/framework/MemBufFormatTarget.cpp +++ b/src/xercesc/framework/MemBufFormatTarget.cpp @@ -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 (pitte@anz.com) + * * 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 @@ void MemBufFormatTarget::writeChars(const XMLByte* const toWrite , 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 @@ void MemBufFormatTarget::writeChars(const XMLByte* const toWrite fIndex += count; } - tmpBuf[count] = lastChar; // restore the last char } const XMLByte* MemBufFormatTarget::getRawBuffer() const @@ -138,7 +134,7 @@ void MemBufFormatTarget::insureCapacity(const unsigned int extraNeeded) 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 diff --git a/src/xercesc/framework/MemBufFormatTarget.hpp b/src/xercesc/framework/MemBufFormatTarget.hpp index b77bbd999ca4c64b2abf8a0ee60f8be7c712cf90..b2e608d0d24c4d3cf91b36eb645dd6211f0de5a2 100644 --- a/src/xercesc/framework/MemBufFormatTarget.hpp +++ b/src/xercesc/framework/MemBufFormatTarget.hpp @@ -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 (pitte@anz.com) + * * 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 @@ public: /** * 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;