summaryrefslogtreecommitdiff
path: root/jni/iconv/lib/cp874.h
blob: 6374dd7d05c6e1cf161db4a80d17848e493822e4 (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
/*
 * 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.
 */

/*
 * CP874
 */

static const unsigned short cp874_2uni[128] = {
  /* 0x80 */
  0x20ac0xfffd0xfffd0xfffd0xfffd0x20260xfffd0xfffd,
  0xfffd0xfffd0xfffd0xfffd0xfffd0xfffd0xfffd0xfffd,
  /* 0x90 */
  0xfffd0x20180x20190x201c0x201d0x20220x20130x2014,
  0xfffd0xfffd0xfffd0xfffd0xfffd0xfffd0xfffd0xfffd,
  /* 0xa0 */
  0x00a00x0e010x0e020x0e030x0e040x0e050x0e060x0e07,
  0x0e080x0e090x0e0a0x0e0b0x0e0c0x0e0d0x0e0e0x0e0f,
  /* 0xb0 */
  0x0e100x0e110x0e120x0e130x0e140x0e150x0e160x0e17,
  0x0e180x0e190x0e1a0x0e1b0x0e1c0x0e1d0x0e1e0x0e1f,
  /* 0xc0 */
  0x0e200x0e210x0e220x0e230x0e240x0e250x0e260x0e27,
  0x0e280x0e290x0e2a0x0e2b0x0e2c0x0e2d0x0e2e0x0e2f,
  /* 0xd0 */
  0x0e300x0e310x0e320x0e330x0e340x0e350x0e360x0e37,
  0x0e380x0e390x0e3a0xfffd0xfffd0xfffd0xfffd0x0e3f,
  /* 0xe0 */
  0x0e400x0e410x0e420x0e430x0e440x0e450x0e460x0e47,
  0x0e480x0e490x0e4a0x0e4b0x0e4c0x0e4d0x0e4e0x0e4f,
  /* 0xf0 */
  0x0e500x0e510x0e520x0e530x0e540x0e550x0e560x0e57,
  0x0e580x0e590x0e5a0x0e5b0xfffd0xfffd0xfffd0xfffd,
};

static int
cp874_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
{
  unsigned char c = *s;
  if (c < 0x80) {
    *pwc = (ucs4_t) c;
    return 1;
  }
  else {
    unsigned short wc = cp874_2uni[c-0x80];
    if (wc != 0xfffd) {
      *pwc = (ucs4_t) wc;
      return 1;
    }
  }
  return RET_ILSEQ;
}

static const unsigned char cp874_page0e[96] = {
  0x000xa10xa20xa30xa40xa50xa60xa7/* 0x00-0x07 */
  0xa80xa90xaa0xab0xac0xad0xae0xaf/* 0x08-0x0f */
  0xb00xb10xb20xb30xb40xb50xb60xb7/* 0x10-0x17 */
  0xb80xb90xba0xbb0xbc0xbd0xbe0xbf/* 0x18-0x1f */
  0xc00xc10xc20xc30xc40xc50xc60xc7/* 0x20-0x27 */
  0xc80xc90xca0xcb0xcc0xcd0xce0xcf/* 0x28-0x2f */
  0xd00xd10xd20xd30xd40xd50xd60xd7/* 0x30-0x37 */
  0xd80xd90xda0x000x000x000x000xdf/* 0x38-0x3f */
  0xe00xe10xe20xe30xe40xe50xe60xe7/* 0x40-0x47 */
  0xe80xe90xea0xeb0xec0xed0xee0xef/* 0x48-0x4f */
  0xf00xf10xf20xf30xf40xf50xf60xf7/* 0x50-0x57 */
  0xf80xf90xfa0xfb0x000x000x000x00/* 0x58-0x5f */
};
static const unsigned char cp874_page20[24] = {
  0x000x000x000x960x970x000x000x00/* 0x10-0x17 */
  0x910x920x000x000x930x940x000x00/* 0x18-0x1f */
  0x000x000x950x000x000x000x850x00/* 0x20-0x27 */
};

static int
cp874_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)
    c = 0xa0;
  else if (wc >= 0x0e00 && wc < 0x0e60)
    c = cp874_page0e[wc-0x0e00];
  else if (wc >= 0x2010 && wc < 0x2028)
    c = cp874_page20[wc-0x2010];
  else if (wc == 0x20ac)
    c = 0x80;
  if (c != 0) {
    *r = c;
    return 1;
  }
  return RET_ILUNI;
}