From 8f8f3c541543cce35ff71b9a545a3619f174049f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 31 Jan 2022 12:53:04 +0100 Subject: [PATCH] pattern: Actually fix strings being displayed wrong --- .../hex/pattern_language/pattern_data.hpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/libimhex/include/hex/pattern_language/pattern_data.hpp b/lib/libimhex/include/hex/pattern_language/pattern_data.hpp index 35372d5a6..2157e4ee9 100644 --- a/lib/libimhex/include/hex/pattern_language/pattern_data.hpp +++ b/lib/libimhex/include/hex/pattern_language/pattern_data.hpp @@ -27,17 +27,16 @@ namespace hex::pl { namespace { - template T> - std::string makeDisplayable(T *data, size_t size) { + std::string makeDisplayable(const std::string &string) { std::string result; - for (T *c = data; c < (data + size); c++) { - if (iscntrl(*c) || *c > 0x7F) + for (auto &c : string) { + if (iscntrl(c) || c > 0x7F) result += " "; else - result += static_cast(*c); + result += c; } - if (size != 0 && *(data + size - 1) == '\x00') + if (string.length() != 0 && string.back() == '\x00') result.pop_back(); return result; @@ -689,11 +688,7 @@ namespace hex::pl { provider->read(this->getOffset(), buffer.data(), size); - buffer.erase(std::remove_if(buffer.begin(), buffer.end(), [](auto c){ - return c == 0x00; - }), buffer.end()); - - this->createDefaultEntry(hex::format("\"{0}\" {1}", makeDisplayable(buffer.data(), this->getSize()), size > this->getSize() ? "(truncated)" : ""), buffer); + this->createDefaultEntry(hex::format("\"{0}\" {1}", makeDisplayable(buffer), size > this->getSize() ? "(truncated)" : ""), buffer); } [[nodiscard]] std::string getFormattedName() const override {