diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index 42fb38aec..49336df5b 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -294,10 +294,12 @@ namespace hex { [[nodiscard]] std::optional getEnvironmentVariable(const std::string &env); [[nodiscard]] inline std::string limitStringLength(const std::string &string, size_t maxLength) { - if (string.length() <= maxLength) - return string; + if (string.size() < maxLength) return string; - return string.substr(0, maxLength - 3) + "..."; + auto it = string.begin() + maxLength; + while (it != string.begin() && !std::isspace(*it)) --it; + + return std::string(string.begin(), it) + "..."; } [[nodiscard]] std::optional getInitialFilePath();