Changeset 927 for libcaca


Ignore:
Timestamp:
May 5, 2006, 7:09:54 AM (15 years ago)
Author:
Sam Hocevar
Message:
  • Implemented the private _cucul_utf32_to_utf8() helper.
Location:
libcaca/trunk/cucul
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/charset.c

    r859 r927  
    101101
    102102    return ret;
     103}
     104
     105unsigned int _cucul_utf32_to_utf8(void *buf, uint32_t ch)
     106{
     107    static const uint8_t mark[7] =
     108    {
     109        0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
     110    };
     111
     112    char *parser = buf;
     113    int bytes;
     114
     115    if(ch < 0x80)
     116    {
     117        *parser++ = ch;
     118        return 1;
     119    }
     120
     121    bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4;
     122    parser += bytes;
     123
     124    switch(bytes)
     125    {
     126        case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
     127        case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
     128        case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
     129    }
     130    *--parser = ch | mark[bytes];
     131
     132    return bytes;
    103133}
    104134
  • libcaca/trunk/cucul/cucul_internals.h

    r896 r927  
    5959extern char const *_cucul_skip_utf8(char const *, unsigned int);
    6060extern uint32_t _cucul_utf8_to_utf32(char const *);
     61extern unsigned int _cucul_utf32_to_utf8(void *, uint32_t);
    6162extern uint8_t _cucul_utf32_to_cp437(uint32_t);
    6263extern uint32_t _cucul_cp437_to_utf32(uint8_t);
Note: See TracChangeset for help on using the changeset viewer.