fix: String inspector rows not displaying the correctly decoded value

This commit is contained in:
WerWolv
2025-12-01 22:38:56 +01:00
parent da755ec75b
commit 46fdbd5bc0
3 changed files with 21 additions and 29 deletions

View File

@@ -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();

View File

@@ -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;