Mercurial > vim
diff src/libvterm/src/unicode.c @ 20518:a4652d7ec99f v8.2.0813
patch 8.2.0813: libvterm code is slightly different from upstream
Commit: https://github.com/vim/vim/commit/591cec8366e87a172495c362477cbf5de8d399f0
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 22 22:06:06 2020 +0200
patch 8.2.0813: libvterm code is slightly different from upstream
Problem: libvterm code is slightly different from upstream.
Solution: Use upstream text to avoid future merge problems. Mainly comment
style changes.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 22 May 2020 22:15:04 +0200 |
parents | e02d45e302a2 |
children | 82336c3b679d |
line wrap: on
line diff
--- a/src/libvterm/src/unicode.c +++ b/src/libvterm/src/unicode.c @@ -1,11 +1,10 @@ #include "vterm_internal.h" -/* ### The following from http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c - * With modifications: - * made functions static - * moved 'combining' table to file scope, so other functions can see it - * ################################################################### - */ +// ### The following from http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c +// With modifications: +// made functions static +// moved 'combining' table to file scope, so other functions can see it +// ################################################################### /* * This is an implementation of wcwidth() and wcswidth() (defined in @@ -75,8 +74,8 @@ struct interval { #if !defined(WCWIDTH_FUNCTION) || !defined(IS_COMBINING_FUNCTION) -// sorted list of non-overlapping intervals of non-spacing characters -// generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" +/* sorted list of non-overlapping intervals of non-spacing characters */ +/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ // Replaced by the combining table from Vim. static const struct interval combining[] = { {0X0300, 0X036F}, @@ -362,7 +361,7 @@ static const struct interval combining[] }; #endif -// auxiliary function for binary search in interval table +/* auxiliary function for binary search in interval table */ static int bisearch(uint32_t ucs, const struct interval *table, int max) { int min = 0; int mid; @@ -382,6 +381,7 @@ static int bisearch(uint32_t ucs, const return 0; } + /* The following two functions define the column width of an ISO 10646 * character as follows: * @@ -422,30 +422,30 @@ int WCWIDTH_FUNCTION(uint32_t ucs); static int mk_wcwidth(uint32_t ucs) { - // test for 8-bit control characters + /* test for 8-bit control characters */ if (ucs == 0) return 0; if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) return -1; - // binary search in table of non-spacing characters + /* binary search in table of non-spacing characters */ if (bisearch(ucs, combining, sizeof(combining) / sizeof(struct interval) - 1)) return 0; - // if we arrive here, ucs is not a combining or C0/C1 control character + /* if we arrive here, ucs is not a combining or C0/C1 control character */ - return 1 + + return 1 + (ucs >= 0x1100 && - (ucs <= 0x115f || // Hangul Jamo init. consonants + (ucs <= 0x115f || /* Hangul Jamo init. consonants */ ucs == 0x2329 || ucs == 0x232a || (ucs >= 0x2e80 && ucs <= 0xa4cf && - ucs != 0x303f) || // CJK ... Yi - (ucs >= 0xac00 && ucs <= 0xd7a3) || // Hangul Syllables - (ucs >= 0xf900 && ucs <= 0xfaff) || // CJK Compatibility Ideographs - (ucs >= 0xfe10 && ucs <= 0xfe19) || // Vertical forms - (ucs >= 0xfe30 && ucs <= 0xfe6f) || // CJK Compatibility Forms - (ucs >= 0xff00 && ucs <= 0xff60) || // Fullwidth Forms + ucs != 0x303f) || /* CJK ... Yi */ + (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */ + (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */ + (ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */ + (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */ + (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ (ucs >= 0xffe0 && ucs <= 0xffe6) || (ucs >= 0x20000 && ucs <= 0x2fffd) || (ucs >= 0x30000 && ucs <= 0x3fffd))); @@ -479,8 +479,8 @@ static int mk_wcswidth(const uint32_t *p static int mk_wcwidth_cjk(uint32_t ucs) { #endif - // sorted list of non-overlapping intervals of East Asian Ambiguous - // characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" + /* sorted list of non-overlapping intervals of East Asian Ambiguous + * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ static const struct interval ambiguous[] = { { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 }, { 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 }, @@ -537,7 +537,7 @@ static int mk_wcwidth_cjk(uint32_t ucs) }; #if 0 - // binary search in table of non-spacing characters + /* binary search in table of non-spacing characters */ if (bisearch(ucs, ambiguous, sizeof(ambiguous) / sizeof(struct interval) - 1)) return 2; @@ -545,6 +545,7 @@ static int mk_wcwidth_cjk(uint32_t ucs) return mk_wcwidth(ucs); } + static int mk_wcswidth_cjk(const uint32_t *pwcs, size_t n) { int w, width = 0;