summaryrefslogtreecommitdiff
path: root/src/libvterm
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-08-22 22:12:17 +0200
committerBram Moolenaar <Bram@vim.org>2017-08-22 22:12:17 +0200
commit6d0826dfbba9880820d9ec221327e4250bbf6540 (patch)
tree4cc32379c4c21b3dfced4bc8339d8541188cf18f /src/libvterm
parent5830232c021102e47a4e6fc81857604e4a031ddf (diff)
downloadvim-git-6d0826dfbba9880820d9ec221327e4250bbf6540.tar.gz
patch 8.0.0985: libvterm has its own idea of character widthv8.0.0985
Problem: Libvterm has its own idea of character width. Solution: Use the Vim functions for character width and composing to avoid a mismatch. (idea by Yasuhiro Matsumoto)
Diffstat (limited to 'src/libvterm')
-rw-r--r--src/libvterm/src/unicode.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/libvterm/src/unicode.c b/src/libvterm/src/unicode.c
index b989add3c..e5a25a5e7 100644
--- a/src/libvterm/src/unicode.c
+++ b/src/libvterm/src/unicode.c
@@ -68,6 +68,7 @@
* Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
*/
+#if !defined(IS_COMBINING_FUNCTION) || !defined(WCWIDTH_FUNCTION)
struct interval {
int first;
int last;
@@ -126,7 +127,6 @@ static const struct interval combining[] = {
{ 0xE0100, 0xE01EF }
};
-
/* auxiliary function for binary search in interval table */
static int bisearch(uint32_t ucs, const struct interval *table, int max) {
int min = 0;
@@ -146,6 +146,7 @@ static int bisearch(uint32_t ucs, const struct interval *table, int max) {
return 0;
}
+#endif
/* The following two functions define the column width of an ISO 10646
@@ -180,6 +181,11 @@ static int bisearch(uint32_t ucs, const struct interval *table, int max) {
* in ISO 10646.
*/
+#ifdef WCWIDTH_FUNCTION
+/* use a provided wcwidth() function */
+int WCWIDTH_FUNCTION(uint32_t ucs);
+#else
+# define WCWIDTH_FUNCTION mk_wcwidth
static int mk_wcwidth(uint32_t ucs)
{
@@ -196,7 +202,7 @@ static int mk_wcwidth(uint32_t ucs)
/* 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 == 0x2329 || ucs == 0x232a ||
@@ -211,6 +217,7 @@ static int mk_wcwidth(uint32_t ucs)
(ucs >= 0x20000 && ucs <= 0x2fffd) ||
(ucs >= 0x30000 && ucs <= 0x3fffd)));
}
+#endif
#if 0 /* unused */
static int mk_wcswidth(const uint32_t *pwcs, size_t n)
@@ -317,15 +324,28 @@ static int mk_wcswidth_cjk(const uint32_t *pwcs, size_t n)
}
#endif
+#ifdef IS_COMBINING_FUNCTION
+/* Use a provided is_combining() function. */
+int IS_COMBINING_FUNCTION(uint32_t codepoint);
+#else
+# define IS_COMBINING_FUNCTION vterm_is_combining
+ static int
+vterm_is_combining(uint32_t codepoint)
+{
+ return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1);
+}
+#endif
+
+
/* ################################
* ### The rest added by Paul Evans */
INTERNAL int vterm_unicode_width(uint32_t codepoint)
{
- return mk_wcwidth(codepoint);
+ return WCWIDTH_FUNCTION(codepoint);
}
INTERNAL int vterm_unicode_is_combining(uint32_t codepoint)
{
- return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1);
+ return IS_COMBINING_FUNCTION(codepoint);
}