mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
fix: String inspector rows not displaying the correctly decoded value
This commit is contained in:
@@ -362,7 +362,7 @@ namespace hex {
|
||||
|
||||
[[nodiscard]] std::optional<std::string> getEnvironmentVariable(const std::string &env);
|
||||
|
||||
[[nodiscard]] std::string limitStringLength(const std::string &string, size_t maxLength);
|
||||
[[nodiscard]] std::string limitStringLength(const std::string &string, size_t maxLength, bool fromBothEnds = true);
|
||||
|
||||
[[nodiscard]] std::optional<std::fs::path> getInitialFilePath();
|
||||
|
||||
|
||||
@@ -601,13 +601,13 @@ namespace hex {
|
||||
return value;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string limitStringLength(const std::string &string, size_t maxLength) {
|
||||
[[nodiscard]] std::string limitStringLength(const std::string &string, size_t maxLength, bool fromBothEnds) {
|
||||
// If the string is shorter than the max length, return it as is
|
||||
if (string.size() < maxLength)
|
||||
return string;
|
||||
|
||||
// If the string is longer than the max length, find the last space before the max length
|
||||
auto it = string.begin() + maxLength / 2;
|
||||
auto it = string.begin() + (fromBothEnds ? maxLength / 2 : maxLength);
|
||||
while (it != string.begin() && !std::isspace(*it)) --it;
|
||||
|
||||
// If there's no space before the max length, just cut the string
|
||||
@@ -624,6 +624,9 @@ namespace hex {
|
||||
|
||||
auto result = std::string(string.begin(), it) + "…";
|
||||
|
||||
if (!fromBothEnds)
|
||||
return result;
|
||||
|
||||
// If the string is longer than the max length, find the last space before the max length
|
||||
it = string.end() - 1 - maxLength / 2;
|
||||
while (it != string.end() && !std::isspace(*it)) ++it;
|
||||
|
||||
@@ -524,7 +524,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
);
|
||||
|
||||
constexpr static auto MaxStringLength = 32;
|
||||
constexpr static auto MaxStringLength = 64;
|
||||
|
||||
ContentRegistry::DataInspector::add("hex.builtin.inspector.string", 1,
|
||||
[](auto buffer, auto endian, auto style) {
|
||||
@@ -541,10 +541,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
value = copyValue = hex::encodeByteString(stringBuffer);
|
||||
|
||||
if (value.size() > MaxStringLength) {
|
||||
value.resize(MaxStringLength);
|
||||
value += "...";
|
||||
}
|
||||
copyValue = value;
|
||||
value = hex::limitStringLength(value, MaxStringLength, false);
|
||||
} else {
|
||||
value = "";
|
||||
copyValue = "";
|
||||
@@ -570,21 +568,18 @@ namespace hex::plugin::builtin {
|
||||
std::string value, copyValue;
|
||||
|
||||
if (currSelection.has_value()) {
|
||||
std::wstring stringBuffer(std::min<size_t>(currSelection->size * sizeof(wchar_t), 0x1000), 0x00);
|
||||
std::wstring stringBuffer(std::min<size_t>(alignTo(currSelection->size, sizeof(wchar_t)), 0x1000), 0x00);
|
||||
ImHexApi::Provider::get()->read(currSelection->address, stringBuffer.data(), stringBuffer.size());
|
||||
|
||||
for (auto &c : stringBuffer)
|
||||
c = hex::changeEndianness(c, endian);
|
||||
|
||||
std::erase_if(buffer, [](auto c) { return c == 0x00; });
|
||||
std::erase_if(stringBuffer, [](auto c) { return c == 0x00; });
|
||||
|
||||
auto string = wolv::util::wstringToUtf8(stringBuffer).value_or("Invalid");
|
||||
value = copyValue = hex::encodeByteString({ string.begin(), string.end() });
|
||||
|
||||
if (value.size() > MaxStringLength) {
|
||||
value.resize(MaxStringLength);
|
||||
value += "...";
|
||||
}
|
||||
copyValue = string;
|
||||
value = hex::limitStringLength(string, MaxStringLength, false);
|
||||
} else {
|
||||
value = "";
|
||||
copyValue = "";
|
||||
@@ -610,21 +605,18 @@ namespace hex::plugin::builtin {
|
||||
std::string value, copyValue;
|
||||
|
||||
if (currSelection.has_value()) {
|
||||
std::u16string stringBuffer(std::min<size_t>(currSelection->size * sizeof(char16_t), 0x1000), 0x00);
|
||||
std::u16string stringBuffer(std::min<size_t>(alignTo(currSelection->size, sizeof(char16_t)), 0x1000), 0x00);
|
||||
ImHexApi::Provider::get()->read(currSelection->address, stringBuffer.data(), stringBuffer.size());
|
||||
|
||||
for (auto &c : stringBuffer)
|
||||
c = hex::changeEndianness(c, endian);
|
||||
|
||||
std::erase_if(buffer, [](auto c) { return c == 0x00; });
|
||||
std::erase_if(stringBuffer, [](auto c) { return c == 0x00; });
|
||||
|
||||
auto string = wolv::util::utf16ToUtf8(stringBuffer).value_or("Invalid");
|
||||
value = copyValue = hex::encodeByteString({ string.begin(), string.end() });
|
||||
|
||||
if (value.size() > MaxStringLength) {
|
||||
value.resize(MaxStringLength);
|
||||
value += "...";
|
||||
}
|
||||
copyValue = string;
|
||||
value = hex::limitStringLength(string, MaxStringLength, false);
|
||||
} else {
|
||||
value = "";
|
||||
copyValue = "";
|
||||
@@ -650,21 +642,18 @@ namespace hex::plugin::builtin {
|
||||
std::string value, copyValue;
|
||||
|
||||
if (currSelection.has_value()) {
|
||||
std::u32string stringBuffer(std::min<size_t>(currSelection->size * sizeof(char32_t), 0x1000), 0x00);
|
||||
std::u32string stringBuffer(std::min<size_t>(alignTo(currSelection->size, sizeof(char32_t)), 0x1000), 0x00);
|
||||
ImHexApi::Provider::get()->read(currSelection->address, stringBuffer.data(), stringBuffer.size());
|
||||
|
||||
for (auto &c : stringBuffer)
|
||||
c = hex::changeEndianness(c, endian);
|
||||
|
||||
std::erase_if(buffer, [](auto c) { return c == 0x00; });
|
||||
std::erase_if(stringBuffer, [](auto c) { return c == 0x00; });
|
||||
|
||||
auto string = wolv::util::utf32ToUtf8(stringBuffer).value_or("Invalid");
|
||||
value = copyValue = hex::encodeByteString({ string.begin(), string.end() });
|
||||
|
||||
if (value.size() > MaxStringLength) {
|
||||
value.resize(MaxStringLength);
|
||||
value += "...";
|
||||
}
|
||||
copyValue = string;
|
||||
value = hex::limitStringLength(string, MaxStringLength, false);
|
||||
} else {
|
||||
value = "";
|
||||
copyValue = "";
|
||||
|
||||
Reference in New Issue
Block a user