1 /* Access functions for CNS 11643, plane 2 handling.
2 Copyright (C) 1998, 1999, 2000 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. */
23 /* Table for CNS 11643, plane 1 to UCS4 conversion. */
24 extern const uint16_t __cns11643l1_to_ucs4_tab
[];
25 /* Table for CNS 11643, plane 2 to UCS4 conversion. */
26 extern const uint16_t __cns11643l2_to_ucs4_tab
[];
27 /* Table for CNS 11643, plane 14 to UCS4 conversion. */
28 extern const uint16_t __cns11643l14_to_ucs4_tab
[];
31 static inline uint32_t
32 cns11643_to_ucs4 (const char **s
, size_t avail
, unsigned char offset
)
34 unsigned char ch
= *(*s
);
40 if (ch
< offset
|| (ch
- offset
) <= 0x20 || (ch
- offset
) > 0x30)
41 return __UNKNOWN_10646_CHAR
;
47 if ((ch2
- offset
) <= 0x20 || (ch2
- offset
) >= 0x7f)
48 return __UNKNOWN_10646_CHAR
;
51 if ((ch3
- offset
) <= 0x20 || (ch3
- offset
) >= 0x7f)
52 return __UNKNOWN_10646_CHAR
;
54 idx
= (ch2
- 0x21 - offset
) * 94 + (ch3
- 0x21 - offset
);
56 if ((ch
- 0x20 - offset
) == 1)
59 return __UNKNOWN_10646_CHAR
;
60 result
= __cns11643l1_to_ucs4_tab
[idx
];
62 else if ((ch
- 0x20 - offset
) == 2)
65 return __UNKNOWN_10646_CHAR
;
66 result
= __cns11643l2_to_ucs4_tab
[idx
];
68 else if ((ch
- 0x20 - offset
) == 0xe)
71 return __UNKNOWN_10646_CHAR
;
72 result
= __cns11643l14_to_ucs4_tab
[idx
];
75 return __UNKNOWN_10646_CHAR
;
80 result
= __UNKNOWN_10646_CHAR
;
86 /* Tables for the UCS4 -> CNS conversion. */
87 extern const char __cns11643l1_from_ucs4_tab1
[][2];
88 extern const char __cns11643l1_from_ucs4_tab2
[][2];
89 extern const char __cns11643l1_from_ucs4_tab3
[][2];
90 extern const char __cns11643l1_from_ucs4_tab4
[][2];
91 extern const char __cns11643l1_from_ucs4_tab5
[][2];
92 extern const char __cns11643l1_from_ucs4_tab6
[][2];
93 extern const char __cns11643l1_from_ucs4_tab7
[][2];
94 extern const char __cns11643l1_from_ucs4_tab8
[][2];
95 extern const char __cns11643l1_from_ucs4_tab9
[][2];
96 extern const char __cns11643l1_from_ucs4_tab10
[][2];
97 extern const char __cns11643l1_from_ucs4_tab11
[][2];
98 extern const char __cns11643l1_from_ucs4_tab12
[][2];
99 extern const char __cns11643l1_from_ucs4_tab13
[][2];
100 extern const char __cns11643l1_from_ucs4_tab14
[][2];
101 extern const char __cns11643_from_ucs4_tab
[][3];
105 ucs4_to_cns11643 (uint32_t wch
, char *s
, size_t avail
)
107 unsigned int ch
= (unsigned int) wch
;
109 const char *cp
= buf
;
115 cp
= __cns11643l1_from_ucs4_tab1
[ch
- 0xa7];
117 case 0x2c7 ... 0x2d9:
118 cp
= __cns11643l1_from_ucs4_tab2
[ch
- 0x2c7];
120 case 0x391 ... 0x3c9:
121 cp
= __cns11643l1_from_ucs4_tab3
[ch
- 0x391];
123 case 0x2013 ... 0x203e:
124 cp
= __cns11643l1_from_ucs4_tab4
[ch
- 0x2013];
135 case 0x2160 ... 0x2169:
137 buf
[1] = '\x2b' + (ch
- 0x2160);
139 case 0x2170 ... 0x2179:
141 buf
[1] = '\x35' + (ch
- 0x2170);
143 case 0x2190 ... 0x2199:
144 cp
= __cns11643l1_from_ucs4_tab5
[ch
- 0x2190];
146 case 0x2215 ... 0x2267:
147 cp
= __cns11643l1_from_ucs4_tab6
[ch
- 0x2215];
155 case 0x2400 ... 0x2421:
156 cp
= __cns11643l1_from_ucs4_tab7
[ch
- 0x2400];
158 case 0x2460 ... 0x247d:
159 cp
= __cns11643l1_from_ucs4_tab8
[ch
- 0x2460];
161 case 0x2500 ... 0x2642:
162 cp
= __cns11643l1_from_ucs4_tab9
[ch
- 0x2500];
164 case 0x3000 ... 0x3029:
165 cp
= __cns11643l1_from_ucs4_tab10
[ch
- 0x3000];
170 case 0x3105 ... 0x3129:
172 buf
[1] = '\x47' + (ch
- 0x3105);
177 case 0x338e ... 0x33d5:
178 cp
= __cns11643l1_from_ucs4_tab11
[ch
- 0x338e];
180 case 0x4e00 ... 0x9f9c:
181 cp
= __cns11643l1_from_ucs4_tab12
[ch
- 0x4e00];
185 /* FALLTHROUGH. Let's try the other planes. */
186 case 0x9f9d ... 0x9fa5:
187 /* Let's try the other planes. */
189 cp
= __cns11643_from_ucs4_tab
[ch
- 0x4e00];
191 case 0xfe30 ... 0xfe6b:
192 cp
= __cns11643l1_from_ucs4_tab13
[ch
- 0xfe30];
194 case 0xff01 ... 0xff5d:
195 cp
= __cns11643l1_from_ucs4_tab14
[ch
- 0xff01];
207 return __UNKNOWN_10646_CHAR
;
211 return __UNKNOWN_10646_CHAR
;