/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include "build.h" char* tochar_unicode(char d[4], unsigned int uc) { if (uc <= 0x7f) { *d++ = uc; return d; } else if (uc <= 0x7ff) { *(d++) = 0xc0 | ((uc&0x07c0) >> 6); } else { if (uc <= 0xffff) { *(d++) = 0xe0 | ((uc&0xf000) >> 12); } else if (uc <= 0x10ffff) { *(d++) = 0xf0 | ((uc&0x1c0000) >> 18); *(d++) = 0x80 | ((uc&0x03f000) >> 12); } else return 0; *(d++) = 0x80 | ((uc&0x000fc0) >> 6); } *(d++) = 0x80 | (uc&0x003f); return d; }