Conflicts:
	tinyxml2.cpp
	xmltest.cpp
This commit is contained in:
Uli Kusterer 2014-01-25 03:12:21 +01:00
commit 2861a7e63a
5 changed files with 57 additions and 103 deletions

View File

@ -10,7 +10,7 @@ include(GNUInstallDirs)
################################ ################################
# set lib version here # set lib version here
set(GENERIC_LIB_VERSION "1.0.13") set(GENERIC_LIB_VERSION "1.0.14")
set(GENERIC_LIB_SOVERSION "1") set(GENERIC_LIB_SOVERSION "1")

2
dox
View File

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

View File

@ -1293,71 +1293,46 @@ void XMLElement::SetText( const char* inText )
} }
void XMLElement::SetText( int inNum ) void XMLElement::SetText( int v )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( inNum, buf, BUF_SIZE ); XMLUtil::ToStr( v, buf, BUF_SIZE );
if ( FirstChild() && FirstChild()->ToText() ) SetText( buf );
FirstChild()->SetValue( buf );
else {
XMLText* theText = GetDocument()->NewText( buf );
InsertFirstChild( theText );
}
} }
void XMLElement::SetText( unsigned inNum ) void XMLElement::SetText( unsigned v )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( inNum, buf, BUF_SIZE ); XMLUtil::ToStr( v, buf, BUF_SIZE );
if ( FirstChild() && FirstChild()->ToText() ) SetText( buf );
FirstChild()->SetValue( buf );
else {
XMLText* theText = GetDocument()->NewText( buf );
InsertFirstChild( theText );
}
} }
void XMLElement::SetText( double inNum ) void XMLElement::SetText( bool v )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( inNum, buf, BUF_SIZE ); XMLUtil::ToStr( v, buf, BUF_SIZE );
if ( FirstChild() && FirstChild()->ToText() ) SetText( buf );
FirstChild()->SetValue( buf );
else {
XMLText* theText = GetDocument()->NewText( buf );
InsertFirstChild( theText );
}
} }
void XMLElement::SetText( float inNum ) void XMLElement::SetText( float v )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( inNum, buf, BUF_SIZE ); XMLUtil::ToStr( v, buf, BUF_SIZE );
if ( FirstChild() && FirstChild()->ToText() ) SetText( buf );
FirstChild()->SetValue( buf );
else {
XMLText* theText = GetDocument()->NewText( buf );
InsertFirstChild( theText );
}
} }
void XMLElement::SetText( long long inNum )
void XMLElement::SetText( double v )
{ {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
XMLUtil::ToStr( inNum, buf, BUF_SIZE ); XMLUtil::ToStr( v, buf, BUF_SIZE );
if ( FirstChild() && FirstChild()->ToText() ) SetText( buf );
FirstChild()->SetValue( buf );
else {
XMLText* theText = GetDocument()->NewText( buf );
InsertFirstChild( theText );
}
} }
void XMLElement::SetBoolFirstChild( bool inBool ) void XMLElement::SetBoolFirstChild( bool inBool )
{ {
if( FirstChild() && FirstChild()->ToElement() if( FirstChild() && FirstChild()->ToElement()

View File

@ -118,7 +118,7 @@ inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
static const int TIXML2_MAJOR_VERSION = 1; static const int TIXML2_MAJOR_VERSION = 1;
static const int TIXML2_MINOR_VERSION = 0; static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 13; static const int TIXML2_PATCH_VERSION = 14;
namespace tinyxml2 namespace tinyxml2
{ {
@ -1413,7 +1413,17 @@ public:
<foo>Hullaballoo!</foo> <foo>Hullaballoo!</foo>
@endverbatim @endverbatim
*/ */
void SetText( const char* inText ); void SetText( const char* inText );
/// Convenince method for setting text inside and element. See SetText() for important limitations.
void SetText( int value );
/// Convenince method for setting text inside and element. See SetText() for important limitations.
void SetText( unsigned value );
/// Convenince method for setting text inside and element. See SetText() for important limitations.
void SetText( bool value );
/// Convenince method for setting text inside and element. See SetText() for important limitations.
void SetText( double value );
/// Convenince method for setting text inside and element. See SetText() for important limitations.
void SetText( float value );
/// Sets the text to the given number. /// Sets the text to the given number.
void SetText( int inNum ); void SetText( int inNum );
@ -1547,6 +1557,7 @@ private:
//void LinkAttribute( XMLAttribute* attrib ); //void LinkAttribute( XMLAttribute* attrib );
char* ParseAttributes( char* p ); char* ParseAttributes( char* p );
enum { BUF_SIZE = 200 };
int _closingType; int _closingType;
// The attribute list is ordered; there is no 'lastAttribute' // The attribute list is ordered; there is no 'lastAttribute'
// because the list needs to be scanned for dupes before adding // because the list needs to be scanned for dupes before adding

View File

@ -624,83 +624,51 @@ int main( int argc, const char ** argv )
doc.Parse( str ); doc.Parse( str );
XMLElement* element = doc.RootElement(); XMLElement* element = doc.RootElement();
element->SetText("He kept turning his head to left and right, but I could not see anything through the darkness."); element->SetText("darkness.");
XMLTest( "SetText() normal use (open/close).", "He kept turning his head to left and right, but I could not see anything through the darkness.", element->GetText() ); XMLTest( "SetText() normal use (open/close).", "darkness.", element->GetText() );
element->SetText("Suddenly, away on our left I saw a faint flickering blue flame."); element->SetText("blue flame.");
XMLTest( "SetText() replace.", "Suddenly, away on our left I saw a faint flickering blue flame.", element->GetText() ); XMLTest( "SetText() replace.", "blue flame.", element->GetText() );
str = "<foo/>"; str = "<foo/>";
doc.Parse( str ); doc.Parse( str );
element = doc.RootElement(); element = doc.RootElement();
element->SetText("The driver saw it at the same moment."); element->SetText("The driver");
XMLTest( "SetText() normal use. (self-closing)", "The driver saw it at the same moment.", element->GetText() ); XMLTest( "SetText() normal use. (self-closing)", "The driver", element->GetText() );
element->SetText("<b>He at once checked the horses, and, jumping to the ground, disappeared into the darkness.</b>"); element->SetText("<b>horses</b>");
XMLTest( "SetText() replace with tag-like text.", "<b>He at once checked the horses, and, jumping to the ground, disappeared into the darkness.</b>", element->GetText() ); XMLTest( "SetText() replace with tag-like text.", "<b>horses</b>", element->GetText() );
//doc.Print();
str = "<foo><bar>Text in nested element</bar></foo>"; str = "<foo><bar>Text in nested element</bar></foo>";
doc.Parse( str ); doc.Parse( str );
element = doc.RootElement(); element = doc.RootElement();
element->SetText("I did not know what to do, the less as the howling of the wolves grew closer."); element->SetText("wolves");
XMLTest( "SetText() prefix to nested non-text children.", "I did not know what to do, the less as the howling of the wolves grew closer.", element->GetText() ); XMLTest( "SetText() prefix to nested non-text children.", "wolves", element->GetText() );
}
// --------SetBoolFirstChild()-----------
{
const char* str = "<foo></foo>";
XMLDocument doc;
doc.Parse( str );
XMLElement* element = doc.RootElement();
element->SetBoolFirstChild(true);
XMLTest( "SetBoolFirstChild() normal use (open/close).", "true", element->FirstChild()->ToElement()->Value() );
element->SetBoolFirstChild(false);
XMLTest( "SetBoolFirstChild() replace.", "false", element->FirstChild()->ToElement()->Value() );
str = "<foo/>"; str = "<foo/>";
doc.Parse( str ); doc.Parse( str );
element = doc.RootElement(); element = doc.RootElement();
element->SetBoolFirstChild(false);
XMLTest( "SetBoolFirstChild() normal use (self-closing).", "false", element->FirstChild()->ToElement()->Value() );
}
// --------BoolFirstChild()-----------
{
const char* str = "<foo><false /></foo>";
XMLDocument doc;
doc.Parse( str );
XMLElement* element = doc.RootElement();
XMLTest( "BoolFirstChild() normal use (open/close).", false, element->BoolFirstChild() );
str = "<foo><true /></foo>";
doc.Parse( str );
element = doc.RootElement();
XMLTest( "BoolFirstChild() normal use (open/close).", true, element->BoolFirstChild() );
str = "<foo></foo>";
doc.Parse( str );
element = doc.RootElement();
element->SetBoolFirstChild(true); element->SetText( "str" );
XMLTest( "BoolFirstChild() after SetBoolFirstChild().", true, element->BoolFirstChild() ); XMLTest( "SetText types", "str", element->GetText() );
element->SetBoolFirstChild(false); element->SetText( 1 );
XMLTest( "BoolFirstChild() after SetBoolFirstChild() replace.", false, element->BoolFirstChild() ); XMLTest( "SetText types", "1", element->GetText() );
str = "<foo/>"; element->SetText( 1U );
doc.Parse( str ); XMLTest( "SetText types", "1", element->GetText() );
element = doc.RootElement(); element->SetText( true );
element->SetBoolFirstChild(false); XMLTest( "SetText types", "1", element->GetText() ); // TODO: should be 'true'?
XMLTest( "BoolFirstChild() (self-closing) after SetBoolFirstChild() replace.", false, element->BoolFirstChild() );
element->SetText( 1.5f );
XMLTest( "SetText types", "1.5", element->GetText() );
element->SetText( 1.5 );
XMLTest( "SetText types", "1.5", element->GetText() );
} }