]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/jis0212.h
Add aliases unicode and unicodebig for Java. Add definitions for unicodelittle imple...
[thirdparty/glibc.git] / iconvdata / jis0212.h
CommitLineData
04be94a8 1/* Access functions for JISX0212 conversion.
2b474353 2 Copyright (C) 1997, 1998 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
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21#ifndef _JIS0212_H
22#define _JIS0212_H 1
23
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
44static inline wchar_t
8619129f 45jisx0212_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
04be94a8 46{
8619129f 47 const struct jisx0212_idx *rp = __jisx0212_to_ucs_idx;
04be94a8
UD
48 unsigned char ch = *(*s);
49 unsigned char ch2;
8619129f 50 uint32_t wch = 0;
04be94a8
UD
51 int idx;
52
2b474353 53 if (ch < offset || (ch - offset) <= 0x6d || (ch - offset) > 0xea)
04be94a8
UD
54 return UNKNOWN_10646_CHAR;
55
56 if (avail < 2)
57 return 0;
58
59 ch2 = (*s)[1];
2b474353 60 if (ch2 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
04be94a8
UD
61 return UNKNOWN_10646_CHAR;
62
2b474353 63 idx = (ch - 0x21 - offset) * 94 + (ch2 - 0x21 - offset);
04be94a8 64
8619129f 65 while (idx > rp->end)
04be94a8 66 ++rp;
8619129f
UD
67 if (idx >= rp->start)
68 wch = __jisx0212_to_ucs[rp->idx + idx - rp->start];
04be94a8
UD
69
70 if (wch != L'\0')
71 (*s) += 2;
72 else
73 wch = UNKNOWN_10646_CHAR;
74
75 return wch;
76}
77
78
79static inline size_t
2b474353 80ucs4_to_jisx0212 (wchar_t wch, char *s, size_t avail)
04be94a8 81{
8619129f 82 const struct jisx0212_idx *rp = __jisx0212_from_ucs_idx;
04be94a8 83 unsigned int ch = (unsigned int) wch;
8619129f 84 const char *cp;
04be94a8 85
8619129f
UD
86 if (ch >= 0xffff)
87 return UNKNOWN_10646_CHAR;
04be94a8
UD
88 while (ch > rp->end)
89 ++rp;
90 if (ch >= rp->start)
8619129f
UD
91 cp = __jisx0212_from_ucs[rp->idx + ch - rp->start];
92 else
93 return UNKNOWN_10646_CHAR;
04be94a8 94
8619129f 95 if (cp[0] == '\0')
04be94a8
UD
96 return UNKNOWN_10646_CHAR;
97
2b474353 98 s[0] = cp[0];
04be94a8
UD
99 if (cp[1] != '\0')
100 {
101 if (avail < 2)
102 return 0;
103
2b474353 104 s[1] = cp[1];
04be94a8 105 }
04be94a8
UD
106
107 return 2;
108}
109
110#endif /* jis0212.h */