annotate lib/unistr/u8-uctomb-aux.c @ 14079:97fc9a21a8fb

maint: update almost all copyright ranges to include 2011 Run the new "make update-copyright" rule.
author Jim Meyering <meyering@redhat.com>
date Sat, 01 Jan 2011 20:17:23 +0100
parents c2cbabec01dd
children 8250f2777afc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8516
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Conversion UCS-4 to UTF-8.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 12559
diff changeset
2 Copyright (C) 2002, 2006-2007, 2009-2011 Free Software Foundation, Inc.
8516
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2002.
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9307
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8520
diff changeset
5 This program is free software: you can redistribute it and/or modify it
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8520
diff changeset
6 under the terms of the GNU Lesser General Public License as published
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8520
diff changeset
7 by the Free Software Foundation; either version 3 of the License, or
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8520
diff changeset
8 (at your option) any later version.
8516
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9307
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8520
diff changeset
13 Lesser General Public License for more details.
8516
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
9307
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8520
diff changeset
15 You should have received a copy of the GNU Lesser General Public License
ad8a75a45dc9 Change copyright notice from LGPLv2.0+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8520
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8516
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "unistr.h"
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 int
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 {
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 int count;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 if (uc < 0x80)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 /* The case n >= 1 is already handled by the caller. */
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 return -2;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 else if (uc < 0x800)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 count = 2;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 else if (uc < 0x10000)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 {
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 if (uc < 0xd800 || uc >= 0xe000)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9416
diff changeset
36 count = 3;
8516
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9416
diff changeset
38 return -1;
8516
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 }
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 #if 0
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 else if (uc < 0x200000)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 count = 4;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 else if (uc < 0x4000000)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 count = 5;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 else if (uc <= 0x7fffffff)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 count = 6;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #else
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 else if (uc < 0x110000)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 count = 4;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 #endif
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 else
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 return -1;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 if (n < count)
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 return -2;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 switch (count) /* note: code falls through cases! */
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 {
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 #if 0
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 #endif
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 /*case 1:*/ s[0] = uc;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 }
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 return count;
e94dbabdfade Move to here from ucs4-utf8.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 }