#include <stdint.h>
#include <windows.h>
void from_unicode_to_utf8(char *out, uint32_t utf)
{
if (utf <= 0x7F) {
out[0] = utf;
out[1] = 0;
}
else if (utf <= 0x07FF) {
out[0] = (char) (((utf >> 6) & 0x1F) | 0xC0);
out[1] = (char) (((utf >> 0) & 0x3F) | 0x80);
out[2] = 0;
}
else if (utf <= 0xFFFF) {
out[0] = (char) (((utf >> 12) & 0x0F) | 0xE0);
out[1] = (char) (((utf >> 6) & 0x3F) | 0x80);
out[2] = (char) (((utf >> 0) & 0x3F) | 0x80);
out[3] = 0;
}
else if (utf <= 0x1FFFFF) {
out[0] = (char) (((utf >> 18) & 0x07) | 0xF0);
out[1] = (char) (((utf >> 12) & 0x3F) | 0x80);
out[2] = (char) (((utf >> 6) & 0x3F) | 0x80);
out[3] = (char) (((utf >> 0) & 0x3F) | 0x80);
out[4] = 0;
}
else {
out[0] = 0xEF;
out[1] = 0xBF;
out[2] = 0xBD;
out[3] = 0;
}
}