Support for 'long long' number values.
This commit is contained in:
48
tinyxml2.cpp
48
tinyxml2.cpp
@@ -411,6 +411,12 @@ void XMLUtil::ToStr( int v, char* buffer, int bufferSize )
|
||||
}
|
||||
|
||||
|
||||
void XMLUtil::ToStr( long long v, char* buffer, int bufferSize )
|
||||
{
|
||||
TIXML_SNPRINTF( buffer, bufferSize, "%lld", v );
|
||||
}
|
||||
|
||||
|
||||
void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize )
|
||||
{
|
||||
TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
|
||||
@@ -446,6 +452,14 @@ bool XMLUtil::ToInt( const char* str, int* value )
|
||||
return false;
|
||||
}
|
||||
|
||||
bool XMLUtil::ToLongLong( const char* str, long long* value )
|
||||
{
|
||||
if ( TIXML_SSCANF( str, "%lld", value ) == 1 ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool XMLUtil::ToUnsigned( const char* str, unsigned *value )
|
||||
{
|
||||
if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
|
||||
@@ -1166,6 +1180,14 @@ void XMLAttribute::SetAttribute( int v )
|
||||
}
|
||||
|
||||
|
||||
void XMLAttribute::SetAttribute( long long v )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
XMLUtil::ToStr( v, buf, BUF_SIZE );
|
||||
_value.SetStr( buf );
|
||||
}
|
||||
|
||||
|
||||
void XMLAttribute::SetAttribute( unsigned v )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
@@ -1322,6 +1344,19 @@ void XMLElement::SetText( float inNum )
|
||||
}
|
||||
}
|
||||
|
||||
void XMLElement::SetText( long long inNum )
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
XMLUtil::ToStr( inNum, buf, BUF_SIZE );
|
||||
if ( FirstChild() && FirstChild()->ToText() )
|
||||
FirstChild()->SetValue( buf );
|
||||
else {
|
||||
XMLText* theText = GetDocument()->NewText( buf );
|
||||
InsertFirstChild( theText );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void XMLElement::SetBoolFirstChild( bool inBool )
|
||||
{
|
||||
@@ -1371,6 +1406,19 @@ XMLError XMLElement::QueryIntText( int* ival ) const
|
||||
}
|
||||
|
||||
|
||||
XMLError XMLElement::QueryLongLongText( long long* ival ) const
|
||||
{
|
||||
if ( FirstChild() && FirstChild()->ToText() ) {
|
||||
const char* t = FirstChild()->ToText()->Value();
|
||||
if ( XMLUtil::ToLongLong( t, ival ) ) {
|
||||
return XML_SUCCESS;
|
||||
}
|
||||
return XML_CAN_NOT_CONVERT_TEXT;
|
||||
}
|
||||
return XML_NO_TEXT_NODE;
|
||||
}
|
||||
|
||||
|
||||
XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
|
||||
{
|
||||
if ( FirstChild() && FirstChild()->ToText() ) {
|
||||
|
||||
Reference in New Issue
Block a user