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

This commit is contained in:
Lee Thomason 2012-04-28 14:37:11 -07:00
parent 0aa8a80fd7
commit f68c438ee2
4 changed files with 25 additions and 4 deletions

2
dox
View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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 --------------