diff options
author | nicm <nicm> | 2016-01-31 09:57:41 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-01-31 09:57:41 +0000 |
commit | fa64b89ad7af8daf04c50b54fe8b45411750149e (patch) | |
tree | 617d87bedc6e6246399ad29e3ad27334ee56efe1 /utf8.c | |
parent | 49e9f937387356a3970fdb2af6bb56818127b433 (diff) | |
download | rtmux-fa64b89ad7af8daf04c50b54fe8b45411750149e.tar.gz rtmux-fa64b89ad7af8daf04c50b54fe8b45411750149e.tar.bz2 rtmux-fa64b89ad7af8daf04c50b54fe8b45411750149e.zip |
Whoops, need this for the previous reverse trim commit too.
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -724,6 +724,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) |