1 /* Access functions for CNS 11643, plane 1 handling.
2 Copyright (C) 1998-2023 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
[];
26 static inline uint32_t
27 __attribute ((always_inline
))
28 cns11643l1_to_ucs4 (const unsigned char **s
, size_t avail
,
31 unsigned char ch
= *(*s
);
35 if (ch
< offset
|| (ch
- offset
) <= 0x20 || (ch
- offset
) > 0x7d)
36 return __UNKNOWN_10646_CHAR
;
42 if ((ch2
- offset
) <= 0x20 || (ch2
- offset
) >= 0x7f)
43 return __UNKNOWN_10646_CHAR
;
45 idx
= (ch
- 0x21 - offset
) * 94 + (ch2
- 0x21 - offset
);
47 return __UNKNOWN_10646_CHAR
;
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];
73 __attribute ((always_inline
))
74 ucs4_to_cns11643l1 (uint32_t wch
, unsigned char *s
, size_t avail
)
76 unsigned int ch
= (unsigned int) wch
;
83 cp
= __cns11643l1_from_ucs4_tab1
[ch
- 0xa7];
86 cp
= __cns11643l1_from_ucs4_tab2
[ch
- 0x2c7];
89 cp
= __cns11643l1_from_ucs4_tab3
[ch
- 0x391];
91 case 0x2013 ... 0x203e:
92 cp
= __cns11643l1_from_ucs4_tab4
[ch
- 0x2013];
103 case 0x2160 ... 0x2169:
105 buf
[1] = '\x2b' + (ch
- 0x2160);
107 case 0x2170 ... 0x2179:
109 buf
[1] = '\x35' + (ch
- 0x2170);
111 case 0x2190 ... 0x2199:
112 cp
= __cns11643l1_from_ucs4_tab5
[ch
- 0x2190];
114 case 0x2215 ... 0x2267:
115 cp
= __cns11643l1_from_ucs4_tab6
[ch
- 0x2215];
123 case 0x2400 ... 0x2421:
124 cp
= __cns11643l1_from_ucs4_tab7
[ch
- 0x2400];
126 case 0x2460 ... 0x247d:
127 cp
= __cns11643l1_from_ucs4_tab8
[ch
- 0x2460];
129 case 0x2500 ... 0x2642:
130 cp
= __cns11643l1_from_ucs4_tab9
[ch
- 0x2500];
132 case 0x3000 ... 0x3029:
133 cp
= __cns11643l1_from_ucs4_tab10
[ch
- 0x3000];
138 case 0x3105 ... 0x3129:
140 buf
[1] = '\x47' + (ch
- 0x3105);
145 case 0x338e ... 0x33d5:
146 cp
= __cns11643l1_from_ucs4_tab11
[ch
- 0x338e];
148 case 0x4e00 ... 0x9f9c:
149 cp
= __cns11643l1_from_ucs4_tab12
[ch
- 0x4e00];
151 case 0xfe30 ... 0xfe6b:
152 cp
= __cns11643l1_from_ucs4_tab13
[ch
- 0xfe30];
154 case 0xff01 ... 0xff5d:
155 cp
= __cns11643l1_from_ucs4_tab14
[ch
- 0xff01];
167 return __UNKNOWN_10646_CHAR
;
171 return __UNKNOWN_10646_CHAR
;