diff options
author | nicm <nicm> | 2019-11-25 15:04:15 +0000 |
---|---|---|
committer | nicm <nicm> | 2019-11-25 15:04:15 +0000 |
commit | 1ebd8c123415a60960dcd088d75d13f761bd3b3b (patch) | |
tree | 6ebf831a62c612723271e6542e5f7cff436143ed /utf8.c | |
parent | 5d0504ee115a7edd4fe53476a2721c180b0cbc26 (diff) | |
download | rtmux-1ebd8c123415a60960dcd088d75d13f761bd3b3b.tar.gz rtmux-1ebd8c123415a60960dcd088d75d13f761bd3b3b.tar.bz2 rtmux-1ebd8c123415a60960dcd088d75d13f761bd3b3b.zip |
Add p format modifier for padding to width.
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -390,7 +390,7 @@ utf8_cstrwidth(const char *s) return (width); } -/* Pad UTF-8 string to width. Caller frees. */ +/* Pad UTF-8 string to width on the left. Caller frees. */ char * utf8_padcstr(const char *s, u_int width) { @@ -411,6 +411,27 @@ utf8_padcstr(const char *s, u_int width) return (out); } +/* Pad UTF-8 string to width on the right. Caller frees. */ +char * +utf8_rpadcstr(const char *s, u_int width) +{ + size_t slen; + char *out; + u_int n, i; + + n = utf8_cstrwidth(s); + if (n >= width) + return (xstrdup(s)); + + slen = strlen(s); + out = xmalloc(slen + 1 + (width - n)); + for (i = 0; i < width - n; i++) + out[i] = ' '; + memcpy(out + i, s, slen); + out[i + slen] = '\0'; + return (out); +} + int utf8_cstrhas(const char *s, const struct utf8_data *ud) { |