1
0
Fork 0

Codechange: Remove unused Utf8TrimString, Utf8PrevChar.

pull/13985/head
frosch 2025-04-04 21:41:33 +02:00 committed by frosch
parent b1582b815c
commit 14bab7d76b
2 changed files with 1 additions and 61 deletions

View File

@ -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)
{

View File

@ -39,7 +39,7 @@ bool strtolower(std::string &str, std::string::size_type offs = 0);
[[nodiscard]] bool StrValid(std::span<const char> 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 <typename T> requires (!std::is_same_v<T, char *> && (std::is_same_v<std::string_view::iterator, T> || std::is_same_v<std::string::iterator, T>))
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);
/**