From 6a514399c2fa3e384dc6ef2e8ffe645141194431 Mon Sep 17 00:00:00 2001 From: Chow Loong Jin Date: Thu, 26 Mar 2020 16:30:37 +0800 Subject: [PATCH] XMLPrinter: Fix first line indentation Fix indentation of first line when called with !compactMode. --- tinyxml2.cpp | 42 +++++++++++++++++++----------------------- tinyxml2.h | 5 +++++ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index d803b14..e0297c5 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -2659,22 +2659,33 @@ void XMLPrinter::PushHeader( bool writeBOM, bool writeDec ) } } - -void XMLPrinter::OpenElement( const char* name, bool compactMode ) +void XMLPrinter::PrepareForNewNode( bool compactMode ) { SealElementIfJustOpened(); - _stack.Push( name ); - if ( _textDepth < 0 && !_firstElement && !compactMode ) { + if ( compactMode ) { + return; + } + + if ( _firstElement ) { + PrintSpace (_depth); + } else if ( _textDepth < 0) { Putc( '\n' ); PrintSpace( _depth ); } + _firstElement = false; +} + +void XMLPrinter::OpenElement( const char* name, bool compactMode ) +{ + PrepareForNewNode( compactMode ); + _stack.Push( name ); + Write ( "<" ); Write ( name ); _elementJustOpened = true; - _firstElement = false; ++_depth; } @@ -2850,12 +2861,7 @@ void XMLPrinter::PushText( double value ) void XMLPrinter::PushComment( const char* comment ) { - SealElementIfJustOpened(); - if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Putc( '\n' ); - PrintSpace( _depth ); - } - _firstElement = false; + PrepareForNewNode( _compactMode ); Write( "