6868 * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
6969 */
7070
71+ #if !defined(IS_COMBINING_FUNCTION ) || !defined(WCWIDTH_FUNCTION )
7172struct interval {
7273 int first ;
7374 int last ;
@@ -126,7 +127,6 @@ static const struct interval combining[] = {
126127 { 0xE0100 , 0xE01EF }
127128};
128129
129-
130130/* auxiliary function for binary search in interval table */
131131static int bisearch (uint32_t ucs , const struct interval * table , int max ) {
132132 int min = 0 ;
@@ -146,6 +146,7 @@ static int bisearch(uint32_t ucs, const struct interval *table, int max) {
146146
147147 return 0 ;
148148}
149+ #endif
149150
150151
151152/* 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) {
180181 * in ISO 10646.
181182 */
182183
184+ #ifdef WCWIDTH_FUNCTION
185+ /* use a provided wcwidth() function */
186+ int WCWIDTH_FUNCTION (uint32_t ucs );
187+ #else
188+ # define WCWIDTH_FUNCTION mk_wcwidth
183189
184190static int mk_wcwidth (uint32_t ucs )
185191{
@@ -196,7 +202,7 @@ static int mk_wcwidth(uint32_t ucs)
196202
197203 /* if we arrive here, ucs is not a combining or C0/C1 control character */
198204
199- return 1 +
205+ return 1 +
200206 (ucs >= 0x1100 &&
201207 (ucs <= 0x115f || /* Hangul Jamo init. consonants */
202208 ucs == 0x2329 || ucs == 0x232a ||
@@ -211,6 +217,7 @@ static int mk_wcwidth(uint32_t ucs)
211217 (ucs >= 0x20000 && ucs <= 0x2fffd ) ||
212218 (ucs >= 0x30000 && ucs <= 0x3fffd )));
213219}
220+ #endif
214221
215222#if 0 /* unused */
216223static 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)
317324}
318325#endif
319326
327+ #ifdef IS_COMBINING_FUNCTION
328+ /* Use a provided is_combining() function. */
329+ int IS_COMBINING_FUNCTION (uint32_t codepoint );
330+ #else
331+ # define IS_COMBINING_FUNCTION vterm_is_combining
332+ static int
333+ vterm_is_combining (uint32_t codepoint )
334+ {
335+ return bisearch (codepoint , combining , sizeof (combining ) / sizeof (struct interval ) - 1 );
336+ }
337+ #endif
338+
339+
320340/* ################################
321341 * ### The rest added by Paul Evans */
322342
323343INTERNAL int vterm_unicode_width (uint32_t codepoint )
324344{
325- return mk_wcwidth (codepoint );
345+ return WCWIDTH_FUNCTION (codepoint );
326346}
327347
328348INTERNAL int vterm_unicode_is_combining (uint32_t codepoint )
329349{
330- return bisearch (codepoint , combining , sizeof ( combining ) / sizeof ( struct interval ) - 1 );
350+ return IS_COMBINING_FUNCTION (codepoint );
331351}
0 commit comments