]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/cns11643l1.h
Update.
[thirdparty/glibc.git] / iconvdata / cns11643l1.h
CommitLineData
2b474353 1/* Access functions for CNS 11643, plane 1 handling.
dd9423a6 2 Copyright (C) 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
2b474353
UD
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
2b474353
UD
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 14 Lesser General Public License for more details.
2b474353 15
41bdb6e2
AJ
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
2b474353
UD
20
21#include <stdint.h>
8619129f 22#include <gconv.h>
2b474353
UD
23
24/* Table for CNS 11643, plane 1 to UCS4 conversion. */
8619129f 25extern const uint16_t __cns11643l1_to_ucs4_tab[];
2b474353
UD
26
27
9b26f5c4 28static inline uint32_t
dd9423a6 29__attribute ((always_inline))
15a2315c
UD
30cns11643l1_to_ucs4 (const unsigned char **s, size_t avail,
31 unsigned char offset)
2b474353
UD
32{
33 unsigned char ch = *(*s);
34 unsigned char ch2;
35 int idx;
36
37 if (ch < offset || (ch - offset) <= 0x20 || (ch - offset) > 0x7d)
d64b6ad0 38 return __UNKNOWN_10646_CHAR;
2b474353
UD
39
40 if (avail < 2)
41 return 0;
42
43 ch2 = (*s)[1];
44 if ((ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
d64b6ad0 45 return __UNKNOWN_10646_CHAR;
2b474353
UD
46
47 idx = (ch - 0x21 - offset) * 94 + (ch2 - 0x21 - offset);
b79f74cd 48 if (idx > 0x21f2)
d64b6ad0 49 return __UNKNOWN_10646_CHAR;
2b474353
UD
50
51 (*s) += 2;
52
d64b6ad0 53 return __cns11643l1_to_ucs4_tab[idx] ?: ((*s) -= 2, __UNKNOWN_10646_CHAR);
2b474353
UD
54}
55
56
57/* Tables for the UCS4 -> CNS conversion. */
8619129f
UD
58extern const char __cns11643l1_from_ucs4_tab1[][2];
59extern const char __cns11643l1_from_ucs4_tab2[][2];
60extern const char __cns11643l1_from_ucs4_tab3[][2];
61extern const char __cns11643l1_from_ucs4_tab4[][2];
62extern const char __cns11643l1_from_ucs4_tab5[][2];
63extern const char __cns11643l1_from_ucs4_tab6[][2];
64extern const char __cns11643l1_from_ucs4_tab7[][2];
65extern const char __cns11643l1_from_ucs4_tab8[][2];
66extern const char __cns11643l1_from_ucs4_tab9[][2];
67extern const char __cns11643l1_from_ucs4_tab10[][2];
68extern const char __cns11643l1_from_ucs4_tab11[][2];
69extern const char __cns11643l1_from_ucs4_tab12[][2];
70extern const char __cns11643l1_from_ucs4_tab13[][2];
71extern const char __cns11643l1_from_ucs4_tab14[][2];
2b474353
UD
72
73
74static inline size_t
dd9423a6 75__attribute ((always_inline))
15a2315c 76ucs4_to_cns11643l1 (uint32_t wch, unsigned char *s, size_t avail)
2b474353
UD
77{
78 unsigned int ch = (unsigned int) wch;
79 char buf[2];
8619129f
UD
80 const char *cp = buf;
81
82 switch (ch)
2b474353 83 {
8619129f
UD
84 case 0xa7 ... 0xf7:
85 cp = __cns11643l1_from_ucs4_tab1[ch - 0xa7];
86 break;
87 case 0x2c7 ... 0x2d9:
88 cp = __cns11643l1_from_ucs4_tab2[ch - 0x2c7];
89 break;
90 case 0x391 ... 0x3c9:
91 cp = __cns11643l1_from_ucs4_tab3[ch - 0x391];
9b26f5c4 92 break;
8619129f
UD
93 case 0x2013 ... 0x203e:
94 cp = __cns11643l1_from_ucs4_tab4[ch - 0x2013];
9b26f5c4 95 break;
8619129f
UD
96 case 0x2103:
97 cp = "\x22\x6a";
98 break;
99 case 0x2105:
100 cp = "\x22\x22";
101 break;
102 case 0x2109:
103 cp = "\x22\x6b";
104 break;
105 case 0x2160 ... 0x2169:
2b474353
UD
106 buf[0] = '\x24';
107 buf[1] = '\x2b' + (ch - 0x2160);
8619129f
UD
108 break;
109 case 0x2170 ... 0x2179:
2b474353
UD
110 buf[0] = '\x26';
111 buf[1] = '\x35' + (ch - 0x2170);
8619129f 112 break;
9b26f5c4 113 case 0x2190 ... 0x2199:
8619129f
UD
114 cp = __cns11643l1_from_ucs4_tab5[ch - 0x2190];
115 break;
116 case 0x2215 ... 0x2267:
117 cp = __cns11643l1_from_ucs4_tab6[ch - 0x2215];
118 break;
119 case 0x22a5:
120 cp = "\x22\x47";
121 break;
122 case 0x22bf:
123 cp = "\x22\x4a";
124 break;
125 case 0x2400 ... 0x2421:
126 cp = __cns11643l1_from_ucs4_tab7[ch - 0x2400];
127 break;
128 case 0x2460 ... 0x247d:
129 cp = __cns11643l1_from_ucs4_tab8[ch - 0x2460];
130 break;
131 case 0x2500 ... 0x2642:
132 cp = __cns11643l1_from_ucs4_tab9[ch - 0x2500];
133 break;
134 case 0x3000 ... 0x3029:
135 cp = __cns11643l1_from_ucs4_tab10[ch - 0x3000];
136 break;
137 case 0x30fb:
138 cp = "\x21\x26";
139 break;
140 case 0x3105 ... 0x3129:
2b474353 141 buf[0] = '\x25';
b79f74cd 142 buf[1] = '\x47' + (ch - 0x3105);
8619129f
UD
143 break;
144 case 0x32a3:
145 cp = "\x22\x21";
146 break;
147 case 0x338e ... 0x33d5:
148 cp = __cns11643l1_from_ucs4_tab11[ch - 0x338e];
149 break;
150 case 0x4e00 ... 0x9f9c:
151 cp = __cns11643l1_from_ucs4_tab12[ch - 0x4e00];
152 break;
153 case 0xfe30 ... 0xfe6b:
154 cp = __cns11643l1_from_ucs4_tab13[ch - 0xfe30];
155 break;
156 case 0xff01 ... 0xff5d:
157 cp = __cns11643l1_from_ucs4_tab14[ch - 0xff01];
158 break;
159 case 0xffe0:
160 cp = "\x22\x66";
161 break;
162 case 0xffe1:
163 cp = "\x22\x67";
164 break;
165 case 0xffe5:
166 cp = "\x22\x64";
167 break;
168 default:
d64b6ad0 169 return __UNKNOWN_10646_CHAR;
2b474353 170 }
2b474353
UD
171
172 if (cp[0] == '\0')
d64b6ad0 173 return __UNKNOWN_10646_CHAR;
2b474353
UD
174
175 if (avail < 2)
176 return 0;
177
178 s[0] = cp[0];
179 s[1] = cp[1];
180
181 return 2;
182}