Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ucs2_utf8(wchar_t in, unsigned char* out) {
- if (in < 0x80) {
- out[0] = in;
- out[1] = 0;
- return 0;
- }
- else if (in < 0x800) {
- out[0] = 0xC0 | ((in & 0x07C0) >> 6);
- out[1] = 0x80 | (in & 0x003F);
- out[2] = 0;
- return 0;
- }
- else if (in < 0x10000) {
- out[0] = 0xE0 | ((in & 0xF000) >> 12);
- out[1] = 0x80 | ((in & 0x0FC0) >> 6);
- out[2] = 0x80 | (in & 0x003F);
- out[3] = 0;
- return 0;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement