~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/xpdflib/utf8.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2005-02-24 22:09:16 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050224220916-9vxiiqjz066r5489
Tags: 6.0pre23-2
debian/control: Ipe should depend on exact version of libipe.
Closes: #296771.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- C++ -*-
2
 
//========================================================================
3
 
//
4
 
// UTF8.h
5
 
//
6
 
// Copyright 2001-2002 Glyph & Cog, LLC
7
 
//
8
 
//========================================================================
9
 
 
10
 
static int mapUTF8(Unicode u, char *buf, int bufSize) {
11
 
  if        (u <= 0x0000007f) {
12
 
    if (bufSize < 1) {
13
 
      return 0;
14
 
    }
15
 
    buf[0] = (char)u;
16
 
    return 1;
17
 
  } else if (u <= 0x000007ff) {
18
 
    if (bufSize < 2) {
19
 
      return 0;
20
 
    }
21
 
    buf[0] = (char)(0xc0 + (u >> 6));
22
 
    buf[1] = (char)(0x80 + (u & 0x3f));
23
 
    return 2;
24
 
  } else if (u <= 0x0000ffff) {
25
 
    if (bufSize < 3) {
26
 
      return 0;
27
 
    }
28
 
    buf[0] = (char)(0xe0 + (u >> 12));
29
 
    buf[1] = (char)(0x80 + ((u >> 6) & 0x3f));
30
 
    buf[2] = (char)(0x80 + (u & 0x3f));
31
 
    return 3;
32
 
  } else if (u <= 0x0010ffff) {
33
 
    if (bufSize < 4) {
34
 
      return 0;
35
 
    }
36
 
    buf[0] = (char)(0xf0 + (u >> 18));
37
 
    buf[1] = (char)(0x80 + ((u >> 12) & 0x3f));
38
 
    buf[2] = (char)(0x80 + ((u >> 6) & 0x3f));
39
 
    buf[3] = (char)(0x80 + (u & 0x3f));
40
 
    return 4;
41
 
  } else {
42
 
    return 0;
43
 
  }
44
 
}
45
 
 
46
 
static int mapUCS2(Unicode u, char *buf, int bufSize) {
47
 
  if (u <= 0xffff) {
48
 
    if (bufSize < 2) {
49
 
      return 0;
50
 
    }
51
 
    buf[0] = (char)((u >> 8) & 0xff);
52
 
    buf[1] = (char)(u & 0xff);
53
 
    return 2;
54
 
  } else {
55
 
    return 0;
56
 
  }
57
 
}