From ee19d304ff366741f6f94334bbc82124a4c44dbc Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 31 Mar 2014 21:43:35 +0000 Subject: In four byte UTF-8 sequences, only three bits of the first byte should be used. Fix from Koga Osamu. --- utf8.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utf8.c') diff --git a/utf8.c b/utf8.c index 1c81392b..85889dcb 100644 --- a/utf8.c +++ b/utf8.c @@ -311,7 +311,7 @@ utf8_combine(const struct utf8_data *utf8data) value = utf8data->data[3] & 0x3f; value |= (utf8data->data[2] & 0x3f) << 6; value |= (utf8data->data[1] & 0x3f) << 12; - value |= (utf8data->data[0] & 0x3f) << 18; + value |= (utf8data->data[0] & 0x07) << 18; break; } return (value); -- cgit From 252a7373d69646ae866e3a4fa18d46f673864c0e Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 2 Apr 2014 18:12:18 +0000 Subject: Support UTF-8 with choose-buffer, from Kosuke ASAMI. Also make buffer_sample bigger to let it trim at window right edge. --- utf8.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'utf8.c') diff --git a/utf8.c b/utf8.c index 85889dcb..082683e8 100644 --- a/utf8.c +++ b/utf8.c @@ -19,6 +19,7 @@ #include #include +#include #include "tmux.h" @@ -350,3 +351,45 @@ utf8_width(const struct utf8_data *utf8data) } return (1); } + +/* + * Encode len characters from src into dst, which is guaranteed to have four + * bytes available for each character from src (for \abc or UTF-8) plus space + * for \0. + */ +int +utf8_strvis(char *dst, const char *src, size_t len, int flag) +{ + struct utf8_data utf8data; + const char *start, *end; + int more; + size_t i; + + start = dst; + end = src + len; + + while (src < end) { + if (utf8_open(&utf8data, *src)) { + more = 1; + while (++src < end && more) + more = utf8_append(&utf8data, *src); + if (!more) { + /* UTF-8 character finished. */ + for (i = 0; i < utf8data.size; i++) + *dst++ = utf8data.data[i]; + continue; + } else if (utf8data.have > 0) { + /* Not a complete UTF-8 character. */ + src -= utf8data.have; + } + } + if (src < end - 1) + dst = vis(dst, src[0], flag, src[1]); + else if (src < end) + dst = vis(dst, src[0], flag, '\0'); + src++; + } + + *dst = '\0'; + return (dst - start); +} -- cgit From 57c514d2f85f9d1c81601bae32131f1cd2948422 Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Sat, 5 Apr 2014 12:40:19 +0100 Subject: Remove ; not used on Linux. --- utf8.c | 1 - 1 file changed, 1 deletion(-) (limited to 'utf8.c') diff --git a/utf8.c b/utf8.c index 1328dd6e..20e35137 100644 --- a/utf8.c +++ b/utf8.c @@ -19,7 +19,6 @@ #include #include -#include #include "tmux.h" -- cgit