mirror of
https://github.com/javalsai/lidm.git
synced 2025-09-07 13:31:40 +02:00
fix: hostname truncation (#63)
Co-authored-by: javalsai <javalsai@proton.me>
This commit is contained in:
18
src/util.c
18
src/util.c
@@ -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))) {
|
||||
}
|
||||
|
Reference in New Issue
Block a user