summaryrefslogtreecommitdiff
path: root/jni/iconv/lib/cp1253.h
blob: 020f0d6e05715fa2c62dc45256ebc61f45c6fe11 (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
/*
 * 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.
 */

/*
 * CP1253
 */

static const unsigned short cp1253_2uni[128] = {
  /* 0x80 */
  0x20ac0xfffd0x201a0x01920x201e0x20260x20200x2021,
  0xfffd0x20300xfffd0x20390xfffd0xfffd0xfffd0xfffd,
  /* 0x90 */
  0xfffd0x20180x20190x201c0x201d0x20220x20130x2014,
  0xfffd0x21220xfffd0x203a0xfffd0xfffd0xfffd0xfffd,
  /* 0xa0 */
  0x00a00x03850x03860x00a30x00a40x00a50x00a60x00a7,
  0x00a80x00a90xfffd0x00ab0x00ac0x00ad0x00ae0x2015,
  /* 0xb0 */
  0x00b00x00b10x00b20x00b30x03840x00b50x00b60x00b7,
  0x03880x03890x038a0x00bb0x038c0x00bd0x038e0x038f,
  /* 0xc0 */
  0x03900x03910x03920x03930x03940x03950x03960x0397,
  0x03980x03990x039a0x039b0x039c0x039d0x039e0x039f,
  /* 0xd0 */
  0x03a00x03a10xfffd0x03a30x03a40x03a50x03a60x03a7,
  0x03a80x03a90x03aa0x03ab0x03ac0x03ad0x03ae0x03af,
  /* 0xe0 */
  0x03b00x03b10x03b20x03b30x03b40x03b50x03b60x03b7,
  0x03b80x03b90x03ba0x03bb0x03bc0x03bd0x03be0x03bf,
  /* 0xf0 */
  0x03c00x03c10x03c20x03c30x03c40x03c50x03c60x03c7,
  0x03c80x03c90x03ca0x03cb0x03cc0x03cd0x03ce0xfffd,
};

static int
cp1253_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 = cp1253_2uni[c-0x80];
    if (wc != 0xfffd) {
      *pwc = (ucs4_t) wc;
      return 1;
    }
  }
  return RET_ILSEQ;
}

static const unsigned char cp1253_page00[32] = {
  0xa00x000x000xa30xa40xa50xa60xa7/* 0xa0-0xa7 */
  0xa80xa90x000xab0xac0xad0xae0x00/* 0xa8-0xaf */
  0xb00xb10xb20xb30x000xb50xb60xb7/* 0xb0-0xb7 */
  0x000x000x000xbb0x000xbd0x000x00/* 0xb8-0xbf */
};
static const unsigned char cp1253_page03[80] = {
  0x000x000x000x000xb40xa10xa20x00/* 0x80-0x87 */
  0xb80xb90xba0x000xbc0x000xbe0xbf/* 0x88-0x8f */
  0xc00xc10xc20xc30xc40xc50xc60xc7/* 0x90-0x97 */
  0xc80xc90xca0xcb0xcc0xcd0xce0xcf/* 0x98-0x9f */
  0xd00xd10x000xd30xd40xd50xd60xd7/* 0xa0-0xa7 */
  0xd80xd90xda0xdb0xdc0xdd0xde0xdf/* 0xa8-0xaf */
  0xe00xe10xe20xe30xe40xe50xe60xe7/* 0xb0-0xb7 */
  0xe80xe90xea0xeb0xec0xed0xee0xef/* 0xb8-0xbf */
  0xf00xf10xf20xf30xf40xf50xf60xf7/* 0xc0-0xc7 */
  0xf80xf90xfa0xfb0xfc0xfd0xfe0x00/* 0xc8-0xcf */
};
static const unsigned char cp1253_page20[48] = {
  0x000x000x000x960x970xaf0x000x00/* 0x10-0x17 */
  0x910x920x820x000x930x940x840x00/* 0x18-0x1f */
  0x860x870x950x000x000x000x850x00/* 0x20-0x27 */
  0x000x000x000x000x000x000x000x00/* 0x28-0x2f */
  0x890x000x000x000x000x000x000x00/* 0x30-0x37 */
  0x000x8b0x9b0x000x000x000x000x00/* 0x38-0x3f */
};

static int
cp1253_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 = cp1253_page00[wc-0x00a0];
  else if (wc == 0x0192)
    c = 0x83;
  else if (wc >= 0x0380 && wc < 0x03d0)
    c = cp1253_page03[wc-0x0380];
  else if (wc >= 0x2010 && wc < 0x2040)
    c = cp1253_page20[wc-0x2010];
  else if (wc == 0x20ac)
    c = 0x80;
  else if (wc == 0x2122)
    c = 0x99;
  if (c != 0) {
    *r = c;
    return 1;
  }
  return RET_ILUNI;
}