mirror of https://github.com/AxioDL/tinyxml2.git
add variants of SetText() to support types
This commit is contained in:
parent
9c0678a01d
commit
5bb2d8079b
|
@ -10,7 +10,7 @@ include(GNUInstallDirs)
|
|||
################################
|
||||
# set lib version here
|
||||
|
||||
set(GENERIC_LIB_VERSION "1.0.13")
|
||||
set(GENERIC_LIB_VERSION "1.0.14")
|
||||
set(GENERIC_LIB_SOVERSION "1")
|
||||
|
||||
|
||||
|
|
2
dox
2
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.13
|
||||
PROJECT_NUMBER = 1.0.14
|
||||
|
||||
# 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
|
||||
|
|
41
tinyxml2.cpp
41
tinyxml2.cpp
|
@ -1270,6 +1270,47 @@ void XMLElement::SetText( const char* inText )
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void XMLElement::SetText( int v )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
XMLUtil::ToStr( v, buf, BUF_SIZE );
|
||||
SetText( buf );
|
||||
}
|
||||
|
||||
|
||||
void XMLElement::SetText( unsigned v )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
XMLUtil::ToStr( v, buf, BUF_SIZE );
|
||||
SetText( buf );
|
||||
}
|
||||
|
||||
|
||||
void XMLElement::SetText( bool v )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
XMLUtil::ToStr( v, buf, BUF_SIZE );
|
||||
SetText( buf );
|
||||
}
|
||||
|
||||
|
||||
void XMLElement::SetText( float v )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
XMLUtil::ToStr( v, buf, BUF_SIZE );
|
||||
SetText( buf );
|
||||
}
|
||||
|
||||
|
||||
void XMLElement::SetText( double v )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
XMLUtil::ToStr( v, buf, BUF_SIZE );
|
||||
SetText( buf );
|
||||
}
|
||||
|
||||
|
||||
XMLError XMLElement::QueryIntText( int* ival ) const
|
||||
{
|
||||
if ( FirstChild() && FirstChild()->ToText() ) {
|
||||
|
|
15
tinyxml2.h
15
tinyxml2.h
|
@ -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_MINOR_VERSION = 0;
|
||||
static const int TIXML2_PATCH_VERSION = 13;
|
||||
static const int TIXML2_PATCH_VERSION = 14;
|
||||
|
||||
namespace tinyxml2
|
||||
{
|
||||
|
@ -1403,7 +1403,17 @@ public:
|
|||
<foo>Hullaballoo!</foo>
|
||||
@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 );
|
||||
|
||||
/**
|
||||
Convenience method to query the value of a child text node. This is probably best
|
||||
|
@ -1465,6 +1475,7 @@ private:
|
|||
//void LinkAttribute( XMLAttribute* attrib );
|
||||
char* ParseAttributes( char* p );
|
||||
|
||||
enum { BUF_SIZE = 200 };
|
||||
int _closingType;
|
||||
// The attribute list is ordered; there is no 'lastAttribute'
|
||||
// because the list needs to be scanned for dupes before adding
|
||||
|
|
22
xmltest.cpp
22
xmltest.cpp
|
@ -647,6 +647,28 @@ int main( int argc, const char ** argv )
|
|||
|
||||
element->SetText("wolves");
|
||||
XMLTest( "SetText() prefix to nested non-text children.", "wolves", element->GetText() );
|
||||
|
||||
str = "<foo/>";
|
||||
doc.Parse( str );
|
||||
element = doc.RootElement();
|
||||
|
||||
element->SetText( "str" );
|
||||
XMLTest( "SetText types", "str", element->GetText() );
|
||||
|
||||
element->SetText( 1 );
|
||||
XMLTest( "SetText types", "1", element->GetText() );
|
||||
|
||||
element->SetText( 1U );
|
||||
XMLTest( "SetText types", "1", element->GetText() );
|
||||
|
||||
element->SetText( true );
|
||||
XMLTest( "SetText types", "1", element->GetText() ); // TODO: should be 'true'?
|
||||
|
||||
element->SetText( 1.5f );
|
||||
XMLTest( "SetText types", "1.5", element->GetText() );
|
||||
|
||||
element->SetText( 1.5 );
|
||||
XMLTest( "SetText types", "1.5", element->GetText() );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue