summaryrefslogtreecommitdiff
path: root/jni/iconv/lib/cp855.h
blob: ddb8bf17d08a17af19e06ee2d9d89419fa419f09 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * 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.
 */

/*
 * CP855
 */

static const unsigned short cp855_2uni[128] = {
  /* 0x80 */
  0x04520x04020x04530x04030x04510x04010x04540x0404,
  0x04550x04050x04560x04060x04570x04070x04580x0408,
  /* 0x90 */
  0x04590x04090x045a0x040a0x045b0x040b0x045c0x040c,
  0x045e0x040e0x045f0x040f0x044e0x042e0x044a0x042a,
  /* 0xa0 */
  0x04300x04100x04310x04110x04460x04260x04340x0414,
  0x04350x04150x04440x04240x04330x04130x00ab0x00bb,
  /* 0xb0 */
  0x25910x25920x25930x25020x25240x04450x04250x0438,
  0x04180x25630x25510x25570x255d0x04390x04190x2510,
  /* 0xc0 */
  0x25140x25340x252c0x251c0x25000x253c0x043a0x041a,
  0x255a0x25540x25690x25660x25600x25500x256c0x00a4,
  /* 0xd0 */
  0x043b0x041b0x043c0x041c0x043d0x041d0x043e0x041e,
  0x043f0x25180x250c0x25880x25840x041f0x044f0x2580,
  /* 0xe0 */
  0x042f0x04400x04200x04410x04210x04420x04220x0443,
  0x04230x04360x04160x04320x04120x044c0x042c0x2116,
  /* 0xf0 */
  0x00ad0x044b0x042b0x04370x04170x04480x04280x044d,
  0x042d0x04490x04290x04470x04270x00a70x25a00x00a0,
};

static int
cp855_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
{
  unsigned char c = *s;
  if (c < 0x80)
    *pwc = (ucs4_t) c;
  else
    *pwc = (ucs4_t) cp855_2uni[c-0x80];
  return 1;
}

static const unsigned char cp855_page00[32] = {
  0xff0x000x000x000xcf0x000x000xfd/* 0xa0-0xa7 */
  0x000x000x000xae0x000xf00x000x00/* 0xa8-0xaf */
  0x000x000x000x000x000x000x000x00/* 0xb0-0xb7 */
  0x000x000x000xaf0x000x000x000x00/* 0xb8-0xbf */
};
static const unsigned char cp855_page04[96] = {
  0x000x850x810x830x870x890x8b0x8d/* 0x00-0x07 */
  0x8f0x910x930x950x970x000x990x9b/* 0x08-0x0f */
  0xa10xa30xec0xad0xa70xa90xea0xf4/* 0x10-0x17 */
  0xb80xbe0xc70xd10xd30xd50xd70xdd/* 0x18-0x1f */
  0xe20xe40xe60xe80xab0xb60xa50xfc/* 0x20-0x27 */
  0xf60xfa0x9f0xf20xee0xf80x9d0xe0/* 0x28-0x2f */
  0xa00xa20xeb0xac0xa60xa80xe90xf3/* 0x30-0x37 */
  0xb70xbd0xc60xd00xd20xd40xd60xd8/* 0x38-0x3f */
  0xe10xe30xe50xe70xaa0xb50xa40xfb/* 0x40-0x47 */
  0xf50xf90x9e0xf10xed0xf70x9c0xde/* 0x48-0x4f */
  0x000x840x800x820x860x880x8a0x8c/* 0x50-0x57 */
  0x8e0x900x920x940x960x000x980x9a/* 0x58-0x5f */
};
static const unsigned char cp855_page25[168] = {
  0xc40x000xb30x000x000x000x000x00/* 0x00-0x07 */
  0x000x000x000x000xda0x000x000x00/* 0x08-0x0f */
  0xbf0x000x000x000xc00x000x000x00/* 0x10-0x17 */
  0xd90x000x000x000xc30x000x000x00/* 0x18-0x1f */
  0x000x000x000x000xb40x000x000x00/* 0x20-0x27 */
  0x000x000x000x000xc20x000x000x00/* 0x28-0x2f */
  0x000x000x000x000xc10x000x000x00/* 0x30-0x37 */
  0x000x000x000x000xc50x000x000x00/* 0x38-0x3f */
  0x000x000x000x000x000x000x000x00/* 0x40-0x47 */
  0x000x000x000x000x000x000x000x00/* 0x48-0x4f */
  0xcd0xba0x000x000xc90x000x000xbb/* 0x50-0x57 */
  0x000x000xc80x000x000xbc0x000x00/* 0x58-0x5f */
  0xcc0x000x000xb90x000x000xcb0x00/* 0x60-0x67 */
  0x000xca0x000x000xce0x000x000x00/* 0x68-0x6f */
  0x000x000x000x000x000x000x000x00/* 0x70-0x77 */
  0x000x000x000x000x000x000x000x00/* 0x78-0x7f */
  0xdf0x000x000x000xdc0x000x000x00/* 0x80-0x87 */
  0xdb0x000x000x000x000x000x000x00/* 0x88-0x8f */
  0x000xb00xb10xb20x000x000x000x00/* 0x90-0x97 */
  0x000x000x000x000x000x000x000x00/* 0x98-0x9f */
  0xfe0x000x000x000x000x000x000x00/* 0xa0-0xa7 */
};

static int
cp855_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
{
  unsigned char c = 0;
  if (wc < 0x0080) {
    *r = wc;
    return 1;
  }
  else if (wc >= 0x00a0 && wc < 0x00c0)
    c = cp855_page00[wc-0x00a0];
  else if (wc >= 0x0400 && wc < 0x0460)
    c = cp855_page04[wc-0x0400];
  else if (wc == 0x2116)
    c = 0xef;
  else if (wc >= 0x2500 && wc < 0x25a8)
    c = cp855_page25[wc-0x2500];
  if (c != 0) {
    *r = c;
    return 1;
  }
  return RET_ILUNI;
}