Update TinyXML2 to 9.0.0

This updates TinyXML2 to the major release tagged on June 6, 2021.
This commit is contained in:
Misa 2022-02-11 11:52:59 -08:00
parent 84f9bb6dd6
commit ed4d3d0fa8
2 changed files with 98 additions and 52 deletions

View File

@ -103,7 +103,7 @@ distribution.
#if defined(_WIN64)
#define TIXML_FSEEK _fseeki64
#define TIXML_FTELL _ftelli64
#elif defined(__APPLE__) || (__FreeBSD__) || (__OpenBSD__)
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__ANDROID__)
#define TIXML_FSEEK fseeko
#define TIXML_FTELL ftello
#elif defined(__unix__) && defined(__x86_64__)
@ -234,13 +234,13 @@ char* StrPair::ParseName( char* p )
if ( !p || !(*p) ) {
return 0;
}
if ( !XMLUtil::IsNameStartChar( *p ) ) {
if ( !XMLUtil::IsNameStartChar( (unsigned char) *p ) ) {
return 0;
}
char* const start = p;
++p;
while ( *p && XMLUtil::IsNameChar( *p ) ) {
while ( *p && XMLUtil::IsNameChar( (unsigned char) *p ) ) {
++p;
}
@ -608,17 +608,26 @@ void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize )
TIXML_SNPRINTF(buffer, bufferSize, "%llu", (long long)v);
}
bool XMLUtil::ToInt( const char* str, int* value )
bool XMLUtil::ToInt(const char* str, int* value)
{
if ( TIXML_SSCANF( str, "%d", value ) == 1 ) {
return true;
if (IsPrefixHex(str)) {
unsigned v;
if (TIXML_SSCANF(str, "%x", &v) == 1) {
*value = static_cast<int>(v);
return true;
}
}
else {
if (TIXML_SSCANF(str, "%d", value) == 1) {
return true;
}
}
return false;
}
bool XMLUtil::ToUnsigned( const char* str, unsigned *value )
bool XMLUtil::ToUnsigned(const char* str, unsigned* value)
{
if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%u", value) == 1) {
return true;
}
return false;
@ -670,18 +679,27 @@ bool XMLUtil::ToDouble( const char* str, double* value )
bool XMLUtil::ToInt64(const char* str, int64_t* value)
{
long long v = 0; // horrible syntax trick to make the compiler happy about %lld
if (TIXML_SSCANF(str, "%lld", &v) == 1) {
*value = static_cast<int64_t>(v);
return true;
}
if (IsPrefixHex(str)) {
unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llx
if (TIXML_SSCANF(str, "%llx", &v) == 1) {
*value = static_cast<int64_t>(v);
return true;
}
}
else {
long long v = 0; // horrible syntax trick to make the compiler happy about %lld
if (TIXML_SSCANF(str, "%lld", &v) == 1) {
*value = static_cast<int64_t>(v);
return true;
}
}
return false;
}
bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {
unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llu
if(TIXML_SSCANF(str, "%llu", &v) == 1) {
if(TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%llu", &v) == 1) {
*value = (uint64_t)v;
return true;
}
@ -1637,8 +1655,18 @@ float XMLElement::FloatAttribute(const char* name, float defaultValue) const
const char* XMLElement::GetText() const
{
if ( FirstChild() && FirstChild()->ToText() ) {
return FirstChild()->Value();
/* skip comment node */
const XMLNode* node = FirstChild();
while (node) {
if (node->ToComment()) {
node = node->NextSibling();
continue;
}
break;
}
if ( node && node->ToText() ) {
return node->Value();
}
return 0;
}
@ -1909,7 +1937,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
}
// attribute.
if (XMLUtil::IsNameStartChar( *p ) ) {
if (XMLUtil::IsNameStartChar( (unsigned char) *p ) ) {
XMLAttribute* attrib = CreateAttribute();
TIXMLASSERT( attrib );
attrib->_parseLineNum = _document->_parseCurLineNum;
@ -2427,6 +2455,13 @@ void XMLDocument::Print( XMLPrinter* streamer ) const
}
void XMLDocument::ClearError() {
_errorID = XML_SUCCESS;
_errorLineNum = 0;
_errorStr.Reset();
}
void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... )
{
TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT );
@ -2659,22 +2694,33 @@ void XMLPrinter::PushHeader( bool writeBOM, bool writeDec )
}
}
void XMLPrinter::OpenElement( const char* name, bool compactMode )
void XMLPrinter::PrepareForNewNode( bool compactMode )
{
SealElementIfJustOpened();
_stack.Push( name );
if ( _textDepth < 0 && !_firstElement && !compactMode ) {
if ( compactMode ) {
return;
}
if ( _firstElement ) {
PrintSpace (_depth);
} else if ( _textDepth < 0) {
Putc( '\n' );
PrintSpace( _depth );
}
_firstElement = false;
}
void XMLPrinter::OpenElement( const char* name, bool compactMode )
{
PrepareForNewNode( compactMode );
_stack.Push( name );
Write ( "<" );
Write ( name );
_elementJustOpened = true;
_firstElement = false;
++_depth;
}
@ -2850,12 +2896,7 @@ void XMLPrinter::PushText( double value )
void XMLPrinter::PushComment( const char* comment )
{
SealElementIfJustOpened();
if ( _textDepth < 0 && !_firstElement && !_compactMode) {
Putc( '\n' );
PrintSpace( _depth );
}
_firstElement = false;
PrepareForNewNode( _compactMode );
Write( "<!--" );
Write( comment );
@ -2865,12 +2906,7 @@ void XMLPrinter::PushComment( const char* comment )
void XMLPrinter::PushDeclaration( const char* value )
{
SealElementIfJustOpened();
if ( _textDepth < 0 && !_firstElement && !_compactMode) {
Putc( '\n' );
PrintSpace( _depth );
}
_firstElement = false;
PrepareForNewNode( _compactMode );
Write( "<?" );
Write( value );
@ -2880,12 +2916,7 @@ void XMLPrinter::PushDeclaration( const char* value )
void XMLPrinter::PushUnknown( const char* value )
{
SealElementIfJustOpened();
if ( _textDepth < 0 && !_firstElement && !_compactMode) {
Putc( '\n' );
PrintSpace( _depth );
}
_firstElement = false;
PrepareForNewNode( _compactMode );
Write( "<!" );
Write( value );

View File

@ -79,6 +79,7 @@ distribution.
#endif
#if !defined(TIXMLASSERT)
#if defined(TINYXML2_DEBUG)
# if defined(_MSC_VER)
# // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
@ -93,16 +94,16 @@ distribution.
#else
# define TIXMLASSERT( x ) {}
#endif
#endif
/* Versioning, past 1.0.14:
http://semver.org/
*/
static const int TIXML2_MAJOR_VERSION = 8;
static const int TIXML2_MAJOR_VERSION = 9;
static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 0;
#define TINYXML2_MAJOR_VERSION 8
#define TINYXML2_MAJOR_VERSION 9
#define TINYXML2_MINOR_VERSION 0
#define TINYXML2_PATCH_VERSION 0
@ -135,7 +136,7 @@ class XMLPrinter;
class TINYXML2_LIB StrPair
{
public:
enum {
enum Mode {
NEEDS_ENTITY_PROCESSING = 0x01,
NEEDS_NEWLINE_NORMALIZATION = 0x02,
NEEDS_WHITESPACE_COLLAPSING = 0x04,
@ -590,6 +591,11 @@ public:
|| ch == '-';
}
inline static bool IsPrefixHex( const char* p) {
p = SkipWhiteSpace(p, 0);
return p && *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X');
}
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
if ( p == q ) {
return true;
@ -1451,6 +1457,10 @@ public:
return QueryFloatAttribute( name, value );
}
XMLError QueryAttribute(const char* name, const char** value) const {
return QueryStringAttribute(name, value);
}
/// Sets the named attribute to value.
void SetAttribute( const char* name, const char* value ) {
XMLAttribute* a = FindOrCreateAttribute( name );
@ -1478,7 +1488,7 @@ public:
XMLAttribute* a = FindOrCreateAttribute(name);
a->SetAttribute(value);
}
/// Sets the named attribute to value.
void SetAttribute( const char* name, bool value ) {
XMLAttribute* a = FindOrCreateAttribute( name );
@ -1864,9 +1874,8 @@ public:
*/
void DeleteNode( XMLNode* node );
void ClearError() {
SetError(XML_SUCCESS, 0, 0);
}
/// Clears the error flags.
void ClearError();
/// Return true if there was an error parsing the document.
bool Error() const {
@ -2322,16 +2331,22 @@ protected:
the space and tabs used. A PrintSpace() override should call Print().
*/
virtual void PrintSpace( int depth );
void Print( const char* format, ... );
void Write( const char* data, size_t size );
inline void Write( const char* data ) { Write( data, strlen( data ) ); }
void Putc( char ch );
virtual void Print( const char* format, ... );
virtual void Write( const char* data, size_t size );
virtual void Putc( char ch );
inline void Write(const char* data) { Write(data, strlen(data)); }
void SealElementIfJustOpened();
bool _elementJustOpened;
DynArray< const char*, 10 > _stack;
private:
/**
Prepares to write a new node. This includes sealing an element that was
just opened, and writing any whitespace necessary if not in compact mode.
*/
void PrepareForNewNode( bool compactMode );
void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
bool _firstElement;