Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. int ucs2_utf8(wchar_t in, unsigned char* out) {
  2.     if (in < 0x80) {
  3.         out[0] = in;
  4.         out[1] = 0;
  5.         return 0;
  6.     }
  7.     else if (in < 0x800) {
  8.         out[0] = 0xC0 | ((in & 0x07C0) >> 6);
  9.         out[1] = 0x80 |  (in & 0x003F);
  10.         out[2] = 0;
  11.         return 0;
  12.     }
  13.     else if (in < 0x10000) {
  14.         out[0] = 0xE0 | ((in & 0xF000) >> 12);
  15.         out[1] = 0x80 | ((in & 0x0FC0) >> 6);
  16.         out[2] = 0x80 |  (in & 0x003F);
  17.         out[3] = 0;
  18.         return 0;
  19.     }
  20.     return -1;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement