Explorar el Código

* Implemented the private _cucul_utf32_to_utf8() helper.

tags/v0.99.beta14
Sam Hocevar sam hace 18 años
padre
commit
4d029660e1
Se han modificado 2 ficheros con 31 adiciones y 0 borrados
  1. +30
    -0
      cucul/charset.c
  2. +1
    -0
      cucul/cucul_internals.h

+ 30
- 0
cucul/charset.c Ver fichero

@@ -102,6 +102,36 @@ uint32_t _cucul_utf8_to_utf32(char const *s)
return ret;
}

unsigned int _cucul_utf32_to_utf8(void *buf, uint32_t ch)
{
static const uint8_t mark[7] =
{
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
};

char *parser = buf;
int bytes;

if(ch < 0x80)
{
*parser++ = ch;
return 1;
}

bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4;
parser += bytes;

switch(bytes)
{
case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
}
*--parser = ch | mark[bytes];

return bytes;
}

/*
* CP437 handling
*/


+ 1
- 0
cucul/cucul_internals.h Ver fichero

@@ -58,6 +58,7 @@ extern void _cucul_putchar32(cucul_canvas_t *, int, int, uint32_t);
extern unsigned int _cucul_strlen_utf8(char const *);
extern char const *_cucul_skip_utf8(char const *, unsigned int);
extern uint32_t _cucul_utf8_to_utf32(char const *);
extern unsigned int _cucul_utf32_to_utf8(void *, uint32_t);
extern uint8_t _cucul_utf32_to_cp437(uint32_t);
extern uint32_t _cucul_cp437_to_utf32(uint8_t);



Cargando…
Cancelar
Guardar