Prechádzať zdrojové kódy

added new test for BOM, and added good defaults for NewDeclaration

Lee Thomason 14 rokov pred
rodič
commit
f68c438ee2
4 zmenil súbory, kde vykonal 25 pridanie a 4 odobranie
  1. 1 1
      dox
  2. 1 1
      tinyxml2.cpp
  3. 11 2
      tinyxml2.h
  4. 12 0
      xmltest.cpp

+ 1 - 1
dox

@@ -32,7 +32,7 @@ PROJECT_NAME           = "TinyXML-2"
 # This could be handy for archiving the generated documentation or
 # if some version control system is used.
 
-PROJECT_NUMBER = 1.0.0
+PROJECT_NUMBER = 1.0.1
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer

+ 1 - 1
tinyxml2.cpp

@@ -1351,7 +1351,7 @@ XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
 {
 	XMLDeclaration* dec = new (commentPool.Alloc()) XMLDeclaration( this );
 	dec->memPool = &commentPool;
-	dec->SetValue( str );
+	dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" );
 	return dec;
 }
 

+ 11 - 2
tinyxml2.h

@@ -85,7 +85,7 @@ distribution.
 
 static const int TIXML2_MAJOR_VERSION = 1;
 static const int TIXML2_MINOR_VERSION = 0;
-static const int TIXML2_PATCH_VERSION = 0;
+static const int TIXML2_PATCH_VERSION = 1;
 
 namespace tinyxml2
 {
@@ -1038,6 +1038,9 @@ public:
 		Returns true if this document has a leading Byte Order Mark of UTF8.
 	*/
 	bool HasBOM() const { return writeBOM; }
+	/** Sets whether to write the BOM when writing the file.
+	*/
+	void SetBOM( bool useBOM ) { writeBOM = useBOM; }
 
 	/** Return the root element of DOM. Equivalent to FirstChildElement().
 	    To get the first node, use FirstChild().
@@ -1084,8 +1087,14 @@ public:
 		Create a new Declaration associated with
 		this Document. The memory for the object
 		is managed by the Document.
+
+		If the 'text' param is null, the standard
+		declaration is used.:
+		@verbatim
+			<?xml version="1.0" encoding="UTF-8"?>
+		@endverbatim
 	*/
-	XMLDeclaration* NewDeclaration( const char* text );
+	XMLDeclaration* NewDeclaration( const char* text=0 );
 	/**
 		Create a new Unknown associated with
 		this Document. The memory for the object

+ 12 - 0
xmltest.cpp

@@ -813,6 +813,18 @@ int main( int /*argc*/, const char ** /*argv*/ )
 		ele = docH.FirstChildElement( "none" ).FirstChildElement( "element" ).ToElement();
 		XMLTest( "Handle, dne, const", false, ele != 0 );
 	}
+	{
+		// Default Declaration & BOM
+		XMLDocument doc;
+		doc.InsertEndChild( doc.NewDeclaration() );
+		doc.SetBOM( true );
+		
+		XMLPrinter printer;
+		doc.Print( &printer );
+
+		static const char* result  = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
+		XMLTest( "BOM and default declaration", printer.CStr(), result, false );
+	}
 
 	
 	// ----------- Performance tracking --------------