libunic/tochar16_unicode.c

17 lines
477 B
C
Raw Normal View History

2022-05-31 15:28:37 +03:00
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "build.h"
2022-08-18 10:44:01 +03:00
char16_t* tochar16_unicode(char16_t d[2], unsigned int uc) {
if (uc <= 0xffff) {
2022-05-31 15:28:37 +03:00
*(d++) = uc;
2022-08-18 10:44:01 +03:00
} else if (uc <= 0x10ffff && (uc < 0xd800 || uc > 0xdfff)) {
uc -= 0x010000;
*(d++) = 0xd800 | (uc&0x0ffc00)>>10;
*(d++) = 0xdc00 | (uc&0x03ff);
} else d = 0;
2022-05-31 15:28:37 +03:00
return d;
}