diff options
author | nicm <nicm> | 2014-04-17 15:37:55 +0000 |
---|---|---|
committer | nicm <nicm> | 2014-04-17 15:37:55 +0000 |
commit | 806520f025dccdcbf266bb9c7cbd984bef00d733 (patch) | |
tree | e60539855f38c78873413536cff8d7fc71215d48 /format.c | |
parent | a5d4b7f3d927b267e21aa34c2451669318536e46 (diff) |
Add some UTF-8 utility functions and use them to prevent the width limit
on formats from splitting UTF-8 characters improperly.
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -194,10 +194,10 @@ int format_replace(struct format_tree *ft, const char *key, size_t keylen, char **buf, size_t *len, size_t *off) { - char *copy, *copy0, *endptr, *ptr, *saved; + char *copy, *copy0, *endptr, *ptr, *saved, *trimmed; const char *value; size_t valuelen; - u_long limit = ULONG_MAX; + u_long limit = 0; /* Make a copy of the key. */ copy0 = copy = xmalloc(keylen + 1); @@ -256,11 +256,14 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, value = ""; saved = NULL; } - valuelen = strlen(value); /* Truncate the value if needed. */ - if (valuelen > limit) - valuelen = limit; + if (limit != 0) { + value = trimmed = utf8_trimcstr(value, limit); + free(saved); + saved = trimmed; + } + valuelen = strlen(value); /* Expand the buffer and copy in the value. */ while (*len - *off < valuelen + 1) { |