diff options
author | nicm <nicm> | 2016-10-11 07:11:40 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-10-11 07:11:40 +0000 |
commit | 8b804fb5894b6717de36c5c9c96f7fd29b14a864 (patch) | |
tree | 74daf8f3e2813818fb408a1fc3e3e96bd818fac9 /utf8.c | |
parent | a81685bfac9d4eac3a7cfd8f8ce13033a46fe01c (diff) | |
download | rtmux-8b804fb5894b6717de36c5c9c96f7fd29b14a864.tar.gz rtmux-8b804fb5894b6717de36c5c9c96f7fd29b14a864.tar.bz2 rtmux-8b804fb5894b6717de36c5c9c96f7fd29b14a864.zip |
Support UTF-8 entry into the command prompt.
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -236,6 +236,33 @@ utf8_sanitize(const char *src) return (dst); } +/* Get UTF-8 buffer length. */ +size_t +utf8_strlen(const struct utf8_data *s) +{ + size_t i; + + for (i = 0; s[i].size != 0; i++) + /* nothing */; + return (i); +} + +/* Get UTF-8 string width. */ +u_int +utf8_strwidth(const struct utf8_data *s, ssize_t n) +{ + ssize_t i; + u_int width; + + width = 0; + for (i = 0; s[i].size != 0; i++) { + if (n != -1 && n == i) + break; + width += s[i].width; + } + return (width); +} + /* * Convert a string into a buffer of UTF-8 characters. Terminated by size == 0. * Caller frees. |