diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-09-23 20:55:00 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-09-23 20:55:00 +0200 |
commit | 68f7fb971322ffb03c8b5deba60ee25e31c77bfd (patch) | |
tree | b393c74fbc4a893028674d714f68c1272bfe618f | |
parent | 003fe73b8902048b6190554e10a68e4b1c3b18c6 (diff) |
Fix text centering of multibyte characters
-rw-r--r-- | center.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -113,8 +113,10 @@ center(FILE *fp) tabs++; } - len = lenfunc(line) + tabs * 8 - tabs + 1; - printf("%*s", ((int) width - len) / 2 + len, line); + len = lenfunc(line) + tabs * 8 - tabs; + for (int i = (width - len) / 2; i; i--) + putchar(' '); + fputs(line, stdout); } if (ferror(fp)) { warn("getline"); @@ -145,6 +147,9 @@ utf8len(const char *s) while (*s) l += (*s++ & 0xC0) != 0x80; + if (l > 0 && s[-1] == '\n') + l--; + return l; } |