Skip to content

Commit a11dca5

Browse files
committed
Update TinyXML-2
1 parent f34ab10 commit a11dca5

File tree

2 files changed

+145
-109
lines changed

2 files changed

+145
-109
lines changed

lib/TinyXML-2/tinyxml2.cpp

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,10 @@ distribution.
103103
#if defined(_WIN64)
104104
#define TIXML_FSEEK _fseeki64
105105
#define TIXML_FTELL _ftelli64
106-
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || (__CYGWIN__)
106+
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
107107
#define TIXML_FSEEK fseeko
108108
#define TIXML_FTELL ftello
109-
#elif defined(__ANDROID__)
110-
#if __ANDROID_API__ > 24
111-
#define TIXML_FSEEK fseeko64
112-
#define TIXML_FTELL ftello64
113-
#else
114-
#define TIXML_FSEEK fseeko
115-
#define TIXML_FTELL ftello
116-
#endif
117-
#elif defined(__unix__) && defined(__x86_64__)
109+
#elif defined(__ANDROID__) && __ANDROID_API__ > 24
118110
#define TIXML_FSEEK fseeko64
119111
#define TIXML_FTELL ftello64
120112
#else
@@ -613,7 +605,7 @@ void XMLUtil::ToStr( int64_t v, char* buffer, int bufferSize )
613605
void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize )
614606
{
615607
// horrible syntax trick to make the compiler happy about %llu
616-
TIXML_SNPRINTF(buffer, bufferSize, "%llu", (long long)v);
608+
TIXML_SNPRINTF(buffer, bufferSize, "%llu", static_cast<unsigned long long>(v));
617609
}
618610

619611
bool XMLUtil::ToInt(const char* str, int* value)
@@ -715,7 +707,7 @@ bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {
715707
}
716708

717709

718-
char* XMLDocument::Identify( char* p, XMLNode** node )
710+
char* XMLDocument::Identify( char* p, XMLNode** node, bool first )
719711
{
720712
TIXMLASSERT( node );
721713
TIXMLASSERT( p );
@@ -767,9 +759,19 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
767759
p += dtdHeaderLen;
768760
}
769761
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
770-
returnNode = CreateUnlinkedNode<XMLElement>( _elementPool );
771-
returnNode->_parseLineNum = _parseCurLineNum;
772-
p += elementHeaderLen;
762+
763+
// Preserve whitespace pedantically before closing tag, when it's immediately after opening tag
764+
if (WhitespaceMode() == PEDANTIC_WHITESPACE && first && p != start && *(p + elementHeaderLen) == '/') {
765+
returnNode = CreateUnlinkedNode<XMLText>(_textPool);
766+
returnNode->_parseLineNum = startLine;
767+
p = start; // Back it up, all the text counts.
768+
_parseCurLineNum = startLine;
769+
}
770+
else {
771+
returnNode = CreateUnlinkedNode<XMLElement>(_elementPool);
772+
returnNode->_parseLineNum = _parseCurLineNum;
773+
p += elementHeaderLen;
774+
}
773775
}
774776
else {
775777
returnNode = CreateUnlinkedNode<XMLText>( _textPool );
@@ -822,6 +824,34 @@ XMLNode::~XMLNode()
822824
}
823825
}
824826

827+
// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2.
828+
829+
int XMLNode::ChildElementCount(const char *value) const {
830+
int count = 0;
831+
832+
const XMLElement *e = FirstChildElement(value);
833+
834+
while (e) {
835+
e = e->NextSiblingElement(value);
836+
count++;
837+
}
838+
839+
return count;
840+
}
841+
842+
int XMLNode::ChildElementCount() const {
843+
int count = 0;
844+
845+
const XMLElement *e = FirstChildElement();
846+
847+
while (e) {
848+
e = e->NextSiblingElement();
849+
count++;
850+
}
851+
852+
return count;
853+
}
854+
825855
const char* XMLNode::Value() const
826856
{
827857
// Edge case: XMLDocuments don't have a Value. Return null.
@@ -1070,14 +1100,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
10701100
if (_document->Error())
10711101
return 0;
10721102

1103+
bool first = true;
10731104
while( p && *p ) {
10741105
XMLNode* node = 0;
10751106

1076-
p = _document->Identify( p, &node );
1107+
p = _document->Identify( p, &node, first );
10771108
TIXMLASSERT( p );
10781109
if ( node == 0 ) {
10791110
break;
10801111
}
1112+
first = false;
10811113

10821114
const int initialLineNum = node->_parseLineNum;
10831115

@@ -2189,7 +2221,7 @@ void XMLDocument::MarkInUse(const XMLNode* const node)
21892221
TIXMLASSERT(node);
21902222
TIXMLASSERT(node->_parent == 0);
21912223

2192-
for (int i = 0; i < _unlinked.Size(); ++i) {
2224+
for (size_t i = 0; i < _unlinked.Size(); ++i) {
21932225
if (node == _unlinked[i]) {
21942226
_unlinked.SwapRemove(i);
21952227
break;
@@ -2472,7 +2504,7 @@ void XMLDocument::ClearError() {
24722504

24732505
void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... )
24742506
{
2475-
TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT );
2507+
TIXMLASSERT(error >= 0 && error < XML_ERROR_COUNT);
24762508
_errorID = error;
24772509
_errorLineNum = lineNum;
24782510
_errorStr.Reset();
@@ -2481,7 +2513,8 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ...
24812513
char* buffer = new char[BUFFER_SIZE];
24822514

24832515
TIXMLASSERT(sizeof(error) <= sizeof(int));
2484-
TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", ErrorIDToName(error), int(error), int(error), lineNum);
2516+
TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d",
2517+
ErrorIDToName(error), static_cast<int>(error), static_cast<unsigned int>(error), lineNum);
24852518

24862519
if (format) {
24872520
size_t len = strlen(buffer);

0 commit comments

Comments
 (0)