1 /* Access functions for CNS 11643 handling.
2 Copyright (C) 1998-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 /* Table for CNS 11643, plane 1 to UCS4 conversion. */
23 extern const uint16_t __cns11643l1_to_ucs4_tab
[];
24 /* Table for CNS 11643, plane 2 to UCS4 conversion. */
25 extern const uint16_t __cns11643l2_to_ucs4_tab
[];
26 /* Table for CNS 11643, plane 3 to UCS4 conversion. */
27 extern const uint32_t __cns11643l3_to_ucs4_tab
[];
28 /* Table for CNS 11643, plane 4 to UCS4 conversion. */
29 extern const uint32_t __cns11643l4_to_ucs4_tab
[];
30 /* Table for CNS 11643, plane 5 to UCS4 conversion. */
31 extern const uint32_t __cns11643l5_to_ucs4_tab
[];
32 /* Table for CNS 11643, plane 6 to UCS4 conversion. */
33 extern const uint32_t __cns11643l6_to_ucs4_tab
[];
34 /* Table for CNS 11643, plane 7 to UCS4 conversion. */
35 extern const uint32_t __cns11643l7_to_ucs4_tab
[];
36 /* Table for CNS 11643, plane 15 (old) to UCS4 conversion. */
37 extern const uint32_t __cns11643l15_to_ucs4_tab
[];
40 static inline uint32_t
41 __attribute ((always_inline
))
42 cns11643_to_ucs4 (const unsigned char **s
, size_t avail
, unsigned char offset
)
44 unsigned char ch
= *(*s
);
50 if (ch
< offset
|| (ch
- offset
) <= 0x20 || (ch
- offset
) > 0x30)
51 return __UNKNOWN_10646_CHAR
;
57 if ((ch2
- offset
) <= 0x20 || (ch2
- offset
) >= 0x7f)
58 return __UNKNOWN_10646_CHAR
;
61 if ((ch3
- offset
) <= 0x20 || (ch3
- offset
) >= 0x7f)
62 return __UNKNOWN_10646_CHAR
;
64 idx
= (ch2
- 0x21 - offset
) * 94 + (ch3
- 0x21 - offset
);
66 switch (ch
- 0x20 - offset
)
70 return __UNKNOWN_10646_CHAR
;
71 result
= __cns11643l1_to_ucs4_tab
[idx
];
75 return __UNKNOWN_10646_CHAR
;
76 result
= __cns11643l2_to_ucs4_tab
[idx
];
80 return __UNKNOWN_10646_CHAR
;
81 result
= __cns11643l3_to_ucs4_tab
[idx
];
85 return __UNKNOWN_10646_CHAR
;
86 result
= __cns11643l4_to_ucs4_tab
[idx
];
90 return __UNKNOWN_10646_CHAR
;
91 result
= __cns11643l5_to_ucs4_tab
[idx
];
95 return __UNKNOWN_10646_CHAR
;
96 result
= __cns11643l6_to_ucs4_tab
[idx
];
100 return __UNKNOWN_10646_CHAR
;
101 result
= __cns11643l7_to_ucs4_tab
[idx
];
105 return __UNKNOWN_10646_CHAR
;
106 result
= __cns11643l15_to_ucs4_tab
[idx
];
109 return __UNKNOWN_10646_CHAR
;
115 result
= __UNKNOWN_10646_CHAR
;
121 /* Tables for the UCS4 -> CNS conversion. */
122 extern const char __cns11643l1_from_ucs4_tab1
[][2];
123 extern const char __cns11643l1_from_ucs4_tab2
[][2];
124 extern const char __cns11643l1_from_ucs4_tab3
[][2];
125 extern const char __cns11643l1_from_ucs4_tab4
[][2];
126 extern const char __cns11643l1_from_ucs4_tab5
[][2];
127 extern const char __cns11643l1_from_ucs4_tab6
[][2];
128 extern const char __cns11643l1_from_ucs4_tab7
[][2];
129 extern const char __cns11643l1_from_ucs4_tab8
[][2];
130 extern const char __cns11643l1_from_ucs4_tab9
[][2];
131 extern const char __cns11643l1_from_ucs4_tab10
[][2];
132 extern const char __cns11643l1_from_ucs4_tab11
[][2];
133 extern const char __cns11643l1_from_ucs4_tab12
[][2];
134 extern const char __cns11643l1_from_ucs4_tab13
[][2];
135 extern const char __cns11643l1_from_ucs4_tab14
[][2];
136 extern const char __cns11643_from_ucs4p0_tab
[][3];
137 extern const char __cns11643_from_ucs4p2_tab
[][3];
138 extern const char __cns11643_from_ucs4p2c_tab
[][3];
142 __attribute ((always_inline
))
143 ucs4_to_cns11643 (uint32_t wch
, unsigned char *s
, size_t avail
)
145 unsigned int ch
= (unsigned int) wch
;
147 const char *cp
= buf
;
153 cp
= __cns11643l1_from_ucs4_tab1
[ch
- 0xa7];
155 case 0x2c7 ... 0x2d9:
156 cp
= __cns11643l1_from_ucs4_tab2
[ch
- 0x2c7];
158 case 0x391 ... 0x3c9:
159 cp
= __cns11643l1_from_ucs4_tab3
[ch
- 0x391];
161 case 0x2013 ... 0x203e:
162 cp
= __cns11643l1_from_ucs4_tab4
[ch
- 0x2013];
173 case 0x2160 ... 0x2169:
175 buf
[1] = '\x2b' + (ch
- 0x2160);
177 case 0x2170 ... 0x2179:
179 buf
[1] = '\x35' + (ch
- 0x2170);
181 case 0x2190 ... 0x2199:
182 cp
= __cns11643l1_from_ucs4_tab5
[ch
- 0x2190];
184 case 0x2215 ... 0x2267:
185 cp
= __cns11643l1_from_ucs4_tab6
[ch
- 0x2215];
193 case 0x2400 ... 0x2421:
194 cp
= __cns11643l1_from_ucs4_tab7
[ch
- 0x2400];
196 case 0x2460 ... 0x247d:
197 cp
= __cns11643l1_from_ucs4_tab8
[ch
- 0x2460];
199 case 0x2500 ... 0x2642:
200 cp
= __cns11643l1_from_ucs4_tab9
[ch
- 0x2500];
202 case 0x3000 ... 0x3029:
203 cp
= __cns11643l1_from_ucs4_tab10
[ch
- 0x3000];
208 case 0x3105 ... 0x3129:
210 buf
[1] = '\x47' + (ch
- 0x3105);
215 case 0x338e ... 0x33d5:
216 cp
= __cns11643l1_from_ucs4_tab11
[ch
- 0x338e];
218 case 0x4e00 ... 0x9f9c:
219 cp
= __cns11643l1_from_ucs4_tab12
[ch
- 0x4e00];
222 /* Let's try the other planes. */
224 case 0x3400 ... 0x4dff:
225 case 0x9f9d ... 0x9fa5:
226 /* Let's try the other planes. */
228 cp
= __cns11643_from_ucs4p0_tab
[ch
- 0x3400];
234 case 0xfe30 ... 0xfe6b:
235 cp
= __cns11643l1_from_ucs4_tab13
[ch
- 0xfe30];
237 case 0xff01 ... 0xff5d:
238 cp
= __cns11643l1_from_ucs4_tab14
[ch
- 0xff01];
249 case 0x20000 ... 0x2a6d6:
251 cp
= __cns11643_from_ucs4p2_tab
[ch
- 0x20000];
253 case 0x2f800 ... 0x2fa1d:
255 cp
= __cns11643_from_ucs4p2c_tab
[ch
- 0x2f800];
258 return __UNKNOWN_10646_CHAR
;
262 return __UNKNOWN_10646_CHAR
;