[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] UTF-8 locales issue in the menu
From: |
Jordi Mallach |
Subject: |
[Nano-devel] UTF-8 locales issue in the menu |
Date: |
Sun, 6 Jul 2003 14:20:00 +0200 |
User-agent: |
Mutt/1.5.4i |
Hi,
I forgot to comment this here:
While discussing Debian Bug#195069, Michael Piefel said that nano
assumes all characters are one byte long, and this looks bad in the
menu.
He proposed the following instead of using strlen. I don't know if this
is already handled by DB's UTF-8 patch for 1.3.x, but here it is.
/* Return the screen width of the given string.
* We assume it's multi-byte and in the current locale.
* If it's not, the value we get will be at least as good
* as the value you get by just calling strlen() */
size_t
mbswidth(const char *s)
{
#ifdef HAVE_WCHAR_H
size_t bytesconsumed, old_n, n, width = 0;
mbstate_t state;
wchar_t nextchar;
memset(&state, 0, sizeof(mbstate_t));
old_n = n = strlen(s);
while (n>0) {
bytesconsumed = mbrtowc(&nextchar, s, n, &state);
if (bytesconsumed == (size_t)(-1) || bytesconsumed == (size_t)(-2)) {
/* Something went wrong, return something reasonable */
return old_n;
}
if (s[0]=='\n')
/* do what strlen() would do, so that caller is always right */
width++;
else
width += wcwidth(nextchar);
s += bytesconsumed, n -= bytesconsumed;
}
return width;
#else
return strlen(s);
#endif
}
--
Jordi Mallach PĂ©rez -- Debian developer http://www.debian.org/
address@hidden address@hidden http://www.sindominio.net/
GnuPG public key information available at http://oskuro.net/~jordi/
pgpkR64Zx07f3.pgp
Description: PGP signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nano-devel] UTF-8 locales issue in the menu,
Jordi Mallach <=