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