aboutsummaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2016-02-05 10:08:55 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2016-02-05 10:08:55 +0000
commit07c23ccc05314f5d351cb70d08a9256e15d105d9 (patch)
tree70a8a25daa06d7330bfabba5dbe9be8fd9fc43c8 /utf8.c
parent2130a07b70db7df8d57b9cad96a6866203daacad (diff)
parent26f899be109d2b7e8c8fae4ca8e3baaccf8d2655 (diff)
downloadrtmux-07c23ccc05314f5d351cb70d08a9256e15d105d9.tar.gz
rtmux-07c23ccc05314f5d351cb70d08a9256e15d105d9.tar.bz2
rtmux-07c23ccc05314f5d351cb70d08a9256e15d105d9.zip
Merge branch 'master' of github.com:tmux/tmux
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/utf8.c b/utf8.c
index 5e32de2d..524ba872 100644
--- a/utf8.c
+++ b/utf8.c
@@ -723,6 +723,43 @@ utf8_trimcstr(const char *s, u_int width)
return (out);
}
+/* Trim UTF-8 string to width. Caller frees. */
+char *
+utf8_rtrimcstr(const char *s, u_int width)
+{
+ struct utf8_data *tmp, *next, *end;
+ char *out;
+ u_int at;
+
+ tmp = utf8_fromcstr(s);
+
+ for (end = tmp; end->size != 0; end++)
+ /* nothing */;
+ if (end == tmp) {
+ free(tmp);
+ return (xstrdup(""));
+ }
+ next = end - 1;
+
+ at = 0;
+ for (;;)
+ {
+ if (at + next->width > width) {
+ next++;
+ break;
+ }
+ at += next->width;
+
+ if (next == tmp)
+ break;
+ next--;
+ }
+
+ out = utf8_tocstr(next);
+ free(tmp);
+ return (out);
+}
+
/* Pad UTF-8 string to width. Caller frees. */
char *
utf8_padcstr(const char *s, u_int width)