particles/string: rewrite truncation code, show three dots only for max>3

This commit is contained in:
kotyk 2023-07-25 16:22:52 +00:00 committed by Daniel Eklöf
parent d5823bcc4c
commit 176ed4a6f3
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

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