Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam
2019-11-25 16:01:27 +00:00
4 changed files with 70 additions and 16 deletions

23
utf8.c
View File

@ -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)
{