remove trailing spaces
This commit is contained in:
124
tinyxml2.cpp
124
tinyxml2.cpp
@@ -70,7 +70,7 @@ struct Entity {
|
||||
};
|
||||
|
||||
static const int NUM_ENTITIES = 5;
|
||||
static const Entity entities[NUM_ENTITIES] =
|
||||
static const Entity entities[NUM_ENTITIES] =
|
||||
{
|
||||
{ "quot", 4, DOUBLE_QUOTE },
|
||||
{ "amp", 3, '&' },
|
||||
@@ -123,7 +123,7 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags )
|
||||
return p + length;
|
||||
}
|
||||
++p;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ char* StrPair::ParseName( char* p )
|
||||
}
|
||||
|
||||
while( *p && (
|
||||
XMLUtil::IsAlphaNum( (unsigned char) *p )
|
||||
XMLUtil::IsAlphaNum( (unsigned char) *p )
|
||||
|| *p == '_'
|
||||
|| *p == ':'
|
||||
|| (*p == '-' && p>start ) // can be in a name, but not lead it.
|
||||
@@ -166,7 +166,7 @@ void StrPair::CollapseWhitespace()
|
||||
while( *p ) {
|
||||
if ( XMLUtil::IsWhiteSpace( *p )) {
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if ( *p == 0 )
|
||||
if ( *p == 0 )
|
||||
break; // don't write to q; this trims the trailing space.
|
||||
*q = ' ';
|
||||
++q;
|
||||
@@ -231,7 +231,7 @@ const char* StrPair::GetStr()
|
||||
int i=0;
|
||||
for(; i<NUM_ENTITIES; ++i ) {
|
||||
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;
|
||||
*q = entities[i].value;
|
||||
@@ -275,9 +275,9 @@ const char* XMLUtil::ReadBOM( const char* p, bool* bom )
|
||||
*bom = false;
|
||||
const unsigned char* pu = reinterpret_cast<const unsigned char*>(p);
|
||||
// Check for BOM:
|
||||
if ( *(pu+0) == TIXML_UTF_LEAD_0
|
||||
if ( *(pu+0) == TIXML_UTF_LEAD_0
|
||||
&& *(pu+1) == TIXML_UTF_LEAD_1
|
||||
&& *(pu+2) == TIXML_UTF_LEAD_2 )
|
||||
&& *(pu+2) == TIXML_UTF_LEAD_2 )
|
||||
{
|
||||
*bom = true;
|
||||
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 FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
||||
|
||||
if (input < 0x80)
|
||||
if (input < 0x80)
|
||||
*length = 1;
|
||||
else if ( input < 0x800 )
|
||||
*length = 2;
|
||||
@@ -306,22 +306,22 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length
|
||||
output += *length;
|
||||
|
||||
// Scary scary fall throughs.
|
||||
switch (*length)
|
||||
switch (*length)
|
||||
{
|
||||
case 4:
|
||||
--output;
|
||||
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
||||
--output;
|
||||
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
||||
input >>= 6;
|
||||
case 3:
|
||||
--output;
|
||||
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
||||
--output;
|
||||
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
||||
input >>= 6;
|
||||
case 2:
|
||||
--output;
|
||||
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
||||
--output;
|
||||
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
||||
input >>= 6;
|
||||
case 1:
|
||||
--output;
|
||||
--output;
|
||||
*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);
|
||||
else if ( *q >= 'A' && *q <= 'F' )
|
||||
ucs += mult * (*q - 'A' + 10 );
|
||||
else
|
||||
else
|
||||
return 0;
|
||||
mult *= 16;
|
||||
--q;
|
||||
@@ -382,7 +382,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
|
||||
{
|
||||
if ( *q >= '0' && *q <= '9' )
|
||||
ucs += mult * (*q - '0');
|
||||
else
|
||||
else
|
||||
return 0;
|
||||
mult *= 10;
|
||||
--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 )
|
||||
{
|
||||
TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
|
||||
TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
|
||||
}
|
||||
|
||||
|
||||
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 )
|
||||
{
|
||||
TIXML_SNPRINTF( buffer, bufferSize, "%f", v );
|
||||
TIXML_SNPRINTF( buffer, bufferSize, "%f", v );
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
char* start = p;
|
||||
@@ -486,7 +486,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
||||
return p;
|
||||
}
|
||||
|
||||
// What is this thing?
|
||||
// What is this thing?
|
||||
// - Elements start with a letter or underscore, but xml is reserved.
|
||||
// - Comments: <!--
|
||||
// - Decleration: <?
|
||||
@@ -600,7 +600,7 @@ void XMLNode::DeleteChildren()
|
||||
while( firstChild ) {
|
||||
XMLNode* node = firstChild;
|
||||
Unlink( node );
|
||||
|
||||
|
||||
DELETE_NODE( node );
|
||||
}
|
||||
firstChild = lastChild = 0;
|
||||
@@ -610,9 +610,9 @@ void XMLNode::DeleteChildren()
|
||||
void XMLNode::Unlink( XMLNode* child )
|
||||
{
|
||||
TIXMLASSERT( child->parent == this );
|
||||
if ( child == firstChild )
|
||||
if ( child == firstChild )
|
||||
firstChild = firstChild->next;
|
||||
if ( child == lastChild )
|
||||
if ( child == lastChild )
|
||||
lastChild = lastChild->prev;
|
||||
|
||||
if ( child->prev ) {
|
||||
@@ -731,8 +731,8 @@ const XMLElement* XMLNode::LastChildElement( const char* value ) const
|
||||
const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
|
||||
{
|
||||
for( XMLNode* element=this->next; element; element = element->next ) {
|
||||
if ( element->ToElement()
|
||||
&& (!value || XMLUtil::StringEqual( value, element->Value() )))
|
||||
if ( element->ToElement()
|
||||
&& (!value || XMLUtil::StringEqual( value, element->Value() )))
|
||||
{
|
||||
return element->ToElement();
|
||||
}
|
||||
@@ -745,7 +745,7 @@ const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const
|
||||
{
|
||||
for( XMLNode* element=this->prev; element; element = element->prev ) {
|
||||
if ( element->ToElement()
|
||||
&& (!value || XMLUtil::StringEqual( value, element->Value() )))
|
||||
&& (!value || XMLUtil::StringEqual( value, element->Value() )))
|
||||
{
|
||||
return element->ToElement();
|
||||
}
|
||||
@@ -765,11 +765,11 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
|
||||
// <foo>
|
||||
// </foo>
|
||||
// <!-- comment -->
|
||||
//
|
||||
//
|
||||
// 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 will be read by the 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.
|
||||
|
||||
@@ -814,7 +814,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
|
||||
p = 0;
|
||||
}
|
||||
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 );
|
||||
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 XMLAttribute* a = FindAttribute( name );
|
||||
if ( !a )
|
||||
return 0;
|
||||
{
|
||||
const XMLAttribute* a = FindAttribute( name );
|
||||
if ( !a )
|
||||
return 0;
|
||||
if ( !value || XMLUtil::StringEqual( a->Value(), value ))
|
||||
return a->Value();
|
||||
return 0;
|
||||
@@ -1269,7 +1269,7 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
|
||||
for( attrib = rootAttribute;
|
||||
attrib;
|
||||
last = attrib, attrib = attrib->next )
|
||||
{
|
||||
{
|
||||
if ( XMLUtil::StringEqual( attrib->Name(), name ) ) {
|
||||
break;
|
||||
}
|
||||
@@ -1337,12 +1337,12 @@ char* XMLElement::ParseAttributes( char* p )
|
||||
// attribute will be doubly added. However, tracking the 'prevAttribute'
|
||||
// avoids re-scanning the attribute list. Preferring performance for
|
||||
// now, may reconsider in the future.
|
||||
if ( prevAttribute ) {
|
||||
if ( prevAttribute ) {
|
||||
prevAttribute->next = attrib;
|
||||
}
|
||||
else {
|
||||
rootAttribute = attrib;
|
||||
}
|
||||
}
|
||||
prevAttribute = attrib;
|
||||
}
|
||||
// end of the tag
|
||||
@@ -1386,7 +1386,7 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair )
|
||||
if ( value.Empty() ) return 0;
|
||||
|
||||
p = ParseAttributes( p );
|
||||
if ( !p || !*p || closingType )
|
||||
if ( !p || !*p || closingType )
|
||||
return p;
|
||||
|
||||
p = XMLNode::ParseDeep( p, strPair );
|
||||
@@ -1422,7 +1422,7 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) const
|
||||
}
|
||||
a = a->Next();
|
||||
b = b->Next();
|
||||
}
|
||||
}
|
||||
if ( a || b ) {
|
||||
// different count
|
||||
return false;
|
||||
@@ -1435,7 +1435,7 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) 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() )
|
||||
{
|
||||
@@ -1560,7 +1560,7 @@ int XMLDocument::LoadFile( const char* filename )
|
||||
}
|
||||
|
||||
|
||||
int XMLDocument::LoadFile( FILE* fp )
|
||||
int XMLDocument::LoadFile( FILE* fp )
|
||||
{
|
||||
DeleteChildren();
|
||||
InitDocument();
|
||||
@@ -1579,7 +1579,7 @@ int XMLDocument::LoadFile( FILE* fp )
|
||||
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
||||
return errorID;
|
||||
}
|
||||
|
||||
|
||||
charBuffer[size] = 0;
|
||||
|
||||
const char* p = charBuffer;
|
||||
@@ -1642,13 +1642,13 @@ int XMLDocument::Parse( const char* p )
|
||||
charBuffer = new char[ len+1 ];
|
||||
memcpy( charBuffer, p, len+1 );
|
||||
|
||||
|
||||
|
||||
ParseDeep( charBuffer, 0 );
|
||||
return errorID;
|
||||
}
|
||||
|
||||
|
||||
void XMLDocument::Print( XMLPrinter* streamer )
|
||||
void XMLDocument::Print( XMLPrinter* streamer )
|
||||
{
|
||||
XMLPrinter stdStreamer( stdout );
|
||||
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 ) {
|
||||
static const int LEN = 20;
|
||||
char buf1[LEN] = { 0 };
|
||||
char buf2[LEN] = { 0 };
|
||||
|
||||
|
||||
if ( errorStr1 ) {
|
||||
TIXML_SNPRINTF( buf1, LEN, "%s", errorStr1 );
|
||||
}
|
||||
@@ -1685,11 +1685,11 @@ void XMLDocument::PrintError() const
|
||||
}
|
||||
|
||||
|
||||
XMLPrinter::XMLPrinter( FILE* file, bool compact ) :
|
||||
elementJustOpened( false ),
|
||||
XMLPrinter::XMLPrinter( FILE* file, bool compact ) :
|
||||
elementJustOpened( false ),
|
||||
firstElement( true ),
|
||||
fp( file ),
|
||||
depth( 0 ),
|
||||
fp( file ),
|
||||
depth( 0 ),
|
||||
textDepth( -1 ),
|
||||
processEntities( true ),
|
||||
compactMode( compact )
|
||||
@@ -1738,7 +1738,7 @@ void XMLPrinter::Print( const char* format, ... )
|
||||
int len = vsnprintf( 0, 0, format, va );
|
||||
// Close out and re-start the va-args
|
||||
va_end( va );
|
||||
va_start( va, format );
|
||||
va_start( va, format );
|
||||
char* p = buffer.PushArr( len ) - 1;
|
||||
vsnprintf( p, len+1, format, va );
|
||||
#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?)
|
||||
if ( *q > 0 && *q < ENTITY_RANGE ) {
|
||||
// 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.
|
||||
if ( flag[(unsigned)(*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];
|
||||
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];
|
||||
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];
|
||||
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];
|
||||
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];
|
||||
XMLUtil::ToStr( value, buf, BUF_SIZE );
|
||||
|
||||
Reference in New Issue
Block a user