particle/string: simplify; no need to call c32len(wtext) twice

This commit is contained in:
Daniel Eklöf 2022-06-13 12:06:59 +02:00
parent 36a4250a96
commit 1b03bd6bc0
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -179,24 +179,20 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
size_t chars = c32len(wtext);
/* Truncate, if necessary */
if (p->max_len > 0) {
const size_t len = c32len(wtext);
if (len > p->max_len) {
if (p->max_len > 0 && chars > p->max_len) {
size_t end = p->max_len;
if (end >= 1) {
/* "allocate" room for three dots at the end */
end -= 1;
}
size_t end = p->max_len;
if (end >= 1) {
/* "allocate" room for three dots at the end */
end -= 1;
}
if (p->max_len > 1) {
wtext[end] = U'';
wtext[end + 1] = U'\0';
chars = end + 1;
} else {
wtext[end] = U'\0';
chars = 0;
}
if (p->max_len > 1) {
wtext[end] = U'';
wtext[end + 1] = U'\0';
chars = end + 1;
} else {
wtext[end] = U'\0';
chars = 0;
}
}