fix: hostname truncation (#63)

Co-authored-by: javalsai <javalsai@proton.me>
This commit is contained in:
Ar1gin
2025-07-16 17:19:58 +05:00
committed by GitHub
parent 6c99675be7
commit 8fc6bff60f
3 changed files with 32 additions and 20 deletions

View File

@@ -103,6 +103,24 @@ size_t utf8len_until(const char* str, const char* until) {
return len;
}
size_t utf8trunc(char* str, size_t n) {
size_t bytes = 0;
while (true) {
if(str[bytes] == '\0') break;
if (utf8_iscont(str[bytes])) {
bytes++;
continue;
}
if(n == 0) {
str[bytes] = '\0';
break;
}
bytes++;
n--;
}
return bytes;
}
const char* utf8back(const char* str) {
while (utf8_iscont(*(--str))) {
}