Merge pull request #338 from Dmitry-Me/removeAmbiguousEnumItems

Get rid of two distinct enum items with same same
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index a93523b..2c07897 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -243,8 +243,8 @@
                         }

                     }

                     else {

-                        int i=0;

-                        for(; i<NUM_ENTITIES; ++i ) {

+                        bool entityFound = false;

+                        for( int i = 0; i < NUM_ENTITIES; ++i ) {

                             const Entity& entity = entities[i];

                             if ( strncmp( p + 1, entity.pattern, entity.length ) == 0

                                     && *( p + entity.length + 1 ) == ';' ) {

@@ -252,10 +252,11 @@
                                 *q = entity.value;

                                 ++q;

                                 p += entity.length + 2;

+                                entityFound = true;

                                 break;

                             }

                         }

-                        if ( i == NUM_ENTITIES ) {

+                        if ( !entityFound ) {

                             // fixme: treat as error?

                             ++p;

                             ++q;

@@ -645,6 +646,9 @@
 

 const char* XMLNode::Value() const 

 {

+    // Catch an edge case: XMLDocuments don't have a a Value. Carefully return nullptr.

+    if ( this->ToDocument() )

+        return 0;

     return _value.GetStr();

 }

 

@@ -887,6 +891,17 @@
             break;

         }

 

+        XMLDeclaration* decl = node->ToDeclaration();

+        if ( decl ) {

+                // A declaration can only be the first child of a document.

+                // Set error, if document already has children.

+                if ( !_document->NoChildren() ) {

+                        _document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0);

+                        DeleteNode( decl );

+                        break;

+                }

+        }

+

         XMLElement* ele = node->ToElement();

         if ( ele ) {

             // We read the end tag. Return it to the parent.

@@ -1846,7 +1861,7 @@
         return _errorID;

     }

 

-    if ( filelength >= (size_t)-1 ) {

+    if ( (size_t)filelength >= (size_t)-1 ) {

         // Cannot handle files which won't fit in buffer together with null terminator

         SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );

         return _errorID;

diff --git a/tinyxml2.h b/tinyxml2.h
index 7eb733e..af14205 100755
--- a/tinyxml2.h
+++ b/tinyxml2.h
@@ -122,9 +122,9 @@
 /* Versioning, past 1.0.14:

 	http://semver.org/

 */

-static const int TIXML2_MAJOR_VERSION = 3;
-static const int TIXML2_MINOR_VERSION = 0;
-static const int TIXML2_PATCH_VERSION = 0;
+static const int TIXML2_MAJOR_VERSION = 3;

+static const int TIXML2_MINOR_VERSION = 0;

+static const int TIXML2_PATCH_VERSION = 0;

 

 namespace tinyxml2

 {

@@ -708,7 +708,7 @@
 

     /** The meaning of 'value' changes for the specific type.

     	@verbatim

-    	Document:	empty

+    	Document:	empty (NULL is returned, not an empty string)

     	Element:	name of the element

     	Comment:	the comment text

     	Unknown:	the tag contents

diff --git a/xmltest.cpp b/xmltest.cpp
index b70fc51..5e0eb3a 100644
--- a/xmltest.cpp
+++ b/xmltest.cpp
@@ -30,7 +30,13 @@
 

 bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true, bool extraNL=false )

 {

-	bool pass = !strcmp( expected, found );

+	bool pass;

+	if ( !expected && !found )

+		pass = true;

+	else if ( !expected || !found )

+		pass = false;

+	else 

+		pass = !strcmp( expected, found );

 	if ( pass )

 		printf ("[pass]");

 	else

@@ -1460,7 +1466,39 @@
 		XMLTest( "Error should be cleared", false, doc.Error() );

 	}

 

-	// ----------- Performance tracking --------------

+	{

+		// Check that declarations are parsed only as the FirstChild

+	    const char* xml0 = "<?xml version=\"1.0\" ?>"

+	                       "   <!-- xml version=\"1.1\" -->"

+	                       "<first />";

+	    const char* xml1 = "<?xml version=\"1.0\" ?>"

+	                       "   <?xml version=\"1.1\" ?>"

+	                       "<first />";

+	    const char* xml2 = "<first />"

+	                       "<?xml version=\"1.0\" ?>";

+	    XMLDocument doc;

+	    doc.Parse(xml0);

+	    XMLTest("Test that the code changes do not affect normal parsing", doc.Error(), false);

+	    doc.Parse(xml1);

+	    XMLTest("Test that the second declaration throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);

+	    doc.Parse(xml2);

+	    XMLTest("Test that declaration after a child throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);

+	}

+

+    {

+	    // No matter - before or after successfully parsing a text -

+	    // calling XMLDocument::Value() causes an assert in debug.

+	    const char* validXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"

+	                           "<first />"

+	                           "<second />";

+	    XMLDocument* doc = new XMLDocument();

+	    XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() );

+	    doc->Parse( validXml );

+	    XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() );

+	    delete doc;

+    }

+

+    // ----------- Performance tracking --------------

 	{

 #if defined( _MSC_VER )

 		__int64 start, end, freq;