[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: utf-8 & ncurses
From: |
Thomas Dickey |
Subject: |
Re: utf-8 & ncurses |
Date: |
Tue, 17 Aug 2010 04:41:04 -0400 (EDT) |
On Tue, 17 Aug 2010, folkert wrote:
Hi,
I'm trying to get ncurses and utf-8 to work with each other.
Let's say I have a string 'string' and an index 'loop'. Now in this
string some utf-8 characters may exist. I try to filter these out and
print them.
#include <ncursesw/ncurses.h>
if ((string[loop] & 0xe0) == 0xc0)
{
wadd_wch(win -> win, (string[loop] << 8) + string[loop + 1]);
loop += 1;
}
else if ((string[loop] & 0xf0) == 0xe0)
{
wadd_wch(win -> win, (string[loop] << 16) + (string[loop + 1]
<< 8) + string[loop + 2]);
loop += 2;
}
....
This doesn't work. No special characters are shown.
The conversion doesn't look right. Basically, UTF-8 uses a few bits from
each byte to tell where it is in a multibyte sequence, and a few bits from
each byte are masked into the result.
ncurses (assuming the locale is set via setlocale...) accepts the bytes
of a UTF-8 string in waddch (unlike X/Open, which requires using wadd_wch,
etc).
To do the conversion, ncurses uses functions such as mbrtowc().
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net