1 /* Access functions for JISX0208 conversion.
2 Copyright (C) 1997-2022 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/>. */
25 /* Struct for table with indices in UCS mapping table. */
26 struct jisx0208_ucs_idx
34 /* Conversion table. */
35 extern const uint16_t __jis0208_to_ucs
[];
37 #define JIS0208_LAT1_MIN 0xa2
38 #define JIS0208_LAT1_MAX 0xf7
39 extern const char __jisx0208_from_ucs4_lat1
[JIS0208_LAT1_MAX
+ 1
40 - JIS0208_LAT1_MIN
][2];
41 extern const char __jisx0208_from_ucs4_greek
[0xc1][2];
42 extern const struct jisx0208_ucs_idx __jisx0208_from_ucs_idx
[];
43 extern const char __jisx0208_from_ucs_tab
[][2];
46 static inline uint32_t
47 __attribute ((always_inline
))
48 jisx0208_to_ucs4 (const unsigned char **s
, size_t avail
, unsigned char offset
)
50 unsigned char ch
= *(*s
);
54 if (ch
< offset
|| (ch
- offset
) <= 0x20)
55 return __UNKNOWN_10646_CHAR
;
61 if (ch2
< offset
|| (ch2
- offset
) <= 0x20 || (ch2
- offset
) >= 0x7f)
62 return __UNKNOWN_10646_CHAR
;
64 idx
= (ch
- 0x21 - offset
) * 94 + (ch2
- 0x21 - offset
);
66 return __UNKNOWN_10646_CHAR
;
70 return __jis0208_to_ucs
[idx
] ?: ((*s
) -= 2, __UNKNOWN_10646_CHAR
);
75 __attribute ((always_inline
))
76 ucs4_to_jisx0208 (uint32_t wch
, unsigned char *s
, size_t avail
)
78 unsigned int ch
= (unsigned int) wch
;
84 if (ch
>= JIS0208_LAT1_MIN
&& ch
<= JIS0208_LAT1_MAX
)
85 cp
= __jisx0208_from_ucs4_lat1
[ch
- JIS0208_LAT1_MIN
];
86 else if (ch
>= 0x391 && ch
<= 0x451)
87 cp
= __jisx0208_from_ucs4_greek
[ch
- 0x391];
90 const struct jisx0208_ucs_idx
*rp
= __jisx0208_from_ucs_idx
;
93 return __UNKNOWN_10646_CHAR
;
97 cp
= __jisx0208_from_ucs_tab
[rp
->idx
+ ch
- rp
->start
];
99 return __UNKNOWN_10646_CHAR
;
103 return __UNKNOWN_10646_CHAR
;
111 #endif /* jis0208.h */