@@ -103,12 +103,17 @@ distribution.
103103#if defined(_WIN64)
104104 #define TIXML_FSEEK _fseeki64
105105 #define TIXML_FTELL _ftelli64
106- #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__ANDROID__ )
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(__unix__) && defined(__x86_64__)
110- #define TIXML_FSEEK fseeko64
111- #define TIXML_FTELL ftello64
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
112117#else
113118 #define TIXML_FSEEK fseek
114119 #define TIXML_FTELL ftell
@@ -707,7 +712,7 @@ bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {
707712}
708713
709714
710- char * XMLDocument::Identify ( char * p, XMLNode** node )
715+ char * XMLDocument::Identify ( char * p, XMLNode** node, bool first )
711716{
712717 TIXMLASSERT ( node );
713718 TIXMLASSERT ( p );
@@ -759,9 +764,19 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
759764 p += dtdHeaderLen;
760765 }
761766 else if ( XMLUtil::StringEqual ( p, elementHeader, elementHeaderLen ) ) {
762- returnNode = CreateUnlinkedNode<XMLElement>( _elementPool );
763- returnNode->_parseLineNum = _parseCurLineNum;
764- p += elementHeaderLen;
767+
768+ // Preserve whitespace pedantically before closing tag, when it's immediately after opening tag
769+ if (WhitespaceMode () == PEDANTIC_WHITESPACE && first && p != start && *(p + elementHeaderLen) == ' /' ) {
770+ returnNode = CreateUnlinkedNode<XMLText>(_textPool);
771+ returnNode->_parseLineNum = startLine;
772+ p = start; // Back it up, all the text counts.
773+ _parseCurLineNum = startLine;
774+ }
775+ else {
776+ returnNode = CreateUnlinkedNode<XMLElement>(_elementPool);
777+ returnNode->_parseLineNum = _parseCurLineNum;
778+ p += elementHeaderLen;
779+ }
765780 }
766781 else {
767782 returnNode = CreateUnlinkedNode<XMLText>( _textPool );
@@ -814,6 +829,34 @@ XMLNode::~XMLNode()
814829 }
815830}
816831
832+ // ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2.
833+
834+ int XMLNode::ChildElementCount (const char *value) const {
835+ int count = 0 ;
836+
837+ const XMLElement *e = FirstChildElement (value);
838+
839+ while (e) {
840+ e = e->NextSiblingElement (value);
841+ count++;
842+ }
843+
844+ return count;
845+ }
846+
847+ int XMLNode::ChildElementCount () const {
848+ int count = 0 ;
849+
850+ const XMLElement *e = FirstChildElement ();
851+
852+ while (e) {
853+ e = e->NextSiblingElement ();
854+ count++;
855+ }
856+
857+ return count;
858+ }
859+
817860const char * XMLNode::Value () const
818861{
819862 // Edge case: XMLDocuments don't have a Value. Return null.
@@ -1062,21 +1105,23 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
10621105 if (_document->Error ())
10631106 return 0 ;
10641107
1108+ bool first = true ;
10651109 while ( p && *p ) {
10661110 XMLNode* node = 0 ;
10671111
1068- p = _document->Identify ( p, &node );
1112+ p = _document->Identify ( p, &node, first );
10691113 TIXMLASSERT ( p );
10701114 if ( node == 0 ) {
10711115 break ;
10721116 }
1117+ first = false ;
10731118
10741119 const int initialLineNum = node->_parseLineNum ;
10751120
10761121 StrPair endTag;
10771122 p = node->ParseDeep ( p, &endTag, curLineNumPtr );
10781123 if ( !p ) {
1079- DeleteNode ( node );
1124+ _document-> DeleteNode ( node );
10801125 if ( !_document->Error () ) {
10811126 _document->SetError ( XML_ERROR_PARSING, initialLineNum, 0 );
10821127 }
@@ -1109,7 +1154,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
11091154 }
11101155 if ( !wellLocated ) {
11111156 _document->SetError ( XML_ERROR_PARSING_DECLARATION, initialLineNum, " XMLDeclaration value=%s" , decl->Value ());
1112- DeleteNode ( node );
1157+ _document-> DeleteNode ( node );
11131158 break ;
11141159 }
11151160 }
@@ -1144,7 +1189,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
11441189 }
11451190 if ( mismatch ) {
11461191 _document->SetError ( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, " XMLElement name=%s" , ele->Name ());
1147- DeleteNode ( node );
1192+ _document-> DeleteNode ( node );
11481193 break ;
11491194 }
11501195 }
@@ -1776,11 +1821,11 @@ XMLError XMLElement::QueryInt64Text(int64_t* ival) const
17761821}
17771822
17781823
1779- XMLError XMLElement::QueryUnsigned64Text (uint64_t * ival ) const
1824+ XMLError XMLElement::QueryUnsigned64Text (uint64_t * uval ) const
17801825{
17811826 if (FirstChild () && FirstChild ()->ToText ()) {
17821827 const char * t = FirstChild ()->Value ();
1783- if (XMLUtil::ToUnsigned64 (t, ival )) {
1828+ if (XMLUtil::ToUnsigned64 (t, uval )) {
17841829 return XML_SUCCESS;
17851830 }
17861831 return XML_CAN_NOT_CONVERT_TEXT;
@@ -2412,21 +2457,21 @@ XMLError XMLDocument::SaveFile( FILE* fp, bool compact )
24122457}
24132458
24142459
2415- XMLError XMLDocument::Parse ( const char * p , size_t len )
2460+ XMLError XMLDocument::Parse ( const char * xml , size_t nBytes )
24162461{
24172462 Clear ();
24182463
2419- if ( len == 0 || !p || !*p ) {
2464+ if ( nBytes == 0 || !xml || !*xml ) {
24202465 SetError ( XML_ERROR_EMPTY_DOCUMENT, 0 , 0 );
24212466 return _errorID;
24222467 }
2423- if ( len == static_cast <size_t >(-1 ) ) {
2424- len = strlen ( p );
2468+ if ( nBytes == static_cast <size_t >(-1 ) ) {
2469+ nBytes = strlen ( xml );
24252470 }
24262471 TIXMLASSERT ( _charBuffer == 0 );
2427- _charBuffer = new char [ len +1 ];
2428- memcpy ( _charBuffer, p, len );
2429- _charBuffer[len ] = 0 ;
2472+ _charBuffer = new char [ nBytes +1 ];
2473+ memcpy ( _charBuffer, xml, nBytes );
2474+ _charBuffer[nBytes ] = 0 ;
24302475
24312476 Parse ();
24322477 if ( Error () ) {
0 commit comments