From 26a7b3325dc14a2a5fcd2875d5db43c4287dec35 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 22 Mar 2022 08:19:46 +0100 Subject: [PATCH] patterns: Unified displaying and stringifying string patterns --- .../pattern_language/patterns/pattern_string.hpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_string.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_string.hpp index e3b23adae..5e25e5822 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_string.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_string.hpp @@ -13,11 +13,11 @@ namespace hex::pl { return std::unique_ptr(new PatternString(*this)); } - std::string getValue(prv::Provider *&provider) { + std::string getValue(prv::Provider *&provider) const { return this->getValue(provider, this->getSize()); } - std::string getValue(prv::Provider *&provider, size_t size) { + std::string getValue(prv::Provider *&provider, size_t size) const { std::vector buffer(size, 0x00); provider->read(this->getOffset(), buffer.data(), size); return hex::encodeByteString(buffer); @@ -28,14 +28,7 @@ namespace hex::pl { } [[nodiscard]] std::string toString(prv::Provider *provider) const override { - std::string buffer(this->getSize(), 0x00); - provider->read(this->getOffset(), buffer.data(), buffer.size()); - - std::erase_if(buffer, [](auto c) { - return c == 0x00; - }); - - return buffer; + return this->getValue(provider); } [[nodiscard]] bool operator==(const Pattern &other) const override { return areCommonPropertiesEqual(other); }