Skip to content
Snippets Groups Projects
Commit 4104524e authored by PeiYong Zhang's avatar PeiYong Zhang
Browse files

Bug#11462: MemBufFormatTarget issue(2) .., proposed patch from

                     Esmond Pitt (pitte@anz.com)


git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@174116 13f79535-47bb-0310-9956-ffa450edef68
parent b9cf9ccf
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment