diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index ca5b9c47..f6931bf8 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -209,13 +209,23 @@ void UtilityClass::updateglow() } } -bool is_positive_num(const std::string& str) +bool is_positive_num(const std::string& str, bool hex) { for (size_t i = 0; i < str.length(); i++) { - if (!std::isdigit(static_cast(str[i]))) + if (hex) { - return false; + if (!std::isxdigit(static_cast(str[i]))) + { + return false; + } + } + else + { + if (!std::isdigit(static_cast(str[i]))) + { + return false; + } } } return true; diff --git a/desktop_version/src/UtilityClass.h b/desktop_version/src/UtilityClass.h index 9842f17b..dcd6c6cd 100644 --- a/desktop_version/src/UtilityClass.h +++ b/desktop_version/src/UtilityClass.h @@ -11,7 +11,7 @@ std::vector split(const std::string &s, char delim, std::vector split(const std::string &s, char delim); -bool is_positive_num(const std::string& str); +bool is_positive_num(const std::string& str, bool hex); #define INBOUNDS(index, vector) ((int) index >= 0 && (int) index < (int) vector.size()) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index ba60ba72..d112ba8e 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -20,6 +20,9 @@ #include #include +#include +#include + edlevelclass::edlevelclass() { tileset=0; @@ -161,16 +164,26 @@ std::string find_tag(const std::string& buf, const std::string& start, const std size_t start_pos = 0; while ((start_pos = value.find("&#", start_pos)) != std::string::npos) { + bool hex = value[start_pos + 2] == 'x'; size_t end = value.find(';', start_pos); - std::string number(value.substr(start_pos + 2, end - start_pos)); + size_t real_start = start_pos + 2 + ((int) hex); + std::string number(value.substr(real_start, end - real_start)); - if (!is_positive_num(number)) + if (!is_positive_num(number, hex)) { return ""; } - int character = atoi(number.c_str()); - int utf32[] = {character, 0}; + uint32_t character = 0; + if (hex) + { + sscanf(number.c_str(), "%" SCNx32, &character); + } + else + { + sscanf(number.c_str(), "%" SCNu32, &character); + } + uint32_t utf32[] = {character, 0}; std::string utf8; utf8::unchecked::utf32to8(utf32, utf32 + 1, std::back_inserter(utf8)); value.replace(start_pos, end - start_pos + 1, utf8);