PowerPC: Update NEWS with ppc64 STT_GNU_IFUNC support
[glibc.git] / iconvdata / jis0208.h
blob9e6db71e3025a0eb031ec00e678cbd62633f2237
1 /* Access functions for JISX0208 conversion.
2 Copyright (C) 1997-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
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, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _JIS0208_H
21 #define _JIS0208_H 1
23 #include <gconv.h>
24 #include <stdint.h>
26 /* Struct for table with indeces in UCS mapping table. */
27 struct jisx0208_ucs_idx
29 uint16_t start;
30 uint16_t end;
31 uint16_t idx;
35 /* Conversion table. */
36 extern const uint16_t __jis0208_to_ucs[];
38 #define JIS0208_LAT1_MIN 0xa2
39 #define JIS0208_LAT1_MAX 0xf7
40 extern const char __jisx0208_from_ucs4_lat1[JIS0208_LAT1_MAX + 1
41 - JIS0208_LAT1_MIN][2];
42 extern const char __jisx0208_from_ucs4_greek[0xc1][2];
43 extern const struct jisx0208_ucs_idx __jisx0208_from_ucs_idx[];
44 extern const char __jisx0208_from_ucs_tab[][2];
47 static inline uint32_t
48 __attribute ((always_inline))
49 jisx0208_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
51 unsigned char ch = *(*s);
52 unsigned char ch2;
53 int idx;
55 if (ch < offset || (ch - offset) <= 0x20)
56 return __UNKNOWN_10646_CHAR;
58 if (avail < 2)
59 return 0;
61 ch2 = (*s)[1];
62 if (ch2 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
63 return __UNKNOWN_10646_CHAR;
65 idx = (ch - 0x21 - offset) * 94 + (ch2 - 0x21 - offset);
66 if (idx >= 0x1e80)
67 return __UNKNOWN_10646_CHAR;
69 (*s) += 2;
71 return __jis0208_to_ucs[idx] ?: ((*s) -= 2, __UNKNOWN_10646_CHAR);
75 static inline size_t
76 __attribute ((always_inline))
77 ucs4_to_jisx0208 (uint32_t wch, unsigned char *s, size_t avail)
79 unsigned int ch = (unsigned int) wch;
80 const char *cp;
82 if (avail < 2)
83 return 0;
85 if (ch >= JIS0208_LAT1_MIN && ch <= JIS0208_LAT1_MAX)
86 cp = __jisx0208_from_ucs4_lat1[ch - JIS0208_LAT1_MIN];
87 else if (ch >= 0x391 && ch <= 0x451)
88 cp = __jisx0208_from_ucs4_greek[ch - 0x391];
89 else
91 const struct jisx0208_ucs_idx *rp = __jisx0208_from_ucs_idx;
93 if (ch >= 0xffff)
94 return __UNKNOWN_10646_CHAR;
95 while (ch > rp->end)
96 ++rp;
97 if (ch >= rp->start)
98 cp = __jisx0208_from_ucs_tab[rp->idx + ch - rp->start];
99 else
100 return __UNKNOWN_10646_CHAR;
103 if (cp[0] == '\0')
104 return __UNKNOWN_10646_CHAR;
106 s[0] = cp[0];
107 s[1] = cp[1];
109 return 2;
112 #endif /* jis0208.h */