[BUG] Fix TMX Tiled Map `CSV`, `BASE64`, & `ZLIB` incorrect parsing (#1131)

* Fix TMX Tiled Map `CSV`, `BASE64`, & `ZLIB` incorrect parsing

* Revert "Fix TMX Tiled Map `CSV`, `BASE64`, & `ZLIB` incorrect parsing"

This reverts commit 3088123a20.

* Use `std::regex_replace` instead

* Avoid copying strings

* Update CCTMXXMLParser.cpp
This commit is contained in:
Turky Mohammed 2023-03-24 17:33:13 -07:00 committed by GitHub
parent 4c90ac17a4
commit eae2ffabcb
1 changed files with 3 additions and 1 deletions

View File

@ -30,6 +30,7 @@ THE SOFTWARE.
#include "2d/CCTMXXMLParser.h" #include "2d/CCTMXXMLParser.h"
#include <unordered_map> #include <unordered_map>
#include <sstream> #include <sstream>
#include <regex>
// #include "2d/CCTMXTiledMap.h" // #include "2d/CCTMXTiledMap.h"
#include "base/ZipUtils.h" #include "base/ZipUtils.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
@ -687,8 +688,8 @@ void TMXMapInfo::endElement(void* /*ctx*/, const char* name)
tmxMapInfo->setStoringCharacters(false); tmxMapInfo->setStoringCharacters(false);
TMXLayerInfo* layer = tmxMapInfo->getLayers().back(); TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
auto currentString = tmxMapInfo->getCurrentString(); auto currentString = tmxMapInfo->getCurrentString();
unsigned char* buffer; unsigned char* buffer;
auto len = utils::base64Decode((unsigned char*)currentString.data(), (unsigned int)currentString.length(), auto len = utils::base64Decode((unsigned char*)currentString.data(), (unsigned int)currentString.length(),
&buffer); &buffer);
@ -808,6 +809,7 @@ void TMXMapInfo::textHandler(void* /*ctx*/, const char* ch, size_t len)
{ {
TMXMapInfo* tmxMapInfo = this; TMXMapInfo* tmxMapInfo = this;
std::string text(ch, 0, len); std::string text(ch, 0, len);
text = std::regex_replace(text, std::regex("[\n\r ]"), "");
if (tmxMapInfo->isStoringCharacters()) if (tmxMapInfo->isStoringCharacters())
{ {