diff --git a/src/string.cpp b/src/string.cpp index 4f67bafa79..4f7b920f42 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -470,33 +470,6 @@ size_t Utf8Decode(char32_t *c, const char *s) return 1; } -/** - * Properly terminate an UTF8 string to some maximum length - * @param s string to check if it needs additional trimming - * @param maxlen the maximum length the buffer can have. - * @return the new length in bytes of the string (eg. strlen(new_string)) - * @note maxlen is the string length _INCLUDING_ the terminating '\0' - */ -size_t Utf8TrimString(char *s, size_t maxlen) -{ - size_t length = 0; - - for (const char *ptr = strchr(s, '\0'); *s != '\0';) { - size_t len = Utf8EncodedCharLen(*s); - /* Silently ignore invalid UTF8 sequences, our only concern trimming */ - if (len == 0) len = 1; - - /* Take care when a hard cutoff was made for the string and - * the last UTF8 sequence is invalid */ - if (length + len >= maxlen || (s + len > ptr)) break; - s += len; - length += len; - } - - *s = '\0'; - return length; -} - #ifdef DEFINE_STRCASESTR char *strcasestr(const char *haystack, const char *needle) { diff --git a/src/string_func.h b/src/string_func.h index 0b1d46b829..b44e6de3eb 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -39,7 +39,7 @@ bool strtolower(std::string &str, std::string::size_type offs = 0); [[nodiscard]] bool StrValid(std::span str); void StrTrimInPlace(std::string &str); -std::string_view StrTrimView(std::string_view str); +[[nodiscard]] std::string_view StrTrimView(std::string_view str); [[nodiscard]] bool StrStartsWithIgnoreCase(std::string_view str, const std::string_view prefix); [[nodiscard]] bool StrEndsWithIgnoreCase(std::string_view str, const std::string_view suffix); @@ -91,9 +91,6 @@ size_t Utf8Decode(char32_t *c, const char *s); template requires (!std::is_same_v && (std::is_same_v || std::is_same_v)) inline size_t Utf8Decode(char32_t *c, T &s) { return Utf8Decode(c, &*s); } -size_t Utf8TrimString(char *s, size_t maxlen); - - inline char32_t Utf8Consume(const char **s) { char32_t c; @@ -151,36 +148,6 @@ inline bool IsUtf8Part(char c) return GB(c, 6, 2) == 2; } -/** - * Retrieve the previous UNICODE character in an UTF-8 encoded string. - * @param s char pointer pointing to (the first char of) the next character - * @return a pointer in 's' to the previous UNICODE character's first byte - * @note The function should not be used to determine the length of the previous - * encoded char because it might be an invalid/corrupt start-sequence - */ -inline char *Utf8PrevChar(char *s) -{ - char *ret = s; - while (IsUtf8Part(*--ret)) {} - return ret; -} - -inline const char *Utf8PrevChar(const char *s) -{ - const char *ret = s; - while (IsUtf8Part(*--ret)) {} - return ret; -} - -inline std::string::iterator Utf8PrevChar(std::string::iterator &s) -{ - auto cur = s; - do { - cur = std::prev(cur); - } while (IsUtf8Part(*cur)); - return cur; -} - size_t Utf8StringLength(std::string_view str); /**