1 //========================================================================
5 // Copyright 2001-2003 Glyph & Cog, LLC
7 //========================================================================
9 static int mapUTF8(Unicode u
, char *buf
, int bufSize
) {
10 if (u
<= 0x0000007f) {
16 } else if (u
<= 0x000007ff) {
20 buf
[0] = (char)(0xc0 + (u
>> 6));
21 buf
[1] = (char)(0x80 + (u
& 0x3f));
23 } else if (u
<= 0x0000ffff) {
27 buf
[0] = (char)(0xe0 + (u
>> 12));
28 buf
[1] = (char)(0x80 + ((u
>> 6) & 0x3f));
29 buf
[2] = (char)(0x80 + (u
& 0x3f));
31 } else if (u
<= 0x0010ffff) {
35 buf
[0] = (char)(0xf0 + (u
>> 18));
36 buf
[1] = (char)(0x80 + ((u
>> 12) & 0x3f));
37 buf
[2] = (char)(0x80 + ((u
>> 6) & 0x3f));
38 buf
[3] = (char)(0x80 + (u
& 0x3f));
45 static int mapUCS2(Unicode u
, char *buf
, int bufSize
) {
50 buf
[0] = (char)((u
>> 8) & 0xff);
51 buf
[1] = (char)(u
& 0xff);