Merge branch 'uliwitness-overridecompactmode'

This commit is contained in:
Lee Thomason 2014-02-23 21:08:22 -08:00
commit 6324acd9f9
2 changed files with 15 additions and 11 deletions

View File

@ -1940,17 +1940,17 @@ void XMLPrinter::PushHeader( bool writeBOM, bool writeDec )
} }
void XMLPrinter::OpenElement( const char* name ) void XMLPrinter::OpenElement( const char* name, bool compactMode )
{ {
if ( _elementJustOpened ) { if ( _elementJustOpened ) {
SealElement(); SealElement();
} }
_stack.Push( name ); _stack.Push( name );
if ( _textDepth < 0 && !_firstElement && !_compactMode ) { if ( _textDepth < 0 && !_firstElement && !compactMode ) {
Print( "\n" ); Print( "\n" );
} }
if ( !_compactMode ) { if ( !compactMode ) {
PrintSpace( _depth ); PrintSpace( _depth );
} }
@ -2002,7 +2002,7 @@ void XMLPrinter::PushAttribute( const char* name, double v )
} }
void XMLPrinter::CloseElement() void XMLPrinter::CloseElement( bool compactMode )
{ {
--_depth; --_depth;
const char* name = _stack.Pop(); const char* name = _stack.Pop();
@ -2011,7 +2011,7 @@ void XMLPrinter::CloseElement()
Print( "/>" ); Print( "/>" );
} }
else { else {
if ( _textDepth < 0 && !_compactMode) { if ( _textDepth < 0 && !compactMode) {
Print( "\n" ); Print( "\n" );
PrintSpace( _depth ); PrintSpace( _depth );
} }
@ -2021,7 +2021,7 @@ void XMLPrinter::CloseElement()
if ( _textDepth == _depth ) { if ( _textDepth == _depth ) {
_textDepth = -1; _textDepth = -1;
} }
if ( _depth == 0 && !_compactMode) { if ( _depth == 0 && !compactMode) {
Print( "\n" ); Print( "\n" );
} }
_elementJustOpened = false; _elementJustOpened = false;
@ -2146,7 +2146,9 @@ bool XMLPrinter::VisitEnter( const XMLDocument& doc )
bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
{ {
OpenElement( element.Name() ); const XMLElement* parentElem = element.Parent()->ToElement();
bool compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;
OpenElement( element.Name(), compactMode );
while ( attribute ) { while ( attribute ) {
PushAttribute( attribute->Name(), attribute->Value() ); PushAttribute( attribute->Name(), attribute->Value() );
attribute = attribute->Next(); attribute = attribute->Next();
@ -2155,9 +2157,9 @@ bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attr
} }
bool XMLPrinter::VisitExit( const XMLElement& ) bool XMLPrinter::VisitExit( const XMLElement& element )
{ {
CloseElement(); CloseElement( CompactMode(element) );
return true; return true;
} }

View File

@ -1967,7 +1967,7 @@ public:
/** If streaming, start writing an element. /** If streaming, start writing an element.
The element must be closed with CloseElement() The element must be closed with CloseElement()
*/ */
void OpenElement( const char* name ); void OpenElement( const char* name, bool compactMode );
/// If streaming, add an attribute to an open element. /// If streaming, add an attribute to an open element.
void PushAttribute( const char* name, const char* value ); void PushAttribute( const char* name, const char* value );
void PushAttribute( const char* name, int value ); void PushAttribute( const char* name, int value );
@ -1975,7 +1975,7 @@ public:
void PushAttribute( const char* name, bool value ); void PushAttribute( const char* name, bool value );
void PushAttribute( const char* name, double value ); void PushAttribute( const char* name, double value );
/// If streaming, close the Element. /// If streaming, close the Element.
virtual void CloseElement(); virtual void CloseElement( bool compactMode );
/// Add a text node. /// Add a text node.
void PushText( const char* text, bool cdata=false ); void PushText( const char* text, bool cdata=false );
@ -2034,6 +2034,8 @@ public:
} }
protected: protected:
virtual bool CompactMode( const XMLElement& ) { return _compactMode; };
/** Prints out the space before an element. You may override to change /** Prints out the space before an element. You may override to change
the space and tabs used. A PrintSpace() override should call Print(). the space and tabs used. A PrintSpace() override should call Print().
*/ */