Skip to content

Commit

Permalink
fix: String limiting slicing unicode characters
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Feb 22, 2024
1 parent 1ede41c commit e6854d6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/libimhex/include/hex/helpers/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,12 @@ namespace hex {
[[nodiscard]] std::optional<std::string> 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<std::fs::path> getInitialFilePath();
Expand Down

0 comments on commit e6854d6

Please sign in to comment.