]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/jis0212.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / iconvdata / jis0212.h
CommitLineData
04be94a8 1/* Access functions for JISX0212 conversion.
04277e02 2 Copyright (C) 1997-2019 Free Software Foundation, Inc.
04be94a8
UD
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
04be94a8
UD
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
41bdb6e2 14 Lesser General Public License for more details.
04be94a8 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
04be94a8
UD
19
20#ifndef _JIS0212_H
21#define _JIS0212_H 1
22
085a4412 23#include <assert.h>
04be94a8 24#include <gconv.h>
2aea1d79 25#include <stdint.h>
04be94a8
UD
26
27
28/* Struct for table with indeces in mapping table. */
29struct jisx0212_idx
30{
31 uint16_t start;
32 uint16_t end;
33 uint16_t idx;
34};
35
36/* Conversion table. */
8619129f
UD
37extern const struct jisx0212_idx __jisx0212_to_ucs_idx[];
38extern const uint16_t __jisx0212_to_ucs[];
04be94a8 39
8619129f
UD
40extern const struct jisx0212_idx __jisx0212_from_ucs_idx[];
41extern const char __jisx0212_from_ucs[][2];
04be94a8
UD
42
43
9b26f5c4 44static inline uint32_t
dd9423a6 45__attribute ((always_inline))
8619129f 46jisx0212_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
04be94a8 47{
8619129f 48 const struct jisx0212_idx *rp = __jisx0212_to_ucs_idx;
04be94a8
UD
49 unsigned char ch = *(*s);
50 unsigned char ch2;
8619129f 51 uint32_t wch = 0;
04be94a8
UD
52 int idx;
53
9b26f5c4 54 if (ch < offset || (ch - offset) < 0x22 || (ch - offset) > 0x6d)
d64b6ad0 55 return __UNKNOWN_10646_CHAR;
04be94a8
UD
56
57 if (avail < 2)
58 return 0;
59
60 ch2 = (*s)[1];
2b474353 61 if (ch2 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
d64b6ad0 62 return __UNKNOWN_10646_CHAR;
04be94a8 63
9b26f5c4 64 idx = (ch - offset - 0x21) * 94 + (ch2 - offset - 0x21);
04be94a8 65
8619129f 66 while (idx > rp->end)
04be94a8 67 ++rp;
8619129f
UD
68 if (idx >= rp->start)
69 wch = __jisx0212_to_ucs[rp->idx + idx - rp->start];
04be94a8
UD
70
71 if (wch != L'\0')
72 (*s) += 2;
73 else
d64b6ad0 74 wch = __UNKNOWN_10646_CHAR;
04be94a8
UD
75
76 return wch;
77}
78
79
80static inline size_t
dd9423a6 81__attribute ((always_inline))
085a4412 82ucs4_to_jisx0212 (uint32_t wch, unsigned char *s, size_t avail)
04be94a8 83{
8619129f 84 const struct jisx0212_idx *rp = __jisx0212_from_ucs_idx;
04be94a8 85 unsigned int ch = (unsigned int) wch;
8619129f 86 const char *cp;
04be94a8 87
8619129f 88 if (ch >= 0xffff)
d64b6ad0 89 return __UNKNOWN_10646_CHAR;
04be94a8
UD
90 while (ch > rp->end)
91 ++rp;
92 if (ch >= rp->start)
8619129f
UD
93 cp = __jisx0212_from_ucs[rp->idx + ch - rp->start];
94 else
d64b6ad0 95 return __UNKNOWN_10646_CHAR;
04be94a8 96
8619129f 97 if (cp[0] == '\0')
d64b6ad0 98 return __UNKNOWN_10646_CHAR;
04be94a8 99
2b474353 100 s[0] = cp[0];
085a4412
UD
101 assert (cp[1] != '\0');
102 if (avail < 2)
103 return 0;
04be94a8 104
085a4412 105 s[1] = cp[1];
04be94a8
UD
106 return 2;
107}
108
109#endif /* jis0212.h */