From 951d88394c5b3000ec55e9ee1f43c568dddc7b1c Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Thu, 26 Jan 2012 08:47:06 -0800 Subject: [PATCH] entity output --- tinyxml2.cpp | 36 +++++++++++++++++++++++++++++++++--- tinyxml2.h | 2 +- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 827bc36..a2d0878 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -628,12 +628,39 @@ void XMLStreamer::PrintSpace( int depth ) } -void XMLStreamer::PrintString( const char* ) +void XMLStreamer::PrintString( const char* p ) { + // Look for runs of bytes between entities to print. + const char* q = p; + while ( *q ) { + if ( *q < ENTITY_RANGE ) { + // Check for entities. If one is found, flush + // the stream up until the entity, write the + // entity, and keep looking. + if ( entityFlag[*q] ) { + while ( p < q ) { + fputc( *p, fp ); + ++p; + } + for( int i=0; i 0 ) { + fprintf( fp, "%s", p ); + } } - void XMLStreamer::OpenElement( const char* name, bool textParent ) { if ( elementJustOpened ) { @@ -645,6 +672,7 @@ void XMLStreamer::OpenElement( const char* name, bool textParent ) stack.Push( name ); text.Push( textParent ? "T" : "" ); + // fixme: can names have entities? fprintf( fp, "<%s", name ); elementJustOpened = true; ++depth; @@ -654,6 +682,7 @@ void XMLStreamer::OpenElement( const char* name, bool textParent ) void XMLStreamer::PushAttribute( const char* name, const char* value ) { TIXMLASSERT( elementJustOpened ); + // fixme: supports entities? fprintf( fp, " %s=\"%s\"", name, value ); } @@ -675,6 +704,7 @@ void XMLStreamer::CloseElement() if ( wasPositive == 0 ) { PrintSpace( depth ); } + // fixme can names have entities? fprintf( fp, "", name ); if ( text.NumPositive() == 0 ) { fprintf( fp, "\n" ); @@ -699,7 +729,7 @@ void XMLStreamer::PushText( const char* text ) if ( elementJustOpened ) { SealElement(); } - fprintf( fp, "%s", text ); + PrintString( text ); } diff --git a/tinyxml2.h b/tinyxml2.h index b6024bb..f48a5cf 100644 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -301,7 +301,7 @@ private: int depth; bool elementJustOpened; enum { - ENTITY_RANGE = 64, + ENTITY_RANGE = 64 }; bool entityFlag[ENTITY_RANGE];