1
0
mirror of https://github.com/ScrelliCopter/tmx2gba.git synced 2025-02-21 03:29:25 +11:00

Trim leading and tailing whitespace in base64 string, fixes exception in base64 lib

This commit is contained in:
2022-09-07 04:03:49 +10:00
parent ff162de80a
commit 62582723bc
2 changed files with 12 additions and 4 deletions

View File

@@ -46,11 +46,19 @@ TmxReader::~TmxReader()
}
bool TmxReader::DecodeMap(uint32_t* aOut, size_t aOutSize, const std::string& aStrIn)
bool TmxReader::DecodeMap(uint32_t* aOut, size_t aOutSize, const std::string& aBase64Dat)
{
// Cut leading & trailing whitespace (including newlines)
auto beg = std::find_if_not(aBase64Dat.begin(), aBase64Dat.end(), std::isspace);
if (beg == std::end(aBase64Dat))
return false;
auto end = std::find_if_not(aBase64Dat.rbegin(), aBase64Dat.rend(), std::isspace);
std::size_t begOff = std::distance(std::begin(aBase64Dat), beg);
std::size_t endOff = std::distance(end, std::rend(aBase64Dat)) - begOff;
auto trimmed = aBase64Dat.substr(begOff, endOff);
// Decode base64 string.
size_t cutTheCrap = aStrIn.find_first_not_of(" \t\n\r");
std::string decoded = base64_decode(aStrIn.substr(cutTheCrap));
std::string decoded = base64_decode(trimmed);
// Decompress compressed data.
auto dstSize = static_cast<mz_ulong>(aOutSize);

View File

@@ -32,7 +32,7 @@ public:
uint32_t LidFromGid(uint32_t aGid);
private:
static bool DecodeMap(uint32_t* aOut, size_t aOutSize, const std::string& aStrIn);
static bool DecodeMap(uint32_t* aOut, size_t aOutSize, const std::string& aBase64Dat);
void ReadTileset(rapidxml::xml_node<>* aXNode);
void ReadLayer(rapidxml::xml_node<>* aXNode);
void ReadObjects(rapidxml::xml_node<>* aXNode);