summaryrefslogtreecommitdiffstats
path: root/utf8.c
diff options
context:
space:
mode:
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/utf8.c b/utf8.c
index b25ac06b..a91da360 100644
--- a/utf8.c
+++ b/utf8.c
@@ -21,7 +21,6 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <vis.h>
#include <wchar.h>
#include "tmux.h"
@@ -110,9 +109,27 @@ utf8_width(wchar_t wc)
{
int width;
+#ifdef HAVE_UTF8PROC
+ width = utf8proc_wcwidth(wc);
+#else
width = wcwidth(wc);
+#endif
if (width < 0 || width > 0xff) {
log_debug("Unicode %04lx, wcwidth() %d", (long)wc, width);
+
+#ifndef __OpenBSD__
+ /*
+ * Many platforms (particularly and inevitably OS X) have no
+ * width for relatively common characters (wcwidth() returns
+ * -1); assume width 1 in this case. This will be wrong for
+ * genuinely nonprintable characters, but they should be
+ * rare. We may pass through stuff that ideally we would block,
+ * but this is no worse than sending the same to the terminal
+ * without tmux.
+ */
+ if (width < 0)
+ return (1);
+#endif
return (-1);
}
return (width);
@@ -122,7 +139,11 @@ utf8_width(wchar_t wc)
enum utf8_state
utf8_combine(const struct utf8_data *ud, wchar_t *wc)
{
+#ifdef HAVE_UTF8PROC
+ switch (utf8proc_mbtowc(wc, ud->data, ud->size)) {
+#else
switch (mbtowc(wc, ud->data, ud->size)) {
+#endif
case -1:
log_debug("UTF-8 %.*s, mbtowc() %d", (int)ud->size, ud->data,
errno);
@@ -142,7 +163,11 @@ utf8_split(wchar_t wc, struct utf8_data *ud)
char s[MB_LEN_MAX];
int slen;
+#ifdef HAVE_UTF8PROC
+ slen = utf8proc_wctomb(s, wc);
+#else
slen = wctomb(s, wc);
+#endif
if (slen <= 0 || slen > (int)sizeof ud->data)
return (UTF8_ERROR);