1 /* Access functions for GB2312 conversion.
2 Copyright (C) 1998, 1999, 2003 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 Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 /* Conversion table. */
29 extern const uint16_t __gb2312_to_ucs
[];
32 static inline uint32_t
33 __attribute ((always_inline
))
34 gb2312_to_ucs4 (const unsigned char **s
, size_t avail
, unsigned char offset
)
36 unsigned char ch
= *(*s
);
40 if (ch
< offset
|| (ch
- offset
) <= 0x20 || (ch
- offset
) > 0x77)
41 return __UNKNOWN_10646_CHAR
;
47 if ((ch2
- offset
) <= 0x20 || (ch2
- offset
) >= 0x7f)
48 return __UNKNOWN_10646_CHAR
;
50 idx
= (ch
- 0x21 - offset
) * 94 + (ch2
- 0x21 - offset
);
52 return __UNKNOWN_10646_CHAR
;
56 return __gb2312_to_ucs
[idx
] ?: ((*s
) -= 2, __UNKNOWN_10646_CHAR
);
60 extern const char __gb2312_from_ucs4_tab1
[][2];
61 extern const char __gb2312_from_ucs4_tab2
[][2];
62 extern const char __gb2312_from_ucs4_tab3
[][2];
63 extern const char __gb2312_from_ucs4_tab4
[][2];
64 extern const char __gb2312_from_ucs4_tab5
[][2];
65 extern const char __gb2312_from_ucs4_tab6
[][2];
66 extern const char __gb2312_from_ucs4_tab7
[][2];
67 extern const char __gb2312_from_ucs4_tab8
[][2];
68 extern const char __gb2312_from_ucs4_tab9
[][2];
71 __attribute ((always_inline
))
72 ucs4_to_gb2312 (uint32_t wch
, unsigned char *s
, size_t avail
)
74 unsigned int ch
= (unsigned int) wch
;
81 cp
= __gb2312_from_ucs4_tab1
[ch
- 0xa4];
128 case 0x391 ... 0x3c9:
129 cp
= __gb2312_from_ucs4_tab2
[ch
- 0x391];
131 case 0x401 ... 0x451:
132 cp
= __gb2312_from_ucs4_tab3
[ch
- 0x401];
134 case 0x2015 ... 0x203b:
135 cp
= __gb2312_from_ucs4_tab4
[ch
- 0x2015];
137 case 0x2103 ... 0x22a5:
138 cp
= __gb2312_from_ucs4_tab5
[ch
- 0x2103];
143 case 0x2460 ... 0x249b:
144 cp
= __gb2312_from_ucs4_tab6
[ch
- 0x2460];
146 case 0x2500 ... 0x254b:
148 buf
[1] = '\x24' + (ch
% 256);
189 case 0x3000 ... 0x3129:
190 cp
= __gb2312_from_ucs4_tab7
[ch
- 0x3000];
192 case 0x3220 ... 0x3229:
194 buf
[1] = '\x65' + (ch
- 0x3220);
196 case 0x4e00 ... 0x9fa0:
197 cp
= __gb2312_from_ucs4_tab8
[ch
- 0x4e00];
199 case 0xff01 ... 0xff5e:
200 cp
= __gb2312_from_ucs4_tab9
[ch
- 0xff01];
215 return __UNKNOWN_10646_CHAR
;
219 return __UNKNOWN_10646_CHAR
;
221 assert (cp
[1] != '\0');
232 #endif /* gb2312.h */