summaryrefslogtreecommitdiff
path: root/jni/iconv/lib/cp936ext.h
blob: db1817b701ec9f42d1b9a7cc5bd7809a980dbafa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 1999-2001 Free Software Foundation, Inc.
 * This file is part of the GNU LIBICONV Library.
 *
 * The GNU LIBICONV Library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * The GNU LIBICONV Library is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
 * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA.
 */

/*
 * CP936 extensions
 */

static const unsigned short cp936ext_2uni_pagea6[181-159] = {
  /* 0xa6 */
                                                          0xfe35,
  0xfe360xfe390xfe3a0xfe3f0xfe400xfe3d0xfe3e0xfe41,
  0xfe420xfe430xfe440xfffd0xfffd0xfe3b0xfe3c0xfe37,
  0xfe380xfe310xfffd0xfe330xfe34,
};
static const unsigned short cp936ext_2uni_pagea8[128-122] = {
  /* 0xa8 */
                  0x02510xfffd0x01440x01480xfffd0x0261,
};

static int
cp936ext_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
{
  unsigned char c1 = s[0];
  if ((c1 == 0xa6) || (c1 == 0xa8)) {
    if (n >= 2) {
      unsigned char c2 = s[1];
      if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0x80 && c2 < 0xff)) {
        unsigned int i = 190 * (c1 - 0x81) + (c2 - (c2 >= 0x80 ? 0x41 : 0x40));
        unsigned short wc = 0xfffd;
        if (i < 7410) {
          if (i >= 7189 && i < 7211)
            wc = cp936ext_2uni_pagea6[i-7189];
        } else {
          if (i >= 7532 && i < 7538)
            wc = cp936ext_2uni_pagea8[i-7532];
        }
        if (wc != 0xfffd) {
          *pwc = (ucs4_t) wc;
          return 2;
        }
      }
      return RET_ILSEQ;
    }
    return RET_TOOFEW(0);
  }
  return RET_ILSEQ;
}

static const unsigned short cp936ext_page01[16] = {
  0x00000x00000x00000x00000xa8bd0x00000x00000x0000/*0x40-0x47*/
  0xa8be0x00000x00000x00000x00000x00000x00000x0000/*0x48-0x4f*/
};
static const unsigned short cp936ext_page02[24] = {
  0x00000xa8bb0x00000x00000x00000x00000x00000x0000/*0x50-0x57*/
  0x00000x00000x00000x00000x00000x00000x00000x0000/*0x58-0x5f*/
  0x00000xa8c00x00000x00000x00000x00000x00000x0000/*0x60-0x67*/
};
static const unsigned short cp936ext_pagefe[24] = {
  0x00000xa6f20x00000xa6f40xa6f50xa6e00xa6e10xa6f0/*0x30-0x37*/
  0xa6f10xa6e20xa6e30xa6ee0xa6ef0xa6e60xa6e70xa6e4/*0x38-0x3f*/
  0xa6e50xa6e80xa6e90xa6ea0xa6eb0x00000x00000x0000/*0x40-0x47*/
};

static int
cp936ext_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
{
  if (n >= 2) {
    unsigned short c = 0;
    if (wc >= 0x0140 && wc < 0x0150)
      c = cp936ext_page01[wc-0x0140];
    else if (wc >= 0x0250 && wc < 0x0268)
      c = cp936ext_page02[wc-0x0250];
    else if (wc >= 0xfe30 && wc < 0xfe48)
      c = cp936ext_pagefe[wc-0xfe30];
    if (c != 0) {
      r[0] = (c >> 8); r[1] = (c & 0xff);
      return 2;
    }
    return RET_ILUNI;
  }
  return RET_TOOSMALL;
}