]> git.ipfire.org Git - thirdparty/glibc.git/blob - iconvdata/jisx0213.h
5632e523bc5ba96cd8371bde9848d6dd92b2e3da
[thirdparty/glibc.git] / iconvdata / jisx0213.h
1 /* Functions for JISX0213 conversion.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Bruno Haible <bruno@clisp.org>, 2002.
5
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.
10
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.
15
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
19 02111-1307 USA. */
20
21 #ifndef _JISX0213_H
22 #define _JISX0213_H 1
23
24 #include <stdint.h>
25
26 extern const uint16_t __jisx0213_to_ucs_combining[][2];
27 extern const uint16_t __jisx0213_to_ucs_main[120 * 94];
28 extern const uint32_t __jisx0213_to_ucs_pagestart[];
29 extern const int16_t __jisx0213_from_ucs_level1[2715];
30 extern const uint16_t __jisx0213_from_ucs_level2[];
31
32 #define NELEMS(arr) (sizeof (arr) / sizeof (arr[0]))
33
34 static inline uint32_t
35 jisx0213_to_ucs4 (unsigned int row, unsigned int col)
36 {
37 uint32_t val;
38
39 if (row >= 0x121 && row <= 0x17e)
40 row -= 289;
41 else if (row == 0x221)
42 row -= 451;
43 else if (row >= 0x223 && row <= 0x225)
44 row -= 452;
45 else if (row == 0x228)
46 row -= 454;
47 else if (row >= 0x22c && row <= 0x22f)
48 row -= 457;
49 else if (row >= 0x26e && row <= 0x27e)
50 row -= 519;
51 else
52 return 0x0000;
53
54 if (col >= 0x21 && col <= 0x7e)
55 col -= 0x21;
56 else
57 return 0x0000;
58
59 val = __jisx0213_to_ucs_main[row * 94 + col];
60 val = __jisx0213_to_ucs_pagestart[val >> 8] + (val & 0xff);
61 if (val == 0xfffd)
62 val = 0x0000;
63 return val;
64 }
65
66 static inline uint16_t
67 ucs4_to_jisx0213 (uint32_t ucs)
68 {
69 if (ucs < NELEMS (__jisx0213_from_ucs_level1) << 6)
70 {
71 int index1 = __jisx0213_from_ucs_level1[ucs >> 6];
72 if (index1 >= 0)
73 return __jisx0213_from_ucs_level2[(index1 << 6) + (ucs & 0x3f)];
74 }
75 return 0x0000;
76 }
77
78 #endif /* _JISX0213_H */