diff --git a/src/common/tuklib_mbstr_width.c b/src/common/tuklib_mbstr_width.c index 7a8bf070..3c63dd1a 100644 --- a/src/common/tuklib_mbstr_width.c +++ b/src/common/tuklib_mbstr_width.c @@ -12,7 +12,7 @@ #include "tuklib_mbstr.h" #include -#if defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) +#ifdef HAVE_MBRTOWC # include #endif @@ -24,7 +24,7 @@ tuklib_mbstr_width(const char *str, size_t *bytes) if (bytes != NULL) *bytes = len; -#if !(defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)) +#ifndef HAVE_MBRTOWC // In single-byte mode, the width of the string is the same // as its length. return len; @@ -46,11 +46,20 @@ tuklib_mbstr_width(const char *str, size_t *bytes) i += ret; +#ifdef HAVE_WCWIDTH const int wc_width = wcwidth(wc); if (wc_width < 0) return (size_t)-1; width += (size_t)wc_width; +#else + // Without wcwidth() (like in a native Windows build), + // assume that one multibyte char == one column. With + // UTF-8, this is less bad than one byte == one column. + // This way quite a few languages will be handled correctly + // in practice; CJK chars will be very wrong though. + ++width; +#endif } // Require that the string ends in the initial shift state.