bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ncurses & utf-8


From: folkert
Subject: ncurses & utf-8
Date: Fri, 16 Aug 2013 10:10:11 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

I'm trying to output UTF-8 codes that I retrieve from a stream.
So first I collect the bytes that make-up the utf-8 code and put them in
a buffer. Then I output them using waddstr().
Before I start ncurses I do:
        /setlocale(LC_ALL,"C-UTF-8");
also tried:
        setlocale(LC_CTYPE, "");
Am linking against libncursesw.

Any suggestions?

char utfbuffer[5];
unsigned char first = (unsigned char)string[loop];

if ((first & 0xe0) == 0xc0)
{
        utfbuffer[0] = string[loop];
        utfbuffer[1] = string[loop + 1];
        utfbuffer[2] = 0x00;
        loop += 1;
}
else if ((first & 0xf0) == 0xe0)
{
        utfbuffer[0] = string[loop];
        utfbuffer[1] = string[loop + 1];
        utfbuffer[2] = string[loop + 2];
        utfbuffer[3] = 0x00;
        loop += 2;
}
else if ((first & 0xf8) == 0xf0)
{
        utfbuffer[0] = string[loop];
        utfbuffer[1] = string[loop + 1];
        utfbuffer[2] = string[loop + 2];
        utfbuffer[3] = string[loop + 3];
        utfbuffer[4] = 0x00;
        loop += 3;
}
else
{
        utfbuffer[0] = string[loop];
        utfbuffer[1] = 0x00;
}

waddstr(win, utfbuffer);


Folkert van Heusden

-- 
MultiTail er et flexible tool for å kontrolere Logfiles og commandoer.
Med filtrer, farger, sammenføringer, forskeliger ansikter etc.
http://www.vanheusden.com/multitail/
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com



reply via email to

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