[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


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

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() */
mbswidth(const char *s)
    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 += wcwidth(nextchar);
        s += bytesconsumed, n -= bytesconsumed;
    return width;
    return strlen(s);

Jordi Mallach PĂ©rez  --  Debian developer
address@hidden     address@hidden
GnuPG public key information available at

Attachment: pgpkR64Zx07f3.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]