summaryrefslogtreecommitdiffstats
path: root/utf8.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-11-25 16:01:27 +0000
committerThomas Adam <thomas@xteddy.org>2019-11-25 16:01:27 +0000
commitdaa93b3fdc21f0c27fe94231cc96213c9b38e949 (patch)
tree23bc1b3a598743231bc215bc6c160a997a21dd02 /utf8.c
parent81d4f95c2fd06377c450b818dfd6b247b24db61d (diff)
parent1ebd8c123415a60960dcd088d75d13f761bd3b3b (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/utf8.c b/utf8.c
index 224aa482..b4e448f7 100644
--- a/utf8.c
+++ b/utf8.c
@@ -415,7 +415,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)
{
@@ -436,6 +436,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)
{