diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b1a8ed7 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: xmltest +xmltest: xmltest.cpp tinyxml2.cpp tinyxml2.h +clean: + rm -f *.o xmltest diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 68b8fa8..b0be17c 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -23,13 +23,10 @@ distribution. #include "tinyxml2.h" -#include -#include -#include -#include +#include +#include +#include #include -#include - using namespace tinyxml2; @@ -684,7 +681,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) DELETE_NODE( node ); node = 0; if ( !document->Error() ) { - document->SetError( ERROR_PARSING, 0, 0 ); + document->SetError( XML_ERROR_PARSING, 0, 0 ); } break; } @@ -703,16 +700,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) XMLElement* ele = node->ToElement(); if ( ele ) { if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) { - document->SetError( ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); + document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); p = 0; } else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) { - document->SetError( ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); + document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); p = 0; } else if ( !endTag.Empty() ) { if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) { - document->SetError( ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); + document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); p = 0; } } @@ -735,14 +732,14 @@ char* XMLText::ParseDeep( char* p, StrPair* ) if ( this->CData() ) { p = value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); if ( !p ) { - document->SetError( ERROR_PARSING_CDATA, start, 0 ); + document->SetError( XML_ERROR_PARSING_CDATA, start, 0 ); } return p; } else { p = value.ParseText( p, "<", document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES ); if ( !p ) { - document->SetError( ERROR_PARSING_TEXT, start, 0 ); + document->SetError( XML_ERROR_PARSING_TEXT, start, 0 ); } if ( p && *p ) { return p-1; @@ -794,7 +791,7 @@ char* XMLComment::ParseDeep( char* p, StrPair* ) const char* start = p; p = value.ParseText( p, "-->", StrPair::COMMENT ); if ( p == 0 ) { - document->SetError( ERROR_PARSING_COMMENT, start, 0 ); + document->SetError( XML_ERROR_PARSING_COMMENT, start, 0 ); } return p; } @@ -841,7 +838,7 @@ char* XMLDeclaration::ParseDeep( char* p, StrPair* ) const char* start = p; p = value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); if ( p == 0 ) { - document->SetError( ERROR_PARSING_DECLARATION, start, 0 ); + document->SetError( XML_ERROR_PARSING_DECLARATION, start, 0 ); } return p; } @@ -888,7 +885,7 @@ char* XMLUnknown::ParseDeep( char* p, StrPair* ) p = value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION ); if ( !p ) { - document->SetError( ERROR_PARSING_UNKNOWN, start, 0 ); + document->SetError( XML_ERROR_PARSING_UNKNOWN, start, 0 ); } return p; } @@ -939,7 +936,7 @@ int XMLAttribute::QueryIntValue( int* value ) const { if ( TIXML_SSCANF( Value(), "%d", value ) == 1 ) return XML_NO_ERROR; - return WRONG_ATTRIBUTE_TYPE; + return XML_WRONG_ATTRIBUTE_TYPE; } @@ -947,7 +944,7 @@ int XMLAttribute::QueryUnsignedValue( unsigned int* value ) const { if ( TIXML_SSCANF( Value(), "%u", value ) == 1 ) return XML_NO_ERROR; - return WRONG_ATTRIBUTE_TYPE; + return XML_WRONG_ATTRIBUTE_TYPE; } @@ -964,7 +961,7 @@ int XMLAttribute::QueryBoolValue( bool* value ) const *value = false; return XML_NO_ERROR; } - return WRONG_ATTRIBUTE_TYPE; + return XML_WRONG_ATTRIBUTE_TYPE; } @@ -972,7 +969,7 @@ int XMLAttribute::QueryDoubleValue( double* value ) const { if ( TIXML_SSCANF( Value(), "%lf", value ) == 1 ) return XML_NO_ERROR; - return WRONG_ATTRIBUTE_TYPE; + return XML_WRONG_ATTRIBUTE_TYPE; } @@ -980,7 +977,7 @@ int XMLAttribute::QueryFloatValue( float* value ) const { if ( TIXML_SSCANF( Value(), "%f", value ) == 1 ) return XML_NO_ERROR; - return WRONG_ATTRIBUTE_TYPE; + return XML_WRONG_ATTRIBUTE_TYPE; } @@ -1132,7 +1129,7 @@ char* XMLElement::ParseAttributes( char* p ) while( p ) { p = XMLUtil::SkipWhiteSpace( p ); if ( !p || !(*p) ) { - document->SetError( ERROR_PARSING_ELEMENT, start, Name() ); + document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name() ); return 0; } @@ -1144,7 +1141,7 @@ char* XMLElement::ParseAttributes( char* p ) p = attrib->ParseDeep( p, document->ProcessEntities() ); if ( !p || Attribute( attrib->Name() ) ) { DELETE_ATTRIBUTE( attrib ); - document->SetError( ERROR_PARSING_ATTRIBUTE, start, p ); + document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p ); return 0; } LinkAttribute( attrib ); @@ -1160,7 +1157,7 @@ char* XMLElement::ParseAttributes( char* p ) break; } else { - document->SetError( ERROR_PARSING_ELEMENT, start, p ); + document->SetError( XML_ERROR_PARSING_ELEMENT, start, p ); return 0; } } @@ -1353,7 +1350,7 @@ int XMLDocument::LoadFile( const char* filename ) #pragma warning ( pop ) #endif if ( !fp ) { - SetError( ERROR_FILE_NOT_FOUND, filename, 0 ); + SetError( XML_ERROR_FILE_NOT_FOUND, filename, 0 ); return errorID; } LoadFile( fp ); @@ -1383,7 +1380,7 @@ int XMLDocument::LoadFile( FILE* fp ) p = XMLUtil::SkipWhiteSpace( p ); p = XMLUtil::ReadBOM( p, &writeBOM ); if ( !p || !*p ) { - SetError( ERROR_EMPTY_DOCUMENT, 0, 0 ); + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return errorID; } @@ -1414,13 +1411,13 @@ int XMLDocument::Parse( const char* p ) InitDocument(); if ( !p || !*p ) { - SetError( ERROR_EMPTY_DOCUMENT, 0, 0 ); + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return errorID; } p = XMLUtil::SkipWhiteSpace( p ); p = XMLUtil::ReadBOM( p, &writeBOM ); if ( !p || !*p ) { - SetError( ERROR_EMPTY_DOCUMENT, 0, 0 ); + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return errorID; } diff --git a/tinyxml2.h b/tinyxml2.h index dceb842..b1fa008 100644 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -24,11 +24,13 @@ distribution. #ifndef TINYXML2_INCLUDED #define TINYXML2_INCLUDED - -#include -#include -#include -#include // Needed by mac. +#include +#include +#include +#include +#if __APPLE__ +# include +#endif /* TODO: add 'lastAttribute' for faster parsing. @@ -36,7 +38,6 @@ distribution. */ /* gcc: g++ -Wall tinyxml2.cpp xmltest.cpp -o gccxmltest.exe - */ #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__) @@ -724,22 +725,22 @@ enum { XML_NO_ERROR = 0, XML_SUCCESS = 0, - NO_ATTRIBUTE, - WRONG_ATTRIBUTE_TYPE, + XML_NO_ATTRIBUTE, + XML_WRONG_ATTRIBUTE_TYPE, - ERROR_FILE_NOT_FOUND, - ERROR_ELEMENT_MISMATCH, - ERROR_PARSING_ELEMENT, - ERROR_PARSING_ATTRIBUTE, - ERROR_IDENTIFYING_TAG, - ERROR_PARSING_TEXT, - ERROR_PARSING_CDATA, - ERROR_PARSING_COMMENT, - ERROR_PARSING_DECLARATION, - ERROR_PARSING_UNKNOWN, - ERROR_EMPTY_DOCUMENT, - ERROR_MISMATCHED_ELEMENT, - ERROR_PARSING + XML_ERROR_FILE_NOT_FOUND, + XML_ERROR_ELEMENT_MISMATCH, + XML_ERROR_PARSING_ELEMENT, + XML_ERROR_PARSING_ATTRIBUTE, + XML_ERROR_IDENTIFYING_TAG, + XML_ERROR_PARSING_TEXT, + XML_ERROR_PARSING_CDATA, + XML_ERROR_PARSING_COMMENT, + XML_ERROR_PARSING_DECLARATION, + XML_ERROR_PARSING_UNKNOWN, + XML_ERROR_EMPTY_DOCUMENT, + XML_ERROR_MISMATCHED_ELEMENT, + XML_ERROR_PARSING }; @@ -773,7 +774,7 @@ public: /** QueryIntAttribute interprets the attribute as an integer, and returns the value in the provided paremeter. The function will return XML_NO_ERROR on success, - and WRONG_ATTRIBUTE_TYPE if the conversion is not successful. + and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful. */ int QueryIntValue( int* value ) const; /// See QueryIntAttribute @@ -855,8 +856,8 @@ public: float FloatAttribute( const char* name ) const { float f=0; QueryFloatAttribute( name, &f ); return f; } /** Given an attribute name, QueryIntAttribute() returns - XML_NO_ERROR, WRONG_ATTRIBUTE_TYPE if the conversion - can't be performed, or NO_ATTRIBUTE if the attribute + XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion + can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. If successful, the result of the conversion will be written to 'value'. If not successful, nothing will be written to 'value'. This allows you to provide default @@ -867,15 +868,15 @@ public: QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 @endverbatim */ - int QueryIntAttribute( const char* name, int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return 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() - int QueryUnsignedAttribute( const char* name, unsigned int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return 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() - int QueryBoolAttribute( const char* name, bool* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return NO_ATTRIBUTE; return a->QueryBoolValue( value ); } + int QueryBoolAttribute( const char* name, bool* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryBoolValue( value ); } /// See QueryIntAttribute() - int QueryDoubleAttribute( const char* name, double* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return NO_ATTRIBUTE; return a->QueryDoubleValue( value ); } + int QueryDoubleAttribute( const char* name, double* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryDoubleValue( value ); } /// See QueryIntAttribute() - int QueryFloatAttribute( const char* name, float* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return NO_ATTRIBUTE; return a->QueryFloatValue( value ); } + int QueryFloatAttribute( const char* name, float* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryFloatValue( value ); } /// Sets the named attribute to value. void SetAttribute( const char* name, const char* value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } diff --git a/xmltest.cpp b/xmltest.cpp index ac5931b..7332ba0 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1,9 +1,8 @@ #include "tinyxml2.h" -#include -#include -#include -#include +#include +#include +#include #if defined( _MSC_VER ) #include @@ -72,7 +71,7 @@ void NullLineEndings( char* p ) } -int main( int /*argc*/, const char* /*argv*/ ) +int main( int /*argc*/, const char ** /*argv*/ ) { #if defined( _MSC_VER ) && defined( DEBUG ) _CrtMemCheckpoint( &startMemState ); @@ -170,7 +169,7 @@ int main( int /*argc*/, const char* /*argv*/ ) XMLTest( "Programmatic DOM", true, doc->FirstChildElement()->FirstChildElement()->BoolAttribute( "attrib" ) ); int value = 10; int result = doc->FirstChildElement()->LastChildElement()->QueryIntAttribute( "attrib", &value ); - XMLTest( "Programmatic DOM", result, NO_ATTRIBUTE ); + XMLTest( "Programmatic DOM", result, XML_NO_ATTRIBUTE ); XMLTest( "Programmatic DOM", value, 10 ); doc->Print(); @@ -224,7 +223,7 @@ int main( int /*argc*/, const char* /*argv*/ ) XMLDocument doc; doc.Parse( error ); - XMLTest( "Bad XML", doc.ErrorID(), ERROR_PARSING_ATTRIBUTE ); + XMLTest( "Bad XML", doc.ErrorID(), XML_ERROR_PARSING_ATTRIBUTE ); } { @@ -247,9 +246,9 @@ int main( int /*argc*/, const char* /*argv*/ ) XMLTest( "Query attribute: double as int", result, XML_NO_ERROR ); XMLTest( "Query attribute: double as int", iVal, 2 ); result = ele->QueryIntAttribute( "attr2", &iVal ); - XMLTest( "Query attribute: not a number", result, WRONG_ATTRIBUTE_TYPE ); + XMLTest( "Query attribute: not a number", result, XML_WRONG_ATTRIBUTE_TYPE ); result = ele->QueryIntAttribute( "bar", &iVal ); - XMLTest( "Query attribute: does not exist", result, NO_ATTRIBUTE ); + XMLTest( "Query attribute: does not exist", result, XML_NO_ATTRIBUTE ); } { @@ -543,7 +542,7 @@ int main( int /*argc*/, const char* /*argv*/ ) XMLDocument doc; doc.Parse( doctype ); - XMLTest( "Parsing repeated attributes.", ERROR_PARSING_ATTRIBUTE, doc.ErrorID() ); // is an error to tinyxml (didn't use to be, but caused issues) + XMLTest( "Parsing repeated attributes.", XML_ERROR_PARSING_ATTRIBUTE, doc.ErrorID() ); // is an error to tinyxml (didn't use to be, but caused issues) doc.PrintError(); } @@ -557,11 +556,11 @@ int main( int /*argc*/, const char* /*argv*/ ) } { - // Empty documents should return TIXML_ERROR_PARSING_EMPTY, bug 1070717 + // Empty documents should return TIXML_XML_ERROR_PARSING_EMPTY, bug 1070717 const char* str = " "; XMLDocument doc; doc.Parse( str ); - XMLTest( "Empty document error", ERROR_EMPTY_DOCUMENT, doc.ErrorID() ); + XMLTest( "Empty document error", XML_ERROR_EMPTY_DOCUMENT, doc.ErrorID() ); } { @@ -588,7 +587,7 @@ int main( int /*argc*/, const char* /*argv*/ ) xml.Parse(" "); XMLTest("Missing end tag with trailing whitespace", xml.Error(), true); xml.Parse(""); - XMLTest("Mismatched tags", xml.ErrorID(), ERROR_MISMATCHED_ELEMENT); + XMLTest("Mismatched tags", xml.ErrorID(), XML_ERROR_MISMATCHED_ELEMENT); }