1
0
mirror of synced 2024-11-28 09:30:51 +01:00

patterns: Unified displaying and stringifying string patterns

This commit is contained in:
WerWolv 2022-03-22 08:19:46 +01:00
parent 47fd5bdc00
commit 26a7b3325d

View File

@ -13,11 +13,11 @@ namespace hex::pl {
return std::unique_ptr<Pattern>(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<u8> 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<decltype(*this)>(other); }