1 /* Access functions for CNS 11643, plane 2 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. */
24 /* Table for CNS 11643, plane 2 to UCS4 conversion. */
25 extern const uint16_t __cns11643l2_to_ucs4_tab
[];
28 static inline uint32_t
29 cns11643l2_to_ucs4 (const unsigned char **s
, size_t avail
,
32 unsigned char ch
= *(*s
);
36 if (ch
< offset
|| (ch
- offset
) <= 0x20 || (ch
- offset
) > 0x7d)
37 return __UNKNOWN_10646_CHAR
;
43 if ((ch2
- offset
) <= 0x20 || (ch2
- offset
) >= 0x7f)
44 return __UNKNOWN_10646_CHAR
;
46 idx
= (ch
- 0x21 - offset
) * 94 + (ch2
- 0x21 - offset
);
48 return __UNKNOWN_10646_CHAR
;
52 return __cns11643l2_to_ucs4_tab
[idx
] ?: ((*s
) -= 2, __UNKNOWN_10646_CHAR
);
56 /* The table which contains the CNS 11643 level 2 mappings. */
57 extern const char __cns11643_from_ucs4_tab
[][3];
61 ucs4_to_cns11643l2 (uint32_t wch
, unsigned char *s
, size_t avail
)
63 unsigned int ch
= (unsigned int) wch
;
64 const char *cp
= NULL
;
66 if (ch
>= 0x4e07 && ch
<= 0x9fa4)
68 cp
= __cns11643_from_ucs4_tab
[ch
- 0x4e00];
76 return __UNKNOWN_10646_CHAR
;