mirror of https://github.com/AxioDL/tinyxml2.git
Switched to Artistic Style auto-formatting to allow integration of patches from other coding styles.
This commit is contained in:
parent
3572ae0308
commit
a9cf3f9f3f
|
@ -70,8 +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, '&' },
|
||||
{ "apos", 4, SINGLE_QUOTE },
|
||||
|
@ -141,8 +140,7 @@ char* StrPair::ParseName( char* 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.
|
||||
{
|
||||
|| (*p == '.' && p>start ) )) { // can be in a name, but not lead it.
|
||||
++p;
|
||||
}
|
||||
|
||||
|
@ -166,8 +164,9 @@ 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,8 +230,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;
|
||||
++q;
|
||||
|
@ -277,8 +275,7 @@ const char* XMLUtil::ReadBOM( const char* p, bool* bom )
|
|||
// Check for BOM:
|
||||
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,22 +289,27 @@ 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 )
|
||||
}
|
||||
else if ( input < 0x800 ) {
|
||||
*length = 2;
|
||||
else if ( input < 0x10000 )
|
||||
}
|
||||
else if ( input < 0x10000 ) {
|
||||
*length = 3;
|
||||
else if ( input < 0x200000 )
|
||||
}
|
||||
else if ( input < 0x200000 ) {
|
||||
*length = 4;
|
||||
else
|
||||
{ *length = 0; return; } // This code won't covert this correctly anyway.
|
||||
}
|
||||
else {
|
||||
*length = 0; // This code won't covert this correctly anyway.
|
||||
return;
|
||||
}
|
||||
|
||||
output += *length;
|
||||
|
||||
// Scary scary fall throughs.
|
||||
switch (*length)
|
||||
{
|
||||
switch (*length) {
|
||||
case 4:
|
||||
--output;
|
||||
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
||||
|
@ -332,58 +334,67 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
|
|||
// Presume an entity, and pull it out.
|
||||
*length = 0;
|
||||
|
||||
if ( *(p+1) == '#' && *(p+2) )
|
||||
{
|
||||
if ( *(p+1) == '#' && *(p+2) ) {
|
||||
unsigned long ucs = 0;
|
||||
ptrdiff_t delta = 0;
|
||||
unsigned mult = 1;
|
||||
|
||||
if ( *(p+2) == 'x' )
|
||||
{
|
||||
if ( *(p+2) == 'x' ) {
|
||||
// Hexadecimal.
|
||||
if ( !*(p+3) ) return 0;
|
||||
if ( !*(p+3) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* q = p+3;
|
||||
q = strchr( q, ';' );
|
||||
|
||||
if ( !q || !*q ) return 0;
|
||||
if ( !q || !*q ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
delta = q-p;
|
||||
--q;
|
||||
|
||||
while ( *q != 'x' )
|
||||
{
|
||||
if ( *q >= '0' && *q <= '9' )
|
||||
while ( *q != 'x' ) {
|
||||
if ( *q >= '0' && *q <= '9' ) {
|
||||
ucs += mult * (*q - '0');
|
||||
else if ( *q >= 'a' && *q <= 'f' )
|
||||
}
|
||||
else if ( *q >= 'a' && *q <= 'f' ) {
|
||||
ucs += mult * (*q - 'a' + 10);
|
||||
else if ( *q >= 'A' && *q <= 'F' )
|
||||
}
|
||||
else if ( *q >= 'A' && *q <= 'F' ) {
|
||||
ucs += mult * (*q - 'A' + 10 );
|
||||
else
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
mult *= 16;
|
||||
--q;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
// Decimal.
|
||||
if ( !*(p+2) ) return 0;
|
||||
if ( !*(p+2) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* q = p+2;
|
||||
q = strchr( q, ';' );
|
||||
|
||||
if ( !q || !*q ) return 0;
|
||||
if ( !q || !*q ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
delta = q-p;
|
||||
--q;
|
||||
|
||||
while ( *q != '#' )
|
||||
{
|
||||
if ( *q >= '0' && *q <= '9' )
|
||||
while ( *q != '#' ) {
|
||||
if ( *q >= '0' && *q <= '9' ) {
|
||||
ucs += mult * (*q - '0');
|
||||
else
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
mult *= 10;
|
||||
--q;
|
||||
}
|
||||
|
@ -428,15 +439,17 @@ void XMLUtil::ToStr( double v, char* buffer, int bufferSize )
|
|||
|
||||
bool XMLUtil::ToInt( const char* str, int* value )
|
||||
{
|
||||
if ( TIXML_SSCANF( str, "%d", value ) == 1 )
|
||||
if ( TIXML_SSCANF( str, "%d", value ) == 1 ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool XMLUtil::ToUnsigned( const char* str, unsigned *value )
|
||||
{
|
||||
if ( TIXML_SSCANF( str, "%u", value ) == 1 )
|
||||
if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -481,8 +494,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
|||
XMLNode* returnNode = 0;
|
||||
char* start = p;
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if( !p || !*p )
|
||||
{
|
||||
if( !p || !*p ) {
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -554,14 +566,13 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
|||
|
||||
bool XMLDocument::Accept( XMLVisitor* visitor ) const
|
||||
{
|
||||
if ( visitor->VisitEnter( *this ) )
|
||||
{
|
||||
for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() )
|
||||
{
|
||||
if ( !node->Accept( visitor ) )
|
||||
if ( visitor->VisitEnter( *this ) ) {
|
||||
for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) {
|
||||
if ( !node->Accept( visitor ) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor->VisitExit( *this );
|
||||
}
|
||||
|
||||
|
@ -588,11 +599,13 @@ XMLNode::~XMLNode()
|
|||
|
||||
void XMLNode::SetValue( const char* str, bool staticMem )
|
||||
{
|
||||
if ( staticMem )
|
||||
if ( staticMem ) {
|
||||
value.SetInternedStr( str );
|
||||
else
|
||||
}
|
||||
else {
|
||||
value.SetStr( str );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XMLNode::DeleteChildren()
|
||||
|
@ -610,10 +623,12 @@ 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 ) {
|
||||
child->prev->next = child->next;
|
||||
|
@ -682,8 +697,9 @@ XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis )
|
|||
XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
|
||||
{
|
||||
TIXMLASSERT( afterThis->parent == this );
|
||||
if ( afterThis->parent != this )
|
||||
if ( afterThis->parent != this ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( afterThis->next == 0 ) {
|
||||
// The last node or the only node.
|
||||
|
@ -732,8 +748,7 @@ 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() )))
|
||||
{
|
||||
&& (!value || XMLUtil::StringEqual( value, element->Value() ))) {
|
||||
return element->ToElement();
|
||||
}
|
||||
}
|
||||
|
@ -745,8 +760,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();
|
||||
}
|
||||
}
|
||||
|
@ -844,8 +858,9 @@ char* XMLText::ParseDeep( char* p, StrPair* )
|
|||
}
|
||||
else {
|
||||
int flags = document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES;
|
||||
if ( document->WhitespaceMode() == COLLAPSE_WHITESPACE )
|
||||
if ( document->WhitespaceMode() == COLLAPSE_WHITESPACE ) {
|
||||
flags |= StrPair::COLLAPSE_WHITESPACE;
|
||||
}
|
||||
|
||||
p = value.ParseText( p, "<", flags );
|
||||
if ( !p ) {
|
||||
|
@ -1027,15 +1042,21 @@ char* XMLAttribute::ParseDeep( char* p, bool processEntities )
|
|||
{
|
||||
// Parse using the name rules: bug fix, was using ParseText before
|
||||
p = name.ParseName( p );
|
||||
if ( !p || !*p ) return 0;
|
||||
if ( !p || !*p ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Skip white space before =
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if ( !p || *p != '=' ) return 0;
|
||||
if ( !p || *p != '=' ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
++p; // move up to opening quote
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if ( *p != '\"' && *p != '\'' ) return 0;
|
||||
if ( *p != '\"' && *p != '\'' ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char endTag[2] = { *p, 0 };
|
||||
++p; // move past opening quote
|
||||
|
@ -1053,16 +1074,18 @@ void XMLAttribute::SetName( const char* n )
|
|||
|
||||
int XMLAttribute::QueryIntValue( int* value ) const
|
||||
{
|
||||
if ( XMLUtil::ToInt( Value(), value ))
|
||||
if ( XMLUtil::ToInt( Value(), value )) {
|
||||
return XML_NO_ERROR;
|
||||
}
|
||||
return XML_WRONG_ATTRIBUTE_TYPE;
|
||||
}
|
||||
|
||||
|
||||
int XMLAttribute::QueryUnsignedValue( unsigned int* value ) const
|
||||
{
|
||||
if ( XMLUtil::ToUnsigned( Value(), value ))
|
||||
if ( XMLUtil::ToUnsigned( Value(), value )) {
|
||||
return XML_NO_ERROR;
|
||||
}
|
||||
return XML_WRONG_ATTRIBUTE_TYPE;
|
||||
}
|
||||
|
||||
|
@ -1078,16 +1101,18 @@ int XMLAttribute::QueryBoolValue( bool* value ) const
|
|||
|
||||
int XMLAttribute::QueryFloatValue( float* value ) const
|
||||
{
|
||||
if ( XMLUtil::ToFloat( Value(), value ))
|
||||
if ( XMLUtil::ToFloat( Value(), value )) {
|
||||
return XML_NO_ERROR;
|
||||
}
|
||||
return XML_WRONG_ATTRIBUTE_TYPE;
|
||||
}
|
||||
|
||||
|
||||
int XMLAttribute::QueryDoubleValue( double* value ) const
|
||||
{
|
||||
if ( XMLUtil::ToDouble( Value(), value ))
|
||||
if ( XMLUtil::ToDouble( Value(), value )) {
|
||||
return XML_NO_ERROR;
|
||||
}
|
||||
return XML_WRONG_ATTRIBUTE_TYPE;
|
||||
}
|
||||
|
||||
|
@ -1158,9 +1183,10 @@ XMLAttribute* XMLElement::FindAttribute( const char* name )
|
|||
{
|
||||
XMLAttribute* a = 0;
|
||||
for( a=rootAttribute; a; a = a->next ) {
|
||||
if ( XMLUtil::StringEqual( a->Name(), name ) )
|
||||
if ( XMLUtil::StringEqual( a->Name(), name ) ) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1169,9 +1195,10 @@ const XMLAttribute* XMLElement::FindAttribute( const char* name ) const
|
|||
{
|
||||
XMLAttribute* a = 0;
|
||||
for( a=rootAttribute; a; a = a->next ) {
|
||||
if ( XMLUtil::StringEqual( a->Name(), name ) )
|
||||
if ( XMLUtil::StringEqual( a->Name(), name ) ) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1179,10 +1206,12 @@ 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 )
|
||||
if ( !a ) {
|
||||
return 0;
|
||||
if ( !value || XMLUtil::StringEqual( a->Value(), value ))
|
||||
}
|
||||
if ( !value || XMLUtil::StringEqual( a->Value(), value )) {
|
||||
return a->Value();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1268,8 +1297,7 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
|
|||
XMLAttribute* attrib = 0;
|
||||
for( attrib = rootAttribute;
|
||||
attrib;
|
||||
last = attrib, attrib = attrib->next )
|
||||
{
|
||||
last = attrib, attrib = attrib->next ) {
|
||||
if ( XMLUtil::StringEqual( attrib->Name(), name ) ) {
|
||||
break;
|
||||
}
|
||||
|
@ -1372,7 +1400,9 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair )
|
|||
{
|
||||
// Read the element name.
|
||||
p = XMLUtil::SkipWhiteSpace( p );
|
||||
if ( !p ) return 0;
|
||||
if ( !p ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The closing element is the </element> form. It is
|
||||
// parsed just like a regular element then deleted from
|
||||
|
@ -1383,11 +1413,14 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair )
|
|||
}
|
||||
|
||||
p = value.ParseName( p );
|
||||
if ( value.Empty() ) return 0;
|
||||
if ( value.Empty() ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = ParseAttributes( p );
|
||||
if ( !p || !*p || closingType )
|
||||
if ( !p || !*p || closingType ) {
|
||||
return p;
|
||||
}
|
||||
|
||||
p = XMLNode::ParseDeep( p, strPair );
|
||||
return p;
|
||||
|
@ -1435,14 +1468,13 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) const
|
|||
|
||||
bool XMLElement::Accept( XMLVisitor* visitor ) const
|
||||
{
|
||||
if ( visitor->VisitEnter( *this, rootAttribute ) )
|
||||
{
|
||||
for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() )
|
||||
{
|
||||
if ( !node->Accept( visitor ) )
|
||||
if ( visitor->VisitEnter( *this, rootAttribute ) ) {
|
||||
for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) {
|
||||
if ( !node->Accept( visitor ) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor->VisitExit( *this );
|
||||
}
|
||||
|
||||
|
@ -1653,8 +1685,9 @@ int XMLDocument::Parse( const char* p, size_t len )
|
|||
void XMLDocument::Print( XMLPrinter* streamer )
|
||||
{
|
||||
XMLPrinter stdStreamer( stdout );
|
||||
if ( !streamer )
|
||||
if ( !streamer ) {
|
||||
streamer = &stdStreamer;
|
||||
}
|
||||
Accept( streamer );
|
||||
}
|
||||
|
||||
|
@ -1883,10 +1916,12 @@ void XMLPrinter::CloseElement()
|
|||
Print( "</%s>", name );
|
||||
}
|
||||
|
||||
if ( textDepth == depth )
|
||||
if ( textDepth == depth ) {
|
||||
textDepth = -1;
|
||||
if ( depth == 0 && !compactMode)
|
||||
}
|
||||
if ( depth == 0 && !compactMode) {
|
||||
Print( "\n" );
|
||||
}
|
||||
elementJustOpened = false;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue