2 * Copyright (C) 1999-2001, 2005, 2016 Free Software Foundation, Inc.
3 * This file is part of the GNU LIBICONV Library.
5 * The GNU LIBICONV Library is free software; you can redistribute it
6 * and/or modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * The GNU LIBICONV Library is distributed in the hope that it will be
11 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
17 * If not, see <http://www.gnu.org/licenses/>.
25 euc_jp_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, size_t n)
28 /* Code set 0 (ASCII or JIS X 0201-1976 Roman) */
30 return ascii_mbtowc(conv,pwc,s,n);
31 /* Code set 1 (JIS X 0208) */
32 if (c >= 0xa1 && c < 0xff) {
36 unsigned char c2 = s[1];
37 if (c2 >= 0xa1 && c2 < 0xff) {
39 buf[0] = c-0x80; buf[1] = c2-0x80;
40 return jisx0208_mbtowc(conv,pwc,buf,2);
44 /* User-defined range. See
45 * Ken Lunde's "CJKV Information Processing", table 4-66, p. 206. */
46 unsigned char c2 = s[1];
47 if (c2 >= 0xa1 && c2 < 0xff) {
48 *pwc = 0xe000 + 94*(c-0xf5) + (c2-0xa1);
54 /* Code set 2 (half-width katakana) */
59 unsigned char c2 = s[1];
60 if (c2 >= 0xa1 && c2 < 0xe0) {
61 int ret = jisx0201_mbtowc(conv,pwc,s+1,n-1);
64 if (ret != 1) abort();
70 /* Code set 3 (JIS X 0212-1990) */
75 unsigned char c2 = s[1];
76 if (c2 >= 0xa1 && c2 < 0xff) {
80 unsigned char c3 = s[2];
81 if (c3 >= 0xa1 && c3 < 0xff) {
84 buf[0] = c2-0x80; buf[1] = c3-0x80;
85 ret = jisx0212_mbtowc(conv,pwc,buf,2);
88 if (ret != 2) abort();
93 /* User-defined range. See
94 * Ken Lunde's "CJKV Information Processing", table 4-66, p. 206. */
95 unsigned char c3 = s[2];
96 if (c3 >= 0xa1 && c3 < 0xff) {
97 *pwc = 0xe3ac + 94*(c2-0xf5) + (c3-0xa1);
110 euc_jp_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, size_t n)
112 unsigned char buf[2];
115 /* Code set 0 (ASCII or JIS X 0201-1976 Roman) */
116 ret = ascii_wctomb(conv,r,wc,n);
117 if (ret != RET_ILUNI)
120 /* Code set 1 (JIS X 0208) */
121 ret = jisx0208_wctomb(conv,buf,wc,2);
122 if (ret != RET_ILUNI) {
123 if (ret != 2) abort();
131 /* Code set 2 (half-width katakana) */
132 ret = jisx0201_wctomb(conv,buf,wc,1);
133 if (ret != RET_ILUNI && buf[0] >= 0x80) {
134 if (ret != 1) abort();
142 /* Code set 3 (JIS X 0212-1990) */
143 ret = jisx0212_wctomb(conv,buf,wc,2);
144 if (ret != RET_ILUNI) {
145 if (ret != 2) abort();
154 /* Extra compatibility with Shift_JIS. */
164 /* User-defined range. See
165 * Ken Lunde's "CJKV Information Processing", table 4-66, p. 206. */
166 if (wc >= 0xe000 && wc < 0xe758) {
168 unsigned char c1, c2;
171 c1 = (unsigned int) (wc - 0xe000) / 94;
172 c2 = (unsigned int) (wc - 0xe000) % 94;
177 unsigned char c1, c2;
180 c1 = (unsigned int) (wc - 0xe3ac) / 94;
181 c2 = (unsigned int) (wc - 0xe3ac) % 94;