Re: UTF-8?



On Sun, 10 Jan 1999, Michael Sobolev wrote:
> 
> Let me rephrase my question, is there a more or less documented (or reliable)
> way for writing a function that would display the text in UTF-8?

maybe  /usr/src/linux/drivers/char/keyboard.c will help you:

/*
 * Many other routines do put_queue, but I think either
 * they produce ASCII, or they produce some user-assigned
 * string, and in both cases we might assume that it is
 * in utf-8 already.
 */
void to_utf8(ushort c) {
    if (c < 0x80)
        put_queue(c);                   /*  0*******  */
    else if (c < 0x800) {
        put_queue(0xc0 | (c >> 6));     /*  110***** 10******  */
        put_queue(0x80 | (c & 0x3f));
    } else {
        put_queue(0xe0 | (c >> 12));    /*  1110**** 10****** 10******  */
        put_queue(0x80 | ((c >> 6) & 0x3f));
        put_queue(0x80 | (c & 0x3f));
    }
    /* UTF-8 is defined for words of up to 31 bits,
       but we need only 16 bits here */
}

but just to decode utf8 text you can use mmencode.

Best regards,
_____
Alexander Kotelnikov
Saint-Petersburg, Russia
mailto:sacha@ak2614.spb.edu



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