1 /* Access functions for GB2312 conversion.
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. */
28 /* Conversion table. */
29 extern const uint16_t __gb2312_to_ucs
[];
32 static inline uint32_t
33 gb2312_to_ucs4 (const unsigned char **s
, size_t avail
, unsigned char offset
)
35 unsigned char ch
= *(*s
);
39 if (ch
< offset
|| (ch
- offset
) <= 0x20 || (ch
- offset
) > 0x77)
40 return __UNKNOWN_10646_CHAR
;
46 if ((ch2
- offset
) <= 0x20 || (ch2
- offset
) >= 0x7f)
47 return __UNKNOWN_10646_CHAR
;
49 idx
= (ch
- 0x21 - offset
) * 94 + (ch2
- 0x21 - offset
);
51 return __UNKNOWN_10646_CHAR
;
55 return __gb2312_to_ucs
[idx
] ?: ((*s
) -= 2, __UNKNOWN_10646_CHAR
);
59 extern const char __gb2312_from_ucs4_tab1
[][2];
60 extern const char __gb2312_from_ucs4_tab2
[][2];
61 extern const char __gb2312_from_ucs4_tab3
[][2];
62 extern const char __gb2312_from_ucs4_tab4
[][2];
63 extern const char __gb2312_from_ucs4_tab5
[][2];
64 extern const char __gb2312_from_ucs4_tab6
[][2];
65 extern const char __gb2312_from_ucs4_tab7
[][2];
66 extern const char __gb2312_from_ucs4_tab8
[][2];
67 extern const char __gb2312_from_ucs4_tab9
[][2];
70 ucs4_to_gb2312 (uint32_t wch
, unsigned char *s
, size_t avail
)
72 unsigned int ch
= (unsigned int) wch
;
79 cp
= __gb2312_from_ucs4_tab1
[ch
- 0xa4];
126 case 0x391 ... 0x3c9:
127 cp
= __gb2312_from_ucs4_tab2
[ch
- 0x391];
129 case 0x401 ... 0x451:
130 cp
= __gb2312_from_ucs4_tab3
[ch
- 0x401];
132 case 0x2015 ... 0x203b:
133 cp
= __gb2312_from_ucs4_tab4
[ch
- 0x2015];
135 case 0x2103 ... 0x22a5:
136 cp
= __gb2312_from_ucs4_tab5
[ch
- 0x2103];
141 case 0x2460 ... 0x249b:
142 cp
= __gb2312_from_ucs4_tab6
[ch
- 0x2460];
144 case 0x2500 ... 0x254b:
146 buf
[1] = '\x24' + (ch
% 256);
187 case 0x3000 ... 0x3129:
188 cp
= __gb2312_from_ucs4_tab7
[ch
- 0x3000];
190 case 0x3220 ... 0x3229:
192 buf
[1] = '\x65' + (ch
- 0x3220);
194 case 0x4e00 ... 0x9fa0:
195 cp
= __gb2312_from_ucs4_tab8
[ch
- 0x4e00];
197 case 0xff01 ... 0xff5e:
198 cp
= __gb2312_from_ucs4_tab9
[ch
- 0xff01];
213 return __UNKNOWN_10646_CHAR
;
217 return __UNKNOWN_10646_CHAR
;
219 assert (cp
[1] != '\0');
230 #endif /* gb2312.h */