[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 05:21:08 -0400 (EDT) |
On Tue, 17 Aug 2010, folkert wrote:
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.
So what you mean is that I need to strip of those markerbits,
concatenate the remaining bits into some variable and then use waddch to
print it?
no - I was saying that ncurses' waddch can print the UTF-8 directly,
assuming that setlocale has already told it that it's using UTF-8
encoding.
If the encoding doesn't match the locale, it couldn't work anyway,
except for the special case where the locale is using ISO-8859-1.
In that special case, it's possible to do your own explicit conversion
and use ncurses to print the codes.
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net