return have_utf8;
}
-/*
- * glibc's wcswidth returns -1 if the string contains a tab character, which
- * makes the function next to useless. The two functions below are taken from
- * mutt.
- */
-
-#define IsWPrint(wc) (iswprint(wc) || wc >= 0xa0)
-
-static int mutt_wcwidth(wchar_t wc, size_t pos)
+static int xwcwidth(wchar_t wc, size_t pos)
{
int n;
+ /* special-case for tab */
if (wc == 0x09) /* tab */
return (pos | 7) + 1 - pos;
n = wcwidth(wc);
- if (IsWPrint(wc) && n > 0)
- return n;
- if (!(wc & ~0x7f))
- return 2;
- if (!(wc & ~0xffff))
- return 6;
- return 10;
+ /* wcswidth() returns -1 for non-printable characters */
+ return n >= 0? n : 1;
}
-static size_t mutt_wcswidth(const wchar_t *s, size_t n)
+static size_t xwcswidth(const wchar_t *s, size_t n)
{
size_t w = 0;
while (n--)
- w += mutt_wcwidth(*s++, w);
+ w += xwcwidth(*s++, w);
return w;
}
if (mbret == (size_t)-1 || mbret == (size_t)-2)
return -ERRNO_TO_PARA_ERROR(EILSEQ);
bytes_parsed += mbret;
- cells_skipped += mutt_wcwidth(wc, cells_skipped);
+ cells_skipped += xwcwidth(wc, cells_skipped);
}
*bytes_to_skip = bytes_parsed;
return 1;
memset(&state, 0, sizeof(state));
num_wchars = mbsrtowcs(dest, &src, num_wchars, &state);
assert(num_wchars > 0 && num_wchars != (size_t)-1);
- *result = mutt_wcswidth(dest, num_wchars);
+ *result = xwcswidth(dest, num_wchars);
free(dest);
return 1;
}