1
0
mirror of synced 2025-01-19 01:24:15 +01:00

fix: String limiting slicing unicode characters

This commit is contained in:
WerWolv 2024-02-22 23:44:49 +01:00
parent 1ede41c778
commit e6854d6a6a

View File

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