Skip to content

Commit 4356cda

Browse files
halx99minggo
authored andcommitted
Remove tinyxml2 from CCSaxParser implement. (#20141)
1 parent ca9ffe0 commit 4356cda

File tree

1 file changed

+6
-63
lines changed

1 file changed

+6
-63
lines changed

cocos/platform/CCSAXParser.cpp

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -28,66 +28,10 @@
2828
#include <vector> // because its based on windows 8 build :P
2929

3030
#include "platform/CCFileUtils.h"
31-
#include "tinyxml2.h"
3231
#include "rapidxml/rapidxml_sax3.hpp"
3332

3433
NS_CC_BEGIN
3534

36-
class XmlSaxHander : public tinyxml2::XMLVisitor
37-
{
38-
public:
39-
XmlSaxHander():_ccsaxParserImp(0){};
40-
41-
virtual bool VisitEnter( const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* firstAttribute );
42-
virtual bool VisitExit( const tinyxml2::XMLElement& element );
43-
virtual bool Visit( const tinyxml2::XMLText& text );
44-
virtual bool Visit( const tinyxml2::XMLUnknown&){ return true; }
45-
46-
void setSAXParserImp(SAXParser* parser)
47-
{
48-
_ccsaxParserImp = parser;
49-
}
50-
51-
private:
52-
SAXParser *_ccsaxParserImp;
53-
};
54-
55-
56-
bool XmlSaxHander::VisitEnter( const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* firstAttribute )
57-
{
58-
//log(" VisitEnter %s",element.Value());
59-
60-
std::vector<const char*> attsVector;
61-
for( const tinyxml2::XMLAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() )
62-
{
63-
//log("%s", attrib->Name());
64-
attsVector.push_back(attrib->Name());
65-
//log("%s",attrib->Value());
66-
attsVector.push_back(attrib->Value());
67-
}
68-
69-
// nullptr is used in c++11
70-
//attsVector.push_back(nullptr);
71-
attsVector.push_back(nullptr);
72-
73-
SAXParser::startElement(_ccsaxParserImp, (const CC_XML_CHAR *)element.Value(), (const CC_XML_CHAR **)(&attsVector[0]));
74-
return true;
75-
}
76-
bool XmlSaxHander::VisitExit( const tinyxml2::XMLElement& element )
77-
{
78-
//log("VisitExit %s",element.Value());
79-
80-
SAXParser::endElement(_ccsaxParserImp, (const CC_XML_CHAR *)element.Value());
81-
return true;
82-
}
83-
84-
bool XmlSaxHander::Visit( const tinyxml2::XMLText& text )
85-
{
86-
//log("Visit %s",text.Value());
87-
SAXParser::textHandler(_ccsaxParserImp, (const CC_XML_CHAR *)text.Value(), strlen(text.Value()));
88-
return true;
89-
}
90-
9135
/// rapidxml SAX handler
9236
class RapidXmlSaxHander : public rapidxml::xml_sax2_handler
9337
{
@@ -136,12 +80,11 @@ bool SAXParser::init(const char* /*encoding*/)
13680

13781
bool SAXParser::parse(const char* xmlData, size_t dataLength)
13882
{
139-
tinyxml2::XMLDocument tinyDoc;
140-
tinyDoc.Parse(xmlData, dataLength);
141-
XmlSaxHander printer;
142-
printer.setSAXParserImp(this);
143-
144-
return tinyDoc.Accept( &printer );
83+
if(xmlData != nullptr && dataLength > 0) {
84+
std::string mutableData(xmlData, dataLength);
85+
return this->parseIntrusive(&mutableData.front(), dataLength);
86+
}
87+
return false;
14588
}
14689

14790
bool SAXParser::parse(const std::string& filename)
@@ -150,7 +93,7 @@ bool SAXParser::parse(const std::string& filename)
15093
Data data = FileUtils::getInstance()->getDataFromFile(filename);
15194
if (!data.isNull())
15295
{
153-
ret = parse((const char*)data.getBytes(), data.getSize());
96+
ret = parseIntrusive((char*)data.getBytes(), data.getSize());
15497
}
15598

15699
return ret;

0 commit comments

Comments
 (0)