|
@@ -548,14 +548,22 @@ void XMLDocument::SetError( int error, const char* str1, const char* str2 )
|
|
|
|
|
|
|
|
StringStack::StringStack()
|
|
StringStack::StringStack()
|
|
|
{
|
|
{
|
|
|
- mem = new char[INIT];
|
|
|
|
|
- *mem = 0;
|
|
|
|
|
|
|
+ *pool = 0;
|
|
|
|
|
+ mem = pool;
|
|
|
inUse = 1; // always has a null
|
|
inUse = 1; // always has a null
|
|
|
allocated = INIT;
|
|
allocated = INIT;
|
|
|
nPositive = 0;
|
|
nPositive = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+StringStack::~StringStack()
|
|
|
|
|
+{
|
|
|
|
|
+ if ( mem != pool ) {
|
|
|
|
|
+ delete [] mem;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
void StringStack::Push( const char* str ) {
|
|
void StringStack::Push( const char* str ) {
|
|
|
int needed = strlen( str ) + 1;
|
|
int needed = strlen( str ) + 1;
|
|
|
if ( needed > 1 )
|
|
if ( needed > 1 )
|
|
@@ -567,7 +575,9 @@ void StringStack::Push( const char* str ) {
|
|
|
|
|
|
|
|
char* newMem = new char[more];
|
|
char* newMem = new char[more];
|
|
|
memcpy( newMem, mem, inUse );
|
|
memcpy( newMem, mem, inUse );
|
|
|
- delete [] mem;
|
|
|
|
|
|
|
+ if ( mem != pool ) {
|
|
|
|
|
+ delete [] mem;
|
|
|
|
|
+ }
|
|
|
mem = newMem;
|
|
mem = newMem;
|
|
|
}
|
|
}
|
|
|
strcpy( mem+inUse, str );
|
|
strcpy( mem+inUse, str );
|
|
@@ -608,10 +618,12 @@ void XMLStreamer::OpenElement( const char* name, bool textParent )
|
|
|
if ( elementJustOpened ) {
|
|
if ( elementJustOpened ) {
|
|
|
SealElement();
|
|
SealElement();
|
|
|
}
|
|
}
|
|
|
|
|
+ if ( text.NumPositive() == 0 ) {
|
|
|
|
|
+ PrintSpace( depth );
|
|
|
|
|
+ }
|
|
|
stack.Push( name );
|
|
stack.Push( name );
|
|
|
text.Push( textParent ? "T" : "" );
|
|
text.Push( textParent ? "T" : "" );
|
|
|
|
|
|
|
|
- PrintSpace( depth );
|
|
|
|
|
fprintf( fp, "<%s", name );
|
|
fprintf( fp, "<%s", name );
|
|
|
elementJustOpened = true;
|
|
elementJustOpened = true;
|
|
|
++depth;
|
|
++depth;
|
|
@@ -629,6 +641,7 @@ void XMLStreamer::CloseElement()
|
|
|
{
|
|
{
|
|
|
--depth;
|
|
--depth;
|
|
|
const char* name = stack.Pop();
|
|
const char* name = stack.Pop();
|
|
|
|
|
+ int wasPositive = text.NumPositive();
|
|
|
text.Pop();
|
|
text.Pop();
|
|
|
|
|
|
|
|
if ( elementJustOpened ) {
|
|
if ( elementJustOpened ) {
|
|
@@ -638,7 +651,9 @@ void XMLStreamer::CloseElement()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- PrintSpace( depth );
|
|
|
|
|
|
|
+ if ( wasPositive == 0 ) {
|
|
|
|
|
+ PrintSpace( depth );
|
|
|
|
|
+ }
|
|
|
fprintf( fp, "</%s>", name );
|
|
fprintf( fp, "</%s>", name );
|
|
|
if ( text.NumPositive() == 0 ) {
|
|
if ( text.NumPositive() == 0 ) {
|
|
|
fprintf( fp, "\n" );
|
|
fprintf( fp, "\n" );
|