diff options
Diffstat (limited to 'src/unicode.c')
-rw-r--r-- | src/unicode.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/unicode.c b/src/unicode.c index 69b7682..0d1b5ff 100644 --- a/src/unicode.c +++ b/src/unicode.c @@ -67,8 +67,6 @@ * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c */ -#include <wchar.h> - struct interval { int first; int last; @@ -129,7 +127,7 @@ static const struct interval combining[] = { /* auxiliary function for binary search in interval table */ -static int bisearch(wchar_t ucs, const struct interval *table, int max) { +static int bisearch(uint32_t ucs, const struct interval *table, int max) { int min = 0; int mid; @@ -177,12 +175,12 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) { * ISO 8859-1 and WGL4 characters, Unicode control characters, * etc.) have a column width of 1. * - * This implementation assumes that wchar_t characters are encoded + * This implementation assumes that uint32_t characters are encoded * in ISO 10646. */ -static int mk_wcwidth(wchar_t ucs) +static int mk_wcwidth(uint32_t ucs) { /* test for 8-bit control characters */ if (ucs == 0) @@ -214,7 +212,7 @@ static int mk_wcwidth(wchar_t ucs) } -static int mk_wcswidth(const wchar_t *pwcs, size_t n) +static int mk_wcswidth(const uint32_t *pwcs, size_t n) { int w, width = 0; @@ -237,7 +235,7 @@ static int mk_wcswidth(const wchar_t *pwcs, size_t n) * the traditional terminal character-width behaviour. It is not * otherwise recommended for general use. */ -static int mk_wcwidth_cjk(wchar_t ucs) +static int mk_wcwidth_cjk(uint32_t ucs) { /* sorted list of non-overlapping intervals of East Asian Ambiguous * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ @@ -305,7 +303,7 @@ static int mk_wcwidth_cjk(wchar_t ucs) } -static int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) +static int mk_wcswidth_cjk(const uint32_t *pwcs, size_t n) { int w, width = 0; @@ -321,12 +319,19 @@ static int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) // ################################ // ### The rest added by Paul Evans -INTERNAL int vterm_unicode_width(int codepoint) +static const struct interval fullwidth[] = { +#include "fullwidth.inc" +}; + +INTERNAL int vterm_unicode_width(uint32_t codepoint) { + if(bisearch(codepoint, fullwidth, sizeof(fullwidth) / sizeof(fullwidth[0]) - 1)) + return 2; + return mk_wcwidth(codepoint); } -INTERNAL int vterm_unicode_is_combining(int codepoint) +INTERNAL int vterm_unicode_is_combining(uint32_t codepoint) { return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1); } |