Skip to content

Commit b5d3ecb

Browse files
committed
Updated TinyXML, make use of second argument of XMLElement::Attribute()
1 parent c1594be commit b5d3ecb

5 files changed

Lines changed: 28 additions & 35 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
631631
// Rule file
632632
else if (std::strncmp(argv[i], "--rule-file=", 12) == 0) {
633633
tinyxml2::XMLDocument doc;
634-
if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_NO_ERROR) {
634+
if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_SUCCESS) {
635635
tinyxml2::XMLElement *node = doc.FirstChildElement();
636636
for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) {
637637
Settings::Rule rule;

externals/tinyxml/tinyxml2.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ distribution.
2424
#include "tinyxml2.h"
2525

2626
#include <new> // yes, this one new style header, is in the Android SDK.
27-
#if defined(ANDROID_NDK) || defined(__QNXNTO__)
27+
#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
2828
# include <stddef.h>
2929
# include <stdarg.h>
3030
#else
@@ -471,7 +471,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
471471
else {
472472
return 0;
473473
}
474-
TIXMLASSERT( digit >= 0 && digit < 16);
474+
TIXMLASSERT( digit < 16 );
475475
TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
476476
const unsigned int digitScaled = mult * digit;
477477
TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
@@ -501,7 +501,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
501501
while ( *q != '#' ) {
502502
if ( *q >= '0' && *q <= '9' ) {
503503
const unsigned int digit = *q - '0';
504-
TIXMLASSERT( digit >= 0 && digit < 10);
504+
TIXMLASSERT( digit < 10 );
505505
TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
506506
const unsigned int digitScaled = mult * digit;
507507
TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
@@ -776,6 +776,7 @@ void XMLNode::DeleteChild( XMLNode* node )
776776
TIXMLASSERT( node );
777777
TIXMLASSERT( node->_document == _document );
778778
TIXMLASSERT( node->_parent == this );
779+
Unlink( node );
779780
DeleteNode( node );
780781
}
781782

@@ -1285,7 +1286,7 @@ void XMLAttribute::SetName( const char* n )
12851286
XMLError XMLAttribute::QueryIntValue( int* value ) const
12861287
{
12871288
if ( XMLUtil::ToInt( Value(), value )) {
1288-
return XML_NO_ERROR;
1289+
return XML_SUCCESS;
12891290
}
12901291
return XML_WRONG_ATTRIBUTE_TYPE;
12911292
}
@@ -1294,7 +1295,7 @@ XMLError XMLAttribute::QueryIntValue( int* value ) const
12941295
XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const
12951296
{
12961297
if ( XMLUtil::ToUnsigned( Value(), value )) {
1297-
return XML_NO_ERROR;
1298+
return XML_SUCCESS;
12981299
}
12991300
return XML_WRONG_ATTRIBUTE_TYPE;
13001301
}
@@ -1303,7 +1304,7 @@ XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const
13031304
XMLError XMLAttribute::QueryBoolValue( bool* value ) const
13041305
{
13051306
if ( XMLUtil::ToBool( Value(), value )) {
1306-
return XML_NO_ERROR;
1307+
return XML_SUCCESS;
13071308
}
13081309
return XML_WRONG_ATTRIBUTE_TYPE;
13091310
}
@@ -1312,7 +1313,7 @@ XMLError XMLAttribute::QueryBoolValue( bool* value ) const
13121313
XMLError XMLAttribute::QueryFloatValue( float* value ) const
13131314
{
13141315
if ( XMLUtil::ToFloat( Value(), value )) {
1315-
return XML_NO_ERROR;
1316+
return XML_SUCCESS;
13161317
}
13171318
return XML_WRONG_ATTRIBUTE_TYPE;
13181319
}
@@ -1321,7 +1322,7 @@ XMLError XMLAttribute::QueryFloatValue( float* value ) const
13211322
XMLError XMLAttribute::QueryDoubleValue( double* value ) const
13221323
{
13231324
if ( XMLUtil::ToDouble( Value(), value )) {
1324-
return XML_NO_ERROR;
1325+
return XML_SUCCESS;
13251326
}
13261327
return XML_WRONG_ATTRIBUTE_TYPE;
13271328
}
@@ -1770,7 +1771,7 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
17701771
XMLNode( 0 ),
17711772
_writeBOM( false ),
17721773
_processEntities( processEntities ),
1773-
_errorID( XML_NO_ERROR ),
1774+
_errorID(XML_SUCCESS),
17741775
_whitespace( whitespace ),
17751776
_errorStr1( 0 ),
17761777
_errorStr2( 0 ),
@@ -1794,7 +1795,7 @@ void XMLDocument::Clear()
17941795
#ifdef DEBUG
17951796
const bool hadError = Error();
17961797
#endif
1797-
_errorID = XML_NO_ERROR;
1798+
_errorID = XML_SUCCESS;
17981799
_errorStr1 = 0;
17991800
_errorStr2 = 0;
18001801

@@ -1953,6 +1954,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
19531954
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
19541955
return _errorID;
19551956
}
1957+
TIXMLASSERT( filelength >= 0 );
19561958

19571959
if ( !LongFitsIntoSizeTMinusOne<>::Fits( filelength ) ) {
19581960
// Cannot handle files which won't fit in buffer together with null terminator
@@ -1998,7 +2000,7 @@ XMLError XMLDocument::SaveFile( FILE* fp, bool compact )
19982000
{
19992001
// Clear any error from the last save, otherwise it will get reported
20002002
// for *this* call.
2001-
SetError( XML_NO_ERROR, 0, 0 );
2003+
SetError(XML_SUCCESS, 0, 0);
20022004
XMLPrinter stream( fp, compact );
20032005
Print( &stream );
20042006
return _errorID;

externals/tinyxml/tinyxml2.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ distribution.
3030
# include <stdio.h>
3131
# include <stdlib.h>
3232
# include <string.h>
33+
# if defined(__PS3__)
34+
# include <stddef.h>
35+
# endif
3336
#else
3437
# include <cctype>
3538
# include <climits>
@@ -485,7 +488,6 @@ class TINYXML2_LIB XMLVisitor
485488
// WARNING: must match XMLDocument::_errorNames[]
486489
enum XMLError {
487490
XML_SUCCESS = 0,
488-
XML_NO_ERROR = 0,
489491
XML_NO_ATTRIBUTE,
490492
XML_WRONG_ATTRIBUTE_TYPE,
491493
XML_ERROR_FILE_NOT_FOUND,
@@ -893,7 +895,6 @@ class TINYXML2_LIB XMLNode
893895
*/
894896
class TINYXML2_LIB XMLText : public XMLNode
895897
{
896-
friend class XMLBase;
897898
friend class XMLDocument;
898899
public:
899900
virtual bool Accept( XMLVisitor* visitor ) const;
@@ -1142,7 +1143,6 @@ class TINYXML2_LIB XMLAttribute
11421143
*/
11431144
class TINYXML2_LIB XMLElement : public XMLNode
11441145
{
1145-
friend class XMLBase;
11461146
friend class XMLDocument;
11471147
public:
11481148
/// Get the name of an element (which is the Value() of the node.)
@@ -1675,7 +1675,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode
16751675

16761676
/// Return true if there was an error parsing the document.
16771677
bool Error() const {
1678-
return _errorID != XML_NO_ERROR;
1678+
return _errorID != XML_SUCCESS;
16791679
}
16801680
/// Return the errorID.
16811681
XMLError ErrorID() const {

lib/library.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Library::Error Library::load(const char exename[], const char path[])
9292
} else
9393
absolute_path = Path::getAbsoluteFilePath(path);
9494

95-
if (error == tinyxml2::XML_NO_ERROR) {
95+
if (error == tinyxml2::XML_SUCCESS) {
9696
if (_files.find(absolute_path) == _files.end()) {
9797
Error err = load(doc);
9898
if (err.errorcode == OK)
@@ -109,7 +109,7 @@ Library::Error Library::load(const char exename[], const char path[])
109109
bool Library::loadxmldata(const char xmldata[], std::size_t len)
110110
{
111111
tinyxml2::XMLDocument doc;
112-
return (tinyxml2::XML_NO_ERROR == doc.Parse(xmldata, len)) && (load(doc).errorcode == OK);
112+
return (tinyxml2::XML_SUCCESS == doc.Parse(xmldata, len)) && (load(doc).errorcode == OK);
113113
}
114114

115115
Library::Error Library::load(const tinyxml2::XMLDocument &doc)
@@ -161,10 +161,9 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
161161
AllocFunc temp;
162162
temp.groupId = allocationId;
163163

164-
const char *init = memorynode->Attribute("init");
165-
if (init && strcmp(init,"false")==0) {
164+
if (memorynode->Attribute("init", "false"))
166165
returnuninitdata.insert(memorynode->GetText());
167-
}
166+
168167
const char *arg = memorynode->Attribute("arg");
169168
if (arg)
170169
temp.arg = atoi(arg);
@@ -234,10 +233,8 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
234233
return Error(MISSING_ATTRIBUTE, "ext");
235234
_markupExtensions.insert(extension);
236235

237-
const char * const reporterrors = node->Attribute("reporterrors");
238-
_reporterrors[extension] = (reporterrors && strcmp(reporterrors, "true") == 0);
239-
const char * const aftercode = node->Attribute("aftercode");
240-
_processAfterCode[extension] = (aftercode && strcmp(aftercode, "true") == 0);
236+
_reporterrors[extension] = (node->Attribute("reporterrors", "true") != nullptr);
237+
_processAfterCode[extension] = (node->Attribute("aftercode", "true") != nullptr);
241238

242239
for (const tinyxml2::XMLElement *markupnode = node->FirstChildElement(); markupnode; markupnode = markupnode->NextSiblingElement()) {
243240
const std::string markupnodename = markupnode->Name();
@@ -339,9 +336,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
339336
const char* const itEndPattern = node->Attribute("itEndPattern");
340337
if (itEndPattern)
341338
container.itEndPattern = itEndPattern;
342-
const char* const opLessAllowed = node->Attribute("opLessAllowed");
343-
if (opLessAllowed)
344-
container.opLessAllowed = std::string(opLessAllowed) == "true";
339+
container.opLessAllowed = (node->Attribute("opLessAllowed", "true") != nullptr);
345340

346341
for (const tinyxml2::XMLElement *containerNode = node->FirstChildElement(); containerNode; containerNode = containerNode->NextSiblingElement()) {
347342
const std::string containerNodeName = containerNode->Name();
@@ -419,18 +414,14 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
419414
if (templateArg)
420415
container.size_templateArgNo = atoi(templateArg);
421416
} else if (containerNodeName == "access") {
422-
const char* const indexArg = containerNode->Attribute("indexOperator");
423-
if (indexArg)
424-
container.arrayLike_indexOp = std::string(indexArg) == "array-like";
417+
container.arrayLike_indexOp = (containerNode->Attribute("indexOperator", "array-like") != nullptr);
425418
}
426419
} else if (containerNodeName == "type") {
427420
const char* const templateArg = containerNode->Attribute("templateParameter");
428421
if (templateArg)
429422
container.type_templateArgNo = atoi(templateArg);
430423

431-
const char* const string = containerNode->Attribute("string");
432-
if (string)
433-
container.stdStringLike = std::string(string) == "std-like";
424+
container.stdStringLike = (containerNode->Attribute("string", "std-like") != nullptr);
434425
} else
435426
unknown_elements.insert(containerNodeName);
436427
}

lib/settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ bool Settings::platformFile(const std::string &filename)
275275
{
276276
// open file..
277277
tinyxml2::XMLDocument doc;
278-
if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_NO_ERROR)
278+
if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_SUCCESS)
279279
return false;
280280

281281
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();

0 commit comments

Comments
 (0)