1 /* Access functions for JISX0208 conversion.
2 Copyright (C) 1997,1998,1999,2000,2003,2005,2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 /* Struct for table with indeces in UCS mapping table. */
29 struct jisx0208_ucs_idx
37 /* Conversion table. */
38 extern const uint16_t __jis0208_to_ucs
[];
40 #define JIS0208_LAT1_MIN 0xa2
41 #define JIS0208_LAT1_MAX 0xf7
42 extern const char __jisx0208_from_ucs4_lat1
[JIS0208_LAT1_MAX
+ 1
43 - JIS0208_LAT1_MIN
][2];
44 extern const char __jisx0208_from_ucs4_greek
[0xc1][2];
45 extern const struct jisx0208_ucs_idx __jisx0208_from_ucs_idx
[];
46 extern const char __jisx0208_from_ucs_tab
[][2];
49 static inline uint32_t
50 __attribute ((always_inline
))
51 jisx0208_to_ucs4 (const unsigned char **s
, size_t avail
, unsigned char offset
)
53 unsigned char ch
= *(*s
);
57 if (ch
< offset
|| (ch
- offset
) <= 0x20)
58 return __UNKNOWN_10646_CHAR
;
64 if (ch2
< offset
|| (ch2
- offset
) <= 0x20 || (ch2
- offset
) >= 0x7f)
65 return __UNKNOWN_10646_CHAR
;
67 idx
= (ch
- 0x21 - offset
) * 94 + (ch2
- 0x21 - offset
);
69 return __UNKNOWN_10646_CHAR
;
73 return __jis0208_to_ucs
[idx
] ?: ((*s
) -= 2, __UNKNOWN_10646_CHAR
);
78 __attribute ((always_inline
))
79 ucs4_to_jisx0208 (uint32_t wch
, unsigned char *s
, size_t avail
)
81 unsigned int ch
= (unsigned int) wch
;
87 if (ch
>= JIS0208_LAT1_MIN
&& ch
<= JIS0208_LAT1_MAX
)
88 cp
= __jisx0208_from_ucs4_lat1
[ch
- JIS0208_LAT1_MIN
];
89 else if (ch
>= 0x391 && ch
<= 0x451)
90 cp
= __jisx0208_from_ucs4_greek
[ch
- 0x391];
93 const struct jisx0208_ucs_idx
*rp
= __jisx0208_from_ucs_idx
;
96 return __UNKNOWN_10646_CHAR
;
100 cp
= __jisx0208_from_ucs_tab
[rp
->idx
+ ch
- rp
->start
];
102 return __UNKNOWN_10646_CHAR
;
106 return __UNKNOWN_10646_CHAR
;
114 #endif /* jis0208.h */