upgrade to xpdf 3.00.
[swftools.git] / pdf2swf / xpdf / UTF8.h
blob8536dbf9436924dd13c5e3d5ea1dd59740e1c3e0
1 //========================================================================
2 //
3 // UTF8.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 static int mapUTF8(Unicode u, char *buf, int bufSize) {
10 if (u <= 0x0000007f) {
11 if (bufSize < 1) {
12 return 0;
14 buf[0] = (char)u;
15 return 1;
16 } else if (u <= 0x000007ff) {
17 if (bufSize < 2) {
18 return 0;
20 buf[0] = (char)(0xc0 + (u >> 6));
21 buf[1] = (char)(0x80 + (u & 0x3f));
22 return 2;
23 } else if (u <= 0x0000ffff) {
24 if (bufSize < 3) {
25 return 0;
27 buf[0] = (char)(0xe0 + (u >> 12));
28 buf[1] = (char)(0x80 + ((u >> 6) & 0x3f));
29 buf[2] = (char)(0x80 + (u & 0x3f));
30 return 3;
31 } else if (u <= 0x0010ffff) {
32 if (bufSize < 4) {
33 return 0;
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));
39 return 4;
40 } else {
41 return 0;
45 static int mapUCS2(Unicode u, char *buf, int bufSize) {
46 if (u <= 0xffff) {
47 if (bufSize < 2) {
48 return 0;
50 buf[0] = (char)((u >> 8) & 0xff);
51 buf[1] = (char)(u & 0xff);
52 return 2;
53 } else {
54 return 0;