remove trailing spaces

This commit is contained in:
Lee Thomason (grinliz) 2012-09-16 11:32:34 -07:00
parent 6da5410110
commit 2f1f6247e0
3 changed files with 139 additions and 139 deletions

View File

@ -70,7 +70,7 @@ struct Entity {
}; };
static const int NUM_ENTITIES = 5; static const int NUM_ENTITIES = 5;
static const Entity entities[NUM_ENTITIES] = static const Entity entities[NUM_ENTITIES] =
{ {
{ "quot", 4, DOUBLE_QUOTE }, { "quot", 4, DOUBLE_QUOTE },
{ "amp", 3, '&' }, { "amp", 3, '&' },
@ -123,7 +123,7 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags )
return p + length; return p + length;
} }
++p; ++p;
} }
return 0; return 0;
} }
@ -137,7 +137,7 @@ char* StrPair::ParseName( char* p )
} }
while( *p && ( while( *p && (
XMLUtil::IsAlphaNum( (unsigned char) *p ) XMLUtil::IsAlphaNum( (unsigned char) *p )
|| *p == '_' || *p == '_'
|| *p == ':' || *p == ':'
|| (*p == '-' && p>start ) // can be in a name, but not lead it. || (*p == '-' && p>start ) // can be in a name, but not lead it.
@ -166,7 +166,7 @@ void StrPair::CollapseWhitespace()
while( *p ) { while( *p ) {
if ( XMLUtil::IsWhiteSpace( *p )) { if ( XMLUtil::IsWhiteSpace( *p )) {
p = XMLUtil::SkipWhiteSpace( p ); p = XMLUtil::SkipWhiteSpace( p );
if ( *p == 0 ) if ( *p == 0 )
break; // don't write to q; this trims the trailing space. break; // don't write to q; this trims the trailing space.
*q = ' '; *q = ' ';
++q; ++q;
@ -231,7 +231,7 @@ const char* StrPair::GetStr()
int i=0; int i=0;
for(; i<NUM_ENTITIES; ++i ) { for(; i<NUM_ENTITIES; ++i ) {
if ( strncmp( p+1, entities[i].pattern, entities[i].length ) == 0 if ( strncmp( p+1, entities[i].pattern, entities[i].length ) == 0
&& *(p+entities[i].length+1) == ';' ) && *(p+entities[i].length+1) == ';' )
{ {
// Found an entity convert; // Found an entity convert;
*q = entities[i].value; *q = entities[i].value;
@ -275,9 +275,9 @@ const char* XMLUtil::ReadBOM( const char* p, bool* bom )
*bom = false; *bom = false;
const unsigned char* pu = reinterpret_cast<const unsigned char*>(p); const unsigned char* pu = reinterpret_cast<const unsigned char*>(p);
// Check for BOM: // Check for BOM:
if ( *(pu+0) == TIXML_UTF_LEAD_0 if ( *(pu+0) == TIXML_UTF_LEAD_0
&& *(pu+1) == TIXML_UTF_LEAD_1 && *(pu+1) == TIXML_UTF_LEAD_1
&& *(pu+2) == TIXML_UTF_LEAD_2 ) && *(pu+2) == TIXML_UTF_LEAD_2 )
{ {
*bom = true; *bom = true;
p += 3; p += 3;
@ -292,7 +292,7 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length
const unsigned long BYTE_MARK = 0x80; const unsigned long BYTE_MARK = 0x80;
const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
if (input < 0x80) if (input < 0x80)
*length = 1; *length = 1;
else if ( input < 0x800 ) else if ( input < 0x800 )
*length = 2; *length = 2;
@ -306,22 +306,22 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length
output += *length; output += *length;
// Scary scary fall throughs. // Scary scary fall throughs.
switch (*length) switch (*length)
{ {
case 4: case 4:
--output; --output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK); *output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6; input >>= 6;
case 3: case 3:
--output; --output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK); *output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6; input >>= 6;
case 2: case 2:
--output; --output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK); *output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6; input >>= 6;
case 1: case 1:
--output; --output;
*output = (char)(input | FIRST_BYTE_MARK[*length]); *output = (char)(input | FIRST_BYTE_MARK[*length]);
} }
} }
@ -359,7 +359,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
ucs += mult * (*q - 'a' + 10); ucs += mult * (*q - 'a' + 10);
else if ( *q >= 'A' && *q <= 'F' ) else if ( *q >= 'A' && *q <= 'F' )
ucs += mult * (*q - 'A' + 10 ); ucs += mult * (*q - 'A' + 10 );
else else
return 0; return 0;
mult *= 16; mult *= 16;
--q; --q;
@ -382,7 +382,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
{ {
if ( *q >= '0' && *q <= '9' ) if ( *q >= '0' && *q <= '9' )
ucs += mult * (*q - '0'); ucs += mult * (*q - '0');
else else
return 0; return 0;
mult *= 10; mult *= 10;
--q; --q;
@ -396,33 +396,33 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
} }
void XMLUtil::ToStr( int v, char* buffer, int bufferSize ) void XMLUtil::ToStr( int v, char* buffer, int bufferSize )
{ {
TIXML_SNPRINTF( buffer, bufferSize, "%d", v ); TIXML_SNPRINTF( buffer, bufferSize, "%d", v );
} }
void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize ) void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize )
{ {
TIXML_SNPRINTF( buffer, bufferSize, "%u", v ); TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
} }
void XMLUtil::ToStr( bool v, char* buffer, int bufferSize ) void XMLUtil::ToStr( bool v, char* buffer, int bufferSize )
{ {
TIXML_SNPRINTF( buffer, bufferSize, "%d", v ? 1 : 0 ); TIXML_SNPRINTF( buffer, bufferSize, "%d", v ? 1 : 0 );
} }
void XMLUtil::ToStr( float v, char* buffer, int bufferSize ) void XMLUtil::ToStr( float v, char* buffer, int bufferSize )
{ {
TIXML_SNPRINTF( buffer, bufferSize, "%f", v ); TIXML_SNPRINTF( buffer, bufferSize, "%f", v );
} }
void XMLUtil::ToStr( double v, char* buffer, int bufferSize ) void XMLUtil::ToStr( double v, char* buffer, int bufferSize )
{ {
TIXML_SNPRINTF( buffer, bufferSize, "%f", v ); TIXML_SNPRINTF( buffer, bufferSize, "%f", v );
} }
@ -476,7 +476,7 @@ bool XMLUtil::ToDouble( const char* str, double* value )
} }
char* XMLDocument::Identify( char* p, XMLNode** node ) char* XMLDocument::Identify( char* p, XMLNode** node )
{ {
XMLNode* returnNode = 0; XMLNode* returnNode = 0;
char* start = p; char* start = p;
@ -486,7 +486,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
return p; return p;
} }
// What is this thing? // What is this thing?
// - Elements start with a letter or underscore, but xml is reserved. // - Elements start with a letter or underscore, but xml is reserved.
// - Comments: <!-- // - Comments: <!--
// - Decleration: <? // - Decleration: <?
@ -600,7 +600,7 @@ void XMLNode::DeleteChildren()
while( firstChild ) { while( firstChild ) {
XMLNode* node = firstChild; XMLNode* node = firstChild;
Unlink( node ); Unlink( node );
DELETE_NODE( node ); DELETE_NODE( node );
} }
firstChild = lastChild = 0; firstChild = lastChild = 0;
@ -610,9 +610,9 @@ void XMLNode::DeleteChildren()
void XMLNode::Unlink( XMLNode* child ) void XMLNode::Unlink( XMLNode* child )
{ {
TIXMLASSERT( child->parent == this ); TIXMLASSERT( child->parent == this );
if ( child == firstChild ) if ( child == firstChild )
firstChild = firstChild->next; firstChild = firstChild->next;
if ( child == lastChild ) if ( child == lastChild )
lastChild = lastChild->prev; lastChild = lastChild->prev;
if ( child->prev ) { if ( child->prev ) {
@ -731,8 +731,8 @@ const XMLElement* XMLNode::LastChildElement( const char* value ) const
const XMLElement* XMLNode::NextSiblingElement( const char* value ) const const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
{ {
for( XMLNode* element=this->next; element; element = element->next ) { for( XMLNode* element=this->next; element; element = element->next ) {
if ( element->ToElement() if ( element->ToElement()
&& (!value || XMLUtil::StringEqual( value, element->Value() ))) && (!value || XMLUtil::StringEqual( value, element->Value() )))
{ {
return element->ToElement(); return element->ToElement();
} }
@ -745,7 +745,7 @@ const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const
{ {
for( XMLNode* element=this->prev; element; element = element->prev ) { for( XMLNode* element=this->prev; element; element = element->prev ) {
if ( element->ToElement() if ( element->ToElement()
&& (!value || XMLUtil::StringEqual( value, element->Value() ))) && (!value || XMLUtil::StringEqual( value, element->Value() )))
{ {
return element->ToElement(); return element->ToElement();
} }
@ -765,11 +765,11 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
// <foo> // <foo>
// </foo> // </foo>
// <!-- comment --> // <!-- comment -->
// //
// Where the closing element (/foo) *must* be the next thing after the opening // Where the closing element (/foo) *must* be the next thing after the opening
// element, and the names must match. BUT the tricky bit is that the closing // element, and the names must match. BUT the tricky bit is that the closing
// element will be read by the child. // element will be read by the child.
// //
// 'endTag' is the end tag for this node, it is returned by a call to a child. // 'endTag' is the end tag for this node, it is returned by a call to a child.
// 'parentEnd' is the end tag for the parent, which is filled in and returned. // 'parentEnd' is the end tag for the parent, which is filled in and returned.
@ -814,7 +814,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
p = 0; p = 0;
} }
else if ( !endTag.Empty() ) { else if ( !endTag.Empty() ) {
if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) { if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) {
document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
p = 0; p = 0;
} }
@ -1177,10 +1177,10 @@ const XMLAttribute* XMLElement::FindAttribute( const char* name ) const
const char* XMLElement::Attribute( const char* name, const char* value ) const const char* XMLElement::Attribute( const char* name, const char* value ) const
{ {
const XMLAttribute* a = FindAttribute( name ); const XMLAttribute* a = FindAttribute( name );
if ( !a ) if ( !a )
return 0; return 0;
if ( !value || XMLUtil::StringEqual( a->Value(), value )) if ( !value || XMLUtil::StringEqual( a->Value(), value ))
return a->Value(); return a->Value();
return 0; return 0;
@ -1269,7 +1269,7 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
for( attrib = rootAttribute; for( attrib = rootAttribute;
attrib; attrib;
last = attrib, attrib = attrib->next ) last = attrib, attrib = attrib->next )
{ {
if ( XMLUtil::StringEqual( attrib->Name(), name ) ) { if ( XMLUtil::StringEqual( attrib->Name(), name ) ) {
break; break;
} }
@ -1337,12 +1337,12 @@ char* XMLElement::ParseAttributes( char* p )
// attribute will be doubly added. However, tracking the 'prevAttribute' // attribute will be doubly added. However, tracking the 'prevAttribute'
// avoids re-scanning the attribute list. Preferring performance for // avoids re-scanning the attribute list. Preferring performance for
// now, may reconsider in the future. // now, may reconsider in the future.
if ( prevAttribute ) { if ( prevAttribute ) {
prevAttribute->next = attrib; prevAttribute->next = attrib;
} }
else { else {
rootAttribute = attrib; rootAttribute = attrib;
} }
prevAttribute = attrib; prevAttribute = attrib;
} }
// end of the tag // end of the tag
@ -1386,7 +1386,7 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair )
if ( value.Empty() ) return 0; if ( value.Empty() ) return 0;
p = ParseAttributes( p ); p = ParseAttributes( p );
if ( !p || !*p || closingType ) if ( !p || !*p || closingType )
return p; return p;
p = XMLNode::ParseDeep( p, strPair ); p = XMLNode::ParseDeep( p, strPair );
@ -1422,7 +1422,7 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) const
} }
a = a->Next(); a = a->Next();
b = b->Next(); b = b->Next();
} }
if ( a || b ) { if ( a || b ) {
// different count // different count
return false; return false;
@ -1435,7 +1435,7 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) const
bool XMLElement::Accept( XMLVisitor* visitor ) const bool XMLElement::Accept( XMLVisitor* visitor ) const
{ {
if ( visitor->VisitEnter( *this, rootAttribute ) ) if ( visitor->VisitEnter( *this, rootAttribute ) )
{ {
for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() )
{ {
@ -1560,7 +1560,7 @@ int XMLDocument::LoadFile( const char* filename )
} }
int XMLDocument::LoadFile( FILE* fp ) int XMLDocument::LoadFile( FILE* fp )
{ {
DeleteChildren(); DeleteChildren();
InitDocument(); InitDocument();
@ -1579,7 +1579,7 @@ int XMLDocument::LoadFile( FILE* fp )
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return errorID; return errorID;
} }
charBuffer[size] = 0; charBuffer[size] = 0;
const char* p = charBuffer; const char* p = charBuffer;
@ -1642,13 +1642,13 @@ int XMLDocument::Parse( const char* p )
charBuffer = new char[ len+1 ]; charBuffer = new char[ len+1 ];
memcpy( charBuffer, p, len+1 ); memcpy( charBuffer, p, len+1 );
ParseDeep( charBuffer, 0 ); ParseDeep( charBuffer, 0 );
return errorID; return errorID;
} }
void XMLDocument::Print( XMLPrinter* streamer ) void XMLDocument::Print( XMLPrinter* streamer )
{ {
XMLPrinter stdStreamer( stdout ); XMLPrinter stdStreamer( stdout );
if ( !streamer ) if ( !streamer )
@ -1665,13 +1665,13 @@ void XMLDocument::SetError( int error, const char* str1, const char* str2 )
} }
void XMLDocument::PrintError() const void XMLDocument::PrintError() const
{ {
if ( errorID ) { if ( errorID ) {
static const int LEN = 20; static const int LEN = 20;
char buf1[LEN] = { 0 }; char buf1[LEN] = { 0 };
char buf2[LEN] = { 0 }; char buf2[LEN] = { 0 };
if ( errorStr1 ) { if ( errorStr1 ) {
TIXML_SNPRINTF( buf1, LEN, "%s", errorStr1 ); TIXML_SNPRINTF( buf1, LEN, "%s", errorStr1 );
} }
@ -1685,11 +1685,11 @@ void XMLDocument::PrintError() const
} }
XMLPrinter::XMLPrinter( FILE* file, bool compact ) : XMLPrinter::XMLPrinter( FILE* file, bool compact ) :
elementJustOpened( false ), elementJustOpened( false ),
firstElement( true ), firstElement( true ),
fp( file ), fp( file ),
depth( 0 ), depth( 0 ),
textDepth( -1 ), textDepth( -1 ),
processEntities( true ), processEntities( true ),
compactMode( compact ) compactMode( compact )
@ -1738,7 +1738,7 @@ void XMLPrinter::Print( const char* format, ... )
int len = vsnprintf( 0, 0, format, va ); int len = vsnprintf( 0, 0, format, va );
// Close out and re-start the va-args // Close out and re-start the va-args
va_end( va ); va_end( va );
va_start( va, format ); va_start( va, format );
char* p = buffer.PushArr( len ) - 1; char* p = buffer.PushArr( len ) - 1;
vsnprintf( p, len+1, format, va ); vsnprintf( p, len+1, format, va );
#endif #endif
@ -1766,7 +1766,7 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
// Remember, char is sometimes signed. (How many times has that bitten me?) // Remember, char is sometimes signed. (How many times has that bitten me?)
if ( *q > 0 && *q < ENTITY_RANGE ) { if ( *q > 0 && *q < ENTITY_RANGE ) {
// Check for entities. If one is found, flush // Check for entities. If one is found, flush
// the stream up until the entity, write the // the stream up until the entity, write the
// entity, and keep looking. // entity, and keep looking.
if ( flag[(unsigned)(*q)] ) { if ( flag[(unsigned)(*q)] ) {
while ( p < q ) { while ( p < q ) {
@ -1913,7 +1913,7 @@ void XMLPrinter::PushText( const char* text, bool cdata )
} }
} }
void XMLPrinter::PushText( int value ) void XMLPrinter::PushText( int value )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE ); XMLUtil::ToStr( value, buf, BUF_SIZE );
@ -1921,7 +1921,7 @@ void XMLPrinter::PushText( int value )
} }
void XMLPrinter::PushText( unsigned value ) void XMLPrinter::PushText( unsigned value )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE ); XMLUtil::ToStr( value, buf, BUF_SIZE );
@ -1929,7 +1929,7 @@ void XMLPrinter::PushText( unsigned value )
} }
void XMLPrinter::PushText( bool value ) void XMLPrinter::PushText( bool value )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE ); XMLUtil::ToStr( value, buf, BUF_SIZE );
@ -1937,7 +1937,7 @@ void XMLPrinter::PushText( bool value )
} }
void XMLPrinter::PushText( float value ) void XMLPrinter::PushText( float value )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE ); XMLUtil::ToStr( value, buf, BUF_SIZE );
@ -1945,7 +1945,7 @@ void XMLPrinter::PushText( float value )
} }
void XMLPrinter::PushText( double value ) void XMLPrinter::PushText( double value )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( value, buf, BUF_SIZE ); XMLUtil::ToStr( value, buf, BUF_SIZE );

View File

@ -40,7 +40,7 @@ distribution.
#include <cstdarg> #include <cstdarg>
#endif #endif
/* /*
TODO: intern strings instead of allocation. TODO: intern strings instead of allocation.
*/ */
/* /*
@ -74,9 +74,9 @@ distribution.
/*int _snprintf_s( /*int _snprintf_s(
char *buffer, char *buffer,
size_t sizeOfBuffer, size_t sizeOfBuffer,
size_t count, size_t count,
const char *format [, const char *format [,
argument] ... argument] ...
);*/ );*/
inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) { inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) {
va_list va; va_list va;
@ -145,7 +145,7 @@ public:
void SetInternedStr( const char* str ) { Reset(); this->start = const_cast<char*>(str); } void SetInternedStr( const char* str ) { Reset(); this->start = const_cast<char*>(str); }
void SetStr( const char* str, int flags=0 ); void SetStr( const char* str, int flags=0 );
char* ParseText( char* in, const char* endTag, int strFlags ); char* ParseText( char* in, const char* endTag, int strFlags );
char* ParseName( char* in ); char* ParseName( char* in );
@ -160,7 +160,7 @@ private:
// After parsing, if *end != 0, it can be set to zero. // After parsing, if *end != 0, it can be set to zero.
int flags; int flags;
char* start; char* start;
char* end; char* end;
}; };
@ -174,7 +174,7 @@ template <class T, int INIT>
class DynArray class DynArray
{ {
public: public:
DynArray< T, INIT >() DynArray< T, INIT >()
{ {
mem = pool; mem = pool;
allocated = INIT; allocated = INIT;
@ -202,7 +202,7 @@ public:
T Pop() { T Pop() {
return mem[--size]; return mem[--size];
} }
void PopArr( int count ) void PopArr( int count )
{ {
TIXMLASSERT( size >= count ); TIXMLASSERT( size >= count );
size -= count; size -= count;
@ -248,7 +248,7 @@ public:
virtual int ItemSize() const = 0; virtual int ItemSize() const = 0;
virtual void* Alloc() = 0; virtual void* Alloc() = 0;
virtual void Free( void* ) = 0; virtual void Free( void* ) = 0;
}; };
@ -334,7 +334,7 @@ private:
If you return 'true' from a Visit method, recursive parsing will continue. If you return If you return 'true' from a Visit method, recursive parsing will continue. If you return
false, <b>no children of this node or its sibilings</b> will be visited. false, <b>no children of this node or its sibilings</b> will be visited.
All flavors of Visit methods have a default implementation that returns 'true' (continue All flavors of Visit methods have a default implementation that returns 'true' (continue
visiting). You need to only override methods that are interesting to you. visiting). You need to only override methods that are interesting to you.
Generally Accept() is called on the TiXmlDocument, although all nodes support visiting. Generally Accept() is called on the TiXmlDocument, although all nodes support visiting.
@ -375,7 +375,7 @@ public:
class XMLUtil class XMLUtil
{ {
public: public:
// Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
// correct, but simple, and usually works. // correct, but simple, and usually works.
static const char* SkipWhiteSpace( const char* p ) { while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) { ++p; } return p; } static const char* SkipWhiteSpace( const char* p ) { while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) { ++p; } return p; }
static char* SkipWhiteSpace( char* p ) { while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) ) { ++p; } return p; } static char* SkipWhiteSpace( char* p ) { while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) ) { ++p; } return p; }
@ -424,7 +424,7 @@ public:
XML Document Object Model (DOM), except XMLAttributes. XML Document Object Model (DOM), except XMLAttributes.
Nodes have siblings, a parent, and children which can Nodes have siblings, a parent, and children which can
be navigated. A node is always in a XMLDocument. be navigated. A node is always in a XMLDocument.
The type of a XMLNode can be queried, and it can The type of a XMLNode can be queried, and it can
be cast to its more defined type. be cast to its more defined type.
A XMLDocument allocates memory for all its Nodes. A XMLDocument allocates memory for all its Nodes.
@ -510,7 +510,7 @@ public:
*/ */
const XMLElement* LastChildElement( const char* value=0 ) const; const XMLElement* LastChildElement( const char* value=0 ) const;
XMLElement* LastChildElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(_value) ); } XMLElement* LastChildElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(_value) ); }
/// Get the previous (left) sibling node of this node. /// Get the previous (left) sibling node of this node.
const XMLNode* PreviousSibling() const { return prev; } const XMLNode* PreviousSibling() const { return prev; }
XMLNode* PreviousSibling() { return prev; } XMLNode* PreviousSibling() { return prev; }
@ -518,11 +518,11 @@ public:
/// Get the previous (left) sibling element of this node, with an opitionally supplied name. /// Get the previous (left) sibling element of this node, with an opitionally supplied name.
const XMLElement* PreviousSiblingElement( const char* value=0 ) const ; const XMLElement* PreviousSiblingElement( const char* value=0 ) const ;
XMLElement* PreviousSiblingElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( _value ) ); } XMLElement* PreviousSiblingElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( _value ) ); }
/// Get the next (right) sibling node of this node. /// Get the next (right) sibling node of this node.
const XMLNode* NextSibling() const { return next; } const XMLNode* NextSibling() const { return next; }
XMLNode* NextSibling() { return next; } XMLNode* NextSibling() { return next; }
/// Get the next (right) sibling element of this node, with an opitionally supplied name. /// Get the next (right) sibling element of this node, with an opitionally supplied name.
const XMLElement* NextSiblingElement( const char* value=0 ) const; const XMLElement* NextSiblingElement( const char* value=0 ) const;
XMLElement* NextSiblingElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( _value ) ); } XMLElement* NextSiblingElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( _value ) ); }
@ -541,7 +541,7 @@ public:
Add a node after the specified child node. Add a node after the specified child node.
*/ */
XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ); XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
/** /**
Delete all the children of this node. Delete all the children of this node.
*/ */
@ -555,7 +555,7 @@ public:
/** /**
Make a copy of this node, but not its children. Make a copy of this node, but not its children.
You may pass in a Document pointer that will be You may pass in a Document pointer that will be
the owner of the new Node. If the 'document' is the owner of the new Node. If the 'document' is
null, then the node returned will be allocated null, then the node returned will be allocated
from the current Document. (this->GetDocument()) from the current Document. (this->GetDocument())
@ -571,7 +571,7 @@ public:
*/ */
virtual bool ShallowEqual( const XMLNode* compare ) const = 0; virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
/** Accept a hierarchical visit of the nodes in the TinyXML DOM. Every node in the /** Accept a hierarchical visit of the nodes in the TinyXML DOM. Every node in the
XML tree will be conditionally visited and the host will be called back XML tree will be conditionally visited and the host will be called back
via the TiXmlVisitor interface. via the TiXmlVisitor interface.
@ -582,7 +582,7 @@ public:
The interface has been based on ideas from: The interface has been based on ideas from:
- http://www.saxproject.org/ - http://www.saxproject.org/
- http://c2.com/cgi/wiki?HierarchicalVisitorPattern - http://c2.com/cgi/wiki?HierarchicalVisitorPattern
Which are both good references for "visiting". Which are both good references for "visiting".
@ -603,7 +603,7 @@ protected:
virtual ~XMLNode(); virtual ~XMLNode();
XMLNode( const XMLNode& ); // not supported XMLNode( const XMLNode& ); // not supported
XMLNode& operator=( const XMLNode& ); // not supported XMLNode& operator=( const XMLNode& ); // not supported
XMLDocument* document; XMLDocument* document;
XMLNode* parent; XMLNode* parent;
mutable StrPair value; mutable StrPair value;
@ -627,9 +627,9 @@ private:
<root>This is <b>bold</b></root> <root>This is <b>bold</b></root>
@endverbatim @endverbatim
A text node can have 2 ways to output the next. "normal" output A text node can have 2 ways to output the next. "normal" output
and CDATA. It will default to the mode it was parsed from the XML file and and CDATA. It will default to the mode it was parsed from the XML file and
you generally want to leave it alone, but you can change the output mode with you generally want to leave it alone, but you can change the output mode with
SetCDATA() and query it with CDATA(). SetCDATA() and query it with CDATA().
*/ */
class XMLText : public XMLNode class XMLText : public XMLNode
@ -867,15 +867,15 @@ public:
virtual bool Accept( XMLVisitor* visitor ) const; virtual bool Accept( XMLVisitor* visitor ) const;
/** Given an attribute name, Attribute() returns the value /** Given an attribute name, Attribute() returns the value
for the attribute of that name, or null if none for the attribute of that name, or null if none
exists. For example: exists. For example:
@verbatim @verbatim
const char* value = ele->Attribute( "foo" ); const char* value = ele->Attribute( "foo" );
@endverbatim @endverbatim
The 'value' parameter is normally null. However, if specified, The 'value' parameter is normally null. However, if specified,
the attribute will only be returned if the 'name' and 'value' the attribute will only be returned if the 'name' and 'value'
match. This allow you to write code: match. This allow you to write code:
@verbatim @verbatim
@ -893,7 +893,7 @@ public:
/** Given an attribute name, IntAttribute() returns the value /** Given an attribute name, IntAttribute() returns the value
of the attribute interpreted as an integer. 0 will be of the attribute interpreted as an integer. 0 will be
returned if there is an error. For a method with error returned if there is an error. For a method with error
checking, see QueryIntAttribute() checking, see QueryIntAttribute()
*/ */
int IntAttribute( const char* name ) const { int i=0; QueryIntAttribute( name, &i ); return i; } int IntAttribute( const char* name ) const { int i=0; QueryIntAttribute( name, &i ); return i; }
@ -906,7 +906,7 @@ public:
/// See IntAttribute() /// See IntAttribute()
float FloatAttribute( const char* name ) const { float f=0; QueryFloatAttribute( name, &f ); return f; } float FloatAttribute( const char* name ) const { float f=0; QueryFloatAttribute( name, &f ); return f; }
/** Given an attribute name, QueryIntAttribute() returns /** Given an attribute name, QueryIntAttribute() returns
XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion
can't be performed, or XML_NO_ATTRIBUTE if the attribute can't be performed, or XML_NO_ATTRIBUTE if the attribute
doesn't exist. If successful, the result of the conversion doesn't exist. If successful, the result of the conversion
@ -919,7 +919,7 @@ public:
QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10
@endverbatim @endverbatim
*/ */
int QueryIntAttribute( const char* name, int* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryIntValue( _value ); } int QueryIntAttribute( const char* name, int* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryIntValue( _value ); }
/// See QueryIntAttribute() /// See QueryIntAttribute()
int QueryUnsignedAttribute( const char* name, unsigned int* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryUnsignedValue( _value ); } int QueryUnsignedAttribute( const char* name, unsigned int* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryUnsignedValue( _value ); }
/// See QueryIntAttribute() /// See QueryIntAttribute()
@ -953,7 +953,7 @@ public:
/** Convenience function for easy access to the text inside an element. Although easy /** Convenience function for easy access to the text inside an element. Although easy
and concise, GetText() is limited compared to getting the TiXmlText child and concise, GetText() is limited compared to getting the TiXmlText child
and accessing it directly. and accessing it directly.
If the first child of 'this' is a TiXmlText, the GetText() If the first child of 'this' is a TiXmlText, the GetText()
returns the character string of the Text node, else null is returned. returns the character string of the Text node, else null is returned.
@ -963,24 +963,24 @@ public:
const char* str = fooElement->GetText(); const char* str = fooElement->GetText();
@endverbatim @endverbatim
'str' will be a pointer to "This is text". 'str' will be a pointer to "This is text".
Note that this function can be misleading. If the element foo was created from Note that this function can be misleading. If the element foo was created from
this XML: this XML:
@verbatim @verbatim
<foo><b>This is text</b></foo> <foo><b>This is text</b></foo>
@endverbatim @endverbatim
then the value of str would be null. The first child node isn't a text node, it is then the value of str would be null. The first child node isn't a text node, it is
another element. From this XML: another element. From this XML:
@verbatim @verbatim
<foo>This is <b>text</b></foo> <foo>This is <b>text</b></foo>
@endverbatim @endverbatim
GetText() will return "This is ". GetText() will return "This is ".
*/ */
const char* GetText() const; const char* GetText() const;
/** /**
Convenience method to query the value of a child text node. This is probably best Convenience method to query the value of a child text node. This is probably best
shown by example. Given you have a document is this form: shown by example. Given you have a document is this form:
@verbatim @verbatim
@ -1004,7 +1004,7 @@ public:
@returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted
to the requested type, and XML_NO_TEXT_NODE if there is no child text to query. to the requested type, and XML_NO_TEXT_NODE if there is no child text to query.
*/ */
int QueryIntText( int* _value ) const; int QueryIntText( int* _value ) const;
/// See QueryIntText() /// See QueryIntText()
@ -1049,10 +1049,10 @@ private:
enum Whitespace { enum Whitespace {
PRESERVE_WHITESPACE, PRESERVE_WHITESPACE,
COLLAPSE_WHITESPACE COLLAPSE_WHITESPACE
}; };
/** A Document binds together all the functionality. /** A Document binds together all the functionality.
It can be saved, loaded, and printed to the screen. It can be saved, loaded, and printed to the screen.
All Nodes are connected and allocated to a Document. All Nodes are connected and allocated to a Document.
If the Document is deleted, all its Nodes are also deleted. If the Document is deleted, all its Nodes are also deleted.
@ -1062,7 +1062,7 @@ class XMLDocument : public XMLNode
friend class XMLElement; friend class XMLElement;
public: public:
/// constructor /// constructor
XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE ); XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
~XMLDocument(); ~XMLDocument();
virtual XMLDocument* ToDocument() { return this; } virtual XMLDocument* ToDocument() { return this; }
@ -1074,23 +1074,23 @@ public:
an errorID. an errorID.
*/ */
int Parse( const char* xml ); int Parse( const char* xml );
/** /**
Load an XML file from disk. Load an XML file from disk.
Returns XML_NO_ERROR (0) on success, or Returns XML_NO_ERROR (0) on success, or
an errorID. an errorID.
*/ */
int LoadFile( const char* filename ); int LoadFile( const char* filename );
/** /**
Load an XML file from disk. You are responsible Load an XML file from disk. You are responsible
for providing and closing the FILE*. for providing and closing the FILE*.
Returns XML_NO_ERROR (0) on success, or Returns XML_NO_ERROR (0) on success, or
an errorID. an errorID.
*/ */
int LoadFile( FILE* ); int LoadFile( FILE* );
/** /**
Save the XML file to disk. Save the XML file to disk.
Returns XML_NO_ERROR (0) on success, or Returns XML_NO_ERROR (0) on success, or
@ -1185,7 +1185,7 @@ public:
void DeleteNode( XMLNode* node ) { node->parent->DeleteChild( node ); } void DeleteNode( XMLNode* node ) { node->parent->DeleteChild( node ); }
void SetError( int error, const char* str1, const char* str2 ); void SetError( int error, const char* str1, const char* str2 );
/// Return true if there was an error parsing the document. /// Return true if there was an error parsing the document.
bool Error() const { return errorID != XML_NO_ERROR; } bool Error() const { return errorID != XML_NO_ERROR; }
/// Return the errorID. /// Return the errorID.
@ -1238,7 +1238,7 @@ private:
</Document> </Document>
@endverbatim @endverbatim
Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
easy to write a *lot* of code that looks like: easy to write a *lot* of code that looks like:
@verbatim @verbatim
@ -1258,7 +1258,7 @@ private:
@endverbatim @endverbatim
And that doesn't even cover "else" cases. XMLHandle addresses the verbosity And that doesn't even cover "else" cases. XMLHandle addresses the verbosity
of such code. A XMLHandle checks for null pointers so it is perfectly safe of such code. A XMLHandle checks for null pointers so it is perfectly safe
and correct to use: and correct to use:
@verbatim @verbatim
@ -1303,12 +1303,12 @@ public:
/// Get the previous sibling element of this handle. /// Get the previous sibling element of this handle.
XMLHandle PreviousSiblingElement( const char* _value=0 ) { return XMLHandle( node ? node->PreviousSiblingElement( _value ) : 0 ); } XMLHandle PreviousSiblingElement( const char* _value=0 ) { return XMLHandle( node ? node->PreviousSiblingElement( _value ) : 0 ); }
/// Get the next sibling of this handle. /// Get the next sibling of this handle.
XMLHandle NextSibling() { return XMLHandle( node ? node->NextSibling() : 0 ); } XMLHandle NextSibling() { return XMLHandle( node ? node->NextSibling() : 0 ); }
/// Get the next sibling element of this handle. /// Get the next sibling element of this handle.
XMLHandle NextSiblingElement( const char* _value=0 ) { return XMLHandle( node ? node->NextSiblingElement( _value ) : 0 ); } XMLHandle NextSiblingElement( const char* _value=0 ) { return XMLHandle( node ? node->NextSiblingElement( _value ) : 0 ); }
/// Safe cast to XMLNode. This can return null. /// Safe cast to XMLNode. This can return null.
XMLNode* ToNode() { return node; } XMLNode* ToNode() { return node; }
/// Safe cast to XMLElement. This can return null. /// Safe cast to XMLElement. This can return null.
XMLElement* ToElement() { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } XMLElement* ToElement() { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
/// Safe cast to XMLText. This can return null. /// Safe cast to XMLText. This can return null.
@ -1346,7 +1346,7 @@ public:
const XMLConstHandle NextSiblingElement( const char* _value=0 ) const { return XMLConstHandle( node ? node->NextSiblingElement( _value ) : 0 ); } const XMLConstHandle NextSiblingElement( const char* _value=0 ) const { return XMLConstHandle( node ? node->NextSiblingElement( _value ) : 0 ); }
const XMLNode* ToNode() const { return node; } const XMLNode* ToNode() const { return node; }
const XMLElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } const XMLElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
const XMLText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } const XMLText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
const XMLUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } const XMLUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
@ -1375,7 +1375,7 @@ private:
@endverbatim @endverbatim
Print to a File Print to a File
You provide the file pointer. You provide the file pointer.
@verbatim @verbatim
XMLPrinter printer( fp ); XMLPrinter printer( fp );
@ -1462,7 +1462,7 @@ public:
*/ */
const char* CStr() const { return buffer.Mem(); } const char* CStr() const { return buffer.Mem(); }
/** /**
If in print to memory mode, return the size If in print to memory mode, return the size
of the XML file in memory. (Note the size returned of the XML file in memory. (Note the size returned
includes the terminating null.) includes the terminating null.)
*/ */

View File

@ -97,7 +97,7 @@ int example_2()
int example_3() int example_3()
{ {
static const char* xml = static const char* xml =
"<?xml version=\"1.0\"?>" "<?xml version=\"1.0\"?>"
"<!DOCTYPE PLAY SYSTEM \"play.dtd\">" "<!DOCTYPE PLAY SYSTEM \"play.dtd\">"
"<PLAY>" "<PLAY>"
@ -110,7 +110,7 @@ int example_3()
XMLElement* titleElement = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" ); XMLElement* titleElement = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" );
const char* title = titleElement->GetText(); const char* title = titleElement->GetText();
printf( "Name of play (1): %s\n", title ); printf( "Name of play (1): %s\n", title );
XMLText* textNode = titleElement->FirstChild()->ToText(); XMLText* textNode = titleElement->FirstChild()->ToText();
title = textNode->Value(); title = textNode->Value();
printf( "Name of play (2): %s\n", title ); printf( "Name of play (2): %s\n", title );
@ -128,7 +128,7 @@ bool example_4()
" <v>2</v>" " <v>2</v>"
" </textApproach>" " </textApproach>"
"</information>"; "</information>";
XMLDocument doc; XMLDocument doc;
doc.Parse( xml ); doc.Parse( xml );
@ -151,7 +151,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
{ {
#if defined( _MSC_VER ) && defined( DEBUG ) #if defined( _MSC_VER ) && defined( DEBUG )
_CrtMemCheckpoint( &startMemState ); _CrtMemCheckpoint( &startMemState );
#endif #endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning ( push ) #pragma warning ( push )
@ -187,7 +187,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
XMLTest( "Example-3", 0, example_3() ); XMLTest( "Example-3", 0, example_3() );
XMLTest( "Example-4", true, example_4() ); XMLTest( "Example-4", true, example_4() );
/* ------ Example 2: Lookup information. ---- */ /* ------ Example 2: Lookup information. ---- */
{ {
static const char* test[] = { "<element />", static const char* test[] = { "<element />",
@ -268,7 +268,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
XMLTest( "Programmatic DOM", "comment", doc->FirstChildElement( "element" )->FirstChild()->Value() ); XMLTest( "Programmatic DOM", "comment", doc->FirstChildElement( "element" )->FirstChild()->Value() );
XMLTest( "Programmatic DOM", "0", doc->FirstChildElement( "element" )->FirstChildElement()->Attribute( "attrib" ) ); XMLTest( "Programmatic DOM", "0", doc->FirstChildElement( "element" )->FirstChildElement()->Attribute( "attrib" ) );
XMLTest( "Programmatic DOM", 2, doc->FirstChildElement()->LastChildElement( "sub" )->IntAttribute( "attrib" ) ); XMLTest( "Programmatic DOM", 2, doc->FirstChildElement()->LastChildElement( "sub" )->IntAttribute( "attrib" ) );
XMLTest( "Programmatic DOM", "& Text!", XMLTest( "Programmatic DOM", "& Text!",
doc->FirstChildElement()->LastChildElement( "sub" )->FirstChild()->ToText()->Value() ); doc->FirstChildElement()->LastChildElement( "sub" )->FirstChild()->ToText()->Value() );
// And now deletion: // And now deletion:
@ -402,7 +402,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
// Get the attribute "value" from the "Russian" element and check it. // Get the attribute "value" from the "Russian" element and check it.
XMLElement* element = doc.FirstChildElement( "document" )->FirstChildElement( "Russian" ); XMLElement* element = doc.FirstChildElement( "document" )->FirstChildElement( "Russian" );
const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU, const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU,
0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 }; 0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 };
XMLTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ) ); XMLTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ) );
@ -491,7 +491,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
doc.Parse( str ); doc.Parse( str );
doc.Print(); doc.Print();
XMLTest( "CDATA parse.", doc.FirstChildElement()->FirstChild()->Value(), XMLTest( "CDATA parse.", doc.FirstChildElement()->FirstChild()->Value(),
"I am > the rules!\n...since I make symbolic puns", "I am > the rules!\n...since I make symbolic puns",
false ); false );
} }
@ -508,7 +508,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
doc.Parse( str ); doc.Parse( str );
doc.Print(); doc.Print();
XMLTest( "CDATA parse. [ tixml1:1480107 ]", doc.FirstChildElement()->FirstChild()->Value(), XMLTest( "CDATA parse. [ tixml1:1480107 ]", doc.FirstChildElement()->FirstChild()->Value(),
"<b>I am > the rules!</b>\n...since I make symbolic puns", "<b>I am > the rules!</b>\n...since I make symbolic puns",
false ); false );
} }
@ -590,11 +590,11 @@ int main( int /*argc*/, const char ** /*argv*/ )
"<passages count=\"006\" formatversion=\"20020620\">" "<passages count=\"006\" formatversion=\"20020620\">"
"<psg context=\"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;.\">Crazy &ttk;</psg>" "<psg context=\"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;.\">Crazy &ttk;</psg>"
"</passages>"; "</passages>";
XMLDocument doc( false ); XMLDocument doc( false );
doc.Parse( passages ); doc.Parse( passages );
XMLTest( "No entity parsing.", doc.FirstChildElement()->FirstChildElement()->Attribute( "context" ), XMLTest( "No entity parsing.", doc.FirstChildElement()->FirstChildElement()->Attribute( "context" ),
"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;." ); "Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;." );
XMLTest( "No entity parsing.", doc.FirstChildElement()->FirstChildElement()->FirstChild()->Value(), XMLTest( "No entity parsing.", doc.FirstChildElement()->FirstChildElement()->FirstChild()->Value(),
"Crazy &ttk;" ); "Crazy &ttk;" );
@ -625,7 +625,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
{ {
// DOCTYPE not preserved (950171) // DOCTYPE not preserved (950171)
// //
const char* doctype = const char* doctype =
"<?xml version=\"1.0\" ?>" "<?xml version=\"1.0\" ?>"
"<!DOCTYPE PLAY SYSTEM 'play.dtd'>" "<!DOCTYPE PLAY SYSTEM 'play.dtd'>"
@ -639,7 +639,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
doc.DeleteChild( doc.RootElement() ); doc.DeleteChild( doc.RootElement() );
doc.LoadFile( "resources/out/test7.xml" ); doc.LoadFile( "resources/out/test7.xml" );
doc.Print(); doc.Print();
const XMLUnknown* decl = doc.FirstChild()->NextSibling()->ToUnknown(); const XMLUnknown* decl = doc.FirstChild()->NextSibling()->ToUnknown();
XMLTest( "Correct value of unknown.", "DOCTYPE PLAY SYSTEM 'play.dtd'", decl->Value() ); XMLTest( "Correct value of unknown.", "DOCTYPE PLAY SYSTEM 'play.dtd'", decl->Value() );
@ -647,7 +647,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
{ {
// Comments do not stream out correctly. // Comments do not stream out correctly.
const char* doctype = const char* doctype =
"<!-- Somewhat<evil> -->"; "<!-- Somewhat<evil> -->";
XMLDocument doc; XMLDocument doc;
doc.Parse( doctype ); doc.Parse( doctype );
@ -662,7 +662,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
XMLDocument doc; XMLDocument doc;
doc.Parse( doctype ); doc.Parse( doctype );
XMLTest( "Parsing repeated attributes.", (int)XML_ERROR_PARSING_ATTRIBUTE, doc.ErrorID() ); // is an error to tinyxml (didn't use to be, but caused issues) XMLTest( "Parsing repeated attributes.", (int)XML_ERROR_PARSING_ATTRIBUTE, doc.ErrorID() ); // is an error to tinyxml (didn't use to be, but caused issues)
doc.PrintError(); doc.PrintError();
} }
@ -709,7 +709,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
XMLTest("Missing end tag with trailing whitespace", xml.Error(), true); XMLTest("Missing end tag with trailing whitespace", xml.Error(), true);
xml.Parse("<x></y>"); xml.Parse("<x></y>");
XMLTest("Mismatched tags", xml.ErrorID(), (int)XML_ERROR_MISMATCHED_ELEMENT); XMLTest("Mismatched tags", xml.ErrorID(), (int)XML_ERROR_MISMATCHED_ELEMENT);
} }
{ {
@ -756,7 +756,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
XMLDocument doc; XMLDocument doc;
doc.Parse( (const char*)buf); doc.Parse( (const char*)buf);
} }
{ {
@ -806,14 +806,14 @@ int main( int /*argc*/, const char ** /*argv*/ )
} }
XMLTest( "Error in snprinf handling.", true, doc.Error() ); XMLTest( "Error in snprinf handling.", true, doc.Error() );
} }
{ {
// Attribute ordering. // Attribute ordering.
static const char* xml = "<element attrib1=\"1\" attrib2=\"2\" attrib3=\"3\" />"; static const char* xml = "<element attrib1=\"1\" attrib2=\"2\" attrib3=\"3\" />";
XMLDocument doc; XMLDocument doc;
doc.Parse( xml ); doc.Parse( xml );
XMLElement* ele = doc.FirstChildElement(); XMLElement* ele = doc.FirstChildElement();
const XMLAttribute* a = ele->FirstAttribute(); const XMLAttribute* a = ele->FirstAttribute();
XMLTest( "Attribute order", "1", a->Value() ); XMLTest( "Attribute order", "1", a->Value() );
a = a->Next(); a = a->Next();
@ -821,13 +821,13 @@ int main( int /*argc*/, const char ** /*argv*/ )
a = a->Next(); a = a->Next();
XMLTest( "Attribute order", "3", a->Value() ); XMLTest( "Attribute order", "3", a->Value() );
XMLTest( "Attribute order", "attrib3", a->Name() ); XMLTest( "Attribute order", "attrib3", a->Name() );
ele->DeleteAttribute( "attrib2" ); ele->DeleteAttribute( "attrib2" );
a = ele->FirstAttribute(); a = ele->FirstAttribute();
XMLTest( "Attribute order", "1", a->Value() ); XMLTest( "Attribute order", "1", a->Value() );
a = a->Next(); a = a->Next();
XMLTest( "Attribute order", "3", a->Value() ); XMLTest( "Attribute order", "3", a->Value() );
ele->DeleteAttribute( "attrib1" ); ele->DeleteAttribute( "attrib1" );
ele->DeleteAttribute( "attrib3" ); ele->DeleteAttribute( "attrib3" );
XMLTest( "Attribute order (empty)", false, ele->FirstAttribute() ? true : false ); XMLTest( "Attribute order (empty)", false, ele->FirstAttribute() ? true : false );
@ -879,7 +879,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
ele = docH.FirstChildElement( "none" ).FirstChildElement( "element" ).ToElement(); ele = docH.FirstChildElement( "none" ).FirstChildElement( "element" ).ToElement();
XMLTest( "Handle, dne, mutable", false, ele != 0 ); XMLTest( "Handle, dne, mutable", false, ele != 0 );
} }
{ {
static const char* xml = "<element attrib='bar'><sub>Text</sub></element>"; static const char* xml = "<element attrib='bar'><sub>Text</sub></element>";
XMLDocument doc; XMLDocument doc;
@ -897,7 +897,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
XMLDocument doc; XMLDocument doc;
doc.InsertEndChild( doc.NewDeclaration() ); doc.InsertEndChild( doc.NewDeclaration() );
doc.SetBOM( true ); doc.SetBOM( true );
XMLPrinter printer; XMLPrinter printer;
doc.Print( &printer ); doc.Print( &printer );
@ -972,7 +972,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
doc.Parse( xml ); doc.Parse( xml );
XMLTest( "Whitespace all space", true, 0 == doc.FirstChildElement()->FirstChild() ); XMLTest( "Whitespace all space", true, 0 == doc.FirstChildElement()->FirstChild() );
} }
// ----------- Performance tracking -------------- // ----------- Performance tracking --------------
{ {
#if defined( _MSC_VER ) #if defined( _MSC_VER )
@ -1015,7 +1015,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
delete [] mem; delete [] mem;
static const char* note = static const char* note =
#ifdef DEBUG #ifdef DEBUG
"DEBUG"; "DEBUG";
#else #else
@ -1030,7 +1030,7 @@ int main( int /*argc*/, const char ** /*argv*/ )
} }
#if defined( _MSC_VER ) && defined( DEBUG ) #if defined( _MSC_VER ) && defined( DEBUG )
_CrtMemCheckpoint( &endMemState ); _CrtMemCheckpoint( &endMemState );
//_CrtMemDumpStatistics( &endMemState ); //_CrtMemDumpStatistics( &endMemState );
_CrtMemState diffMemState; _CrtMemState diffMemState;