Unicode to UTF-8

From Stack Overflow
Jump to: navigation, search
void unicodeToUtf8(unsigned short unicode, char *s)
{
    if ((unicode >= 0x0800) && (unicode <= 0xD7FF))
    {
        *s++ = 0xe0 | (char) ((unicode >> 12) & 0x0f);
        *s++ = 0x80 | (char) ((unicode >>  6) & 0x3f);
        *s++ = 0x80 | (char) ( unicode        & 0x3f);
        *s++ = 0;
    }
    else
        printf("Don't know how to handle unicode 0x%04X\n", unicode);
}
Personal tools