diff --git a/tochar16_unicode.c b/tochar16_unicode.c index 772e962..fe99803 100644 --- a/tochar16_unicode.c +++ b/tochar16_unicode.c @@ -3,10 +3,14 @@ #include "build.h" -char32_t* tochar32_unicode(char32_t d[1], unsigned int uc) { - if (uc <= 0x10ffff && (uc < 0xd800 || uc > 0xdfff)) { +char16_t* tochar16_unicode(char16_t d[2], unsigned int uc) { + if (uc <= 0xffff) { *(d++) = uc; - } else return 0; + } else if (uc <= 0x10ffff && (uc < 0xd800 || uc > 0xdfff)) { + uc -= 0x010000; + *(d++) = 0xd800 | (uc&0x0ffc00)>>10; + *(d++) = 0xdc00 | (uc&0x03ff); + } else d = 0; return d; }