Fix tochar16_unicode

This commit is contained in:
Gregory Lirent 2022-08-18 10:44:01 +03:00
parent 974541fd6e
commit 350232189a

View File

@ -3,10 +3,14 @@
#include "build.h" #include "build.h"
char32_t* tochar32_unicode(char32_t d[1], unsigned int uc) { char16_t* tochar16_unicode(char16_t d[2], unsigned int uc) {
if (uc <= 0x10ffff && (uc < 0xd800 || uc > 0xdfff)) { if (uc <= 0xffff) {
*(d++) = uc; *(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; return d;
} }