1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qisciicodec_p.h"
36
\brief The QIsciiCodec class provides conversion to and from the ISCII encoding.
47
static const Codecs codecs [] = {
48
{ "Iscii-Dev", 0x900 },
49
{ "Iscii-Bng", 0x980 },
50
{ "Iscii-Pnj", 0xa00 },
51
{ "Iscii-Gjr", 0xa80 },
52
{ "Iscii-Ori", 0xb00 },
53
{ "Iscii-Tml", 0xb80 },
54
{ "Iscii-Tlg", 0xc00 },
55
{ "Iscii-Knd", 0xc80 },
56
{ "Iscii-Mlm", 0xd00 }
59
QIsciiCodec::~QIsciiCodec()
63
QByteArray QIsciiCodec::name() const
65
return codecs[idx].name;
68
int QIsciiCodec::mibEnum() const
70
/* There is no MIBEnum for Iscii */
77
/* iscii range from 0xa0 - 0xff */
78
static const uchar iscii_to_uni_table[0x60] = {
79
0x00, 0x01, 0x02, 0x03,
80
0x05, 0x06, 0x07, 0x08,
81
0x09, 0x0a, 0x0b, 0x0e,
82
0x0f, 0x20, 0x0d, 0x12,
84
0x13, 0x14, 0x11, 0x15,
85
0x16, 0x17, 0x18, 0x19,
86
0x1a, 0x1b, 0x1c, 0x1d,
87
0x1e, 0x1f, 0x20, 0x21,
89
0x22, 0x23, 0x24, 0x25,
90
0x26, 0x27, 0x28, 0x29,
91
0x2a, 0x2b, 0x2c, 0x2d,
92
0x2e, 0x2f, 0x5f, 0x30,
94
0x31, 0x32, 0x33, 0x34,
95
0x35, 0x36, 0x37, 0x38,
96
0x39, INV, 0x3e, 0x3f,
97
0x40, 0x41, 0x42, 0x43,
99
0x46, 0x47, 0x48, 0x45,
100
0x4a, 0x4b, 0x4c, 0x49,
101
0x4d, 0x3c, 0x64, 0x00,
102
0x00, 0x00, 0x00, 0x00,
104
0x00, 0x66, 0x67, 0x68,
105
0x69, 0x6a, 0x6b, 0x6c,
106
0x6d, 0x6e, 0x6f, 0x00,
107
0x00, 0x00, 0x00, 0x00
110
static const uchar uni_to_iscii_table[0x80] = {
111
0x00, 0xa1, 0xa2, 0xa3,
112
0x00, 0xa4, 0xa5, 0xa6,
113
0xa7, 0xa8, 0xa9, 0xaa,
114
0x00, 0xae, 0xab, 0xac,
116
0xad, 0xb2, 0xaf, 0xb0,
117
0xb1, 0xb3, 0xb4, 0xb5,
118
0xb6, 0xb7, 0xb8, 0xb9,
119
0xba, 0xbb, 0xbc, 0xbd,
121
0xbe, 0xbf, 0xc0, 0xc1,
122
0xc2, 0xc3, 0xc4, 0xc5,
123
0xc6, 0xc7, 0xc8, 0xc9,
124
0xca, 0xcb, 0xcc, 0xcd,
126
0xcf, 0xd0, 0xd1, 0xd2,
127
0xd3, 0xd4, 0xd5, 0xd6,
128
0xd7, 0xd8, 0x00, 0x00,
129
0xe9, 0x00, 0xda, 0xdb,
131
0xdc, 0xdd, 0xde, 0xdf,
132
0x00, 0xe3, 0xe0, 0xe1,
133
0xe2, 0xe7, 0xe4, 0xe5,
134
0xe6, 0xe8, 0x00, 0x00,
136
0x00, 0x00, 0x00, 0x00,
137
0x00, 0x00, 0x00, 0x00,
138
0x01, 0x02, 0x03, 0x04, // decomposable into the uc codes listed here + nukta
139
0x05, 0x06, 0x07, 0xce,
141
0x00, 0x00, 0x00, 0x00,
142
0xea, 0x08, 0xf1, 0xf2,
143
0xf3, 0xf4, 0xf5, 0xf6,
144
0xf7, 0xf8, 0xf9, 0xfa,
146
0x00, 0x00, 0x00, 0x00,
147
0x00, 0x00, 0x00, 0x00,
148
0x00, 0x00, 0x00, 0x00,
149
0x00, 0x00, 0x00, 0x00
152
static const uchar uni_to_iscii_pairs[] = {
165
QByteArray QIsciiCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
167
char replacement = '?';
170
if (state->flags & ConvertInvalidToNull)
172
halant = state->state_data[0];
177
result.resize(2*len); //worst case
179
uchar *ch = (uchar *)result.data();
181
int base = codecs[idx].base;
183
for (int i =0; i < len; ++i) {
184
int pos = uc[i].unicode() - base;
185
if (pos > 0 && pos < 0x80) {
186
uchar iscii = uni_to_iscii_table[pos];
190
const uchar *pair = uni_to_iscii_pairs + 2*iscii;
198
if (uc[i].unicode() == 0x200c) { // ZWNJ
200
// Consonant Halant ZWNJ -> Consonant Halant Halant
202
} else if (uc[i].unicode() == 0x200d) { // ZWJ
204
// Consonant Halant ZWJ -> Consonant Halant Nukta
211
halant = (pos == 0x4d);
213
result.truncate(ch - (uchar *)result.data());
216
state->invalidChars += invalid;
217
state->state_data[0] = halant;
222
QString QIsciiCodec::convertToUnicode(const char* chars, int len, ConverterState *state) const
226
halant = state->state_data[0];
231
QChar *uc = (QChar *)result.unicode();
233
int base = codecs[idx].base;
235
for (int i = 0; i < len; ++i) {
236
ushort ch = (uchar) chars[i];
240
ushort c = iscii_to_uni_table[ch - 0xa0];
241
if (halant && (c == INV || c == 0xe9)) {
242
// Consonant Halant INV -> Consonant Halant ZWJ
243
// Consonant Halant Nukta -> Consonant Halant ZWJ
244
*uc++ = QChar(0x200d);
245
} else if (halant && c == 0xe8) {
246
// Consonant Halant Halant -> Consonant Halant ZWNJ
247
*uc++ = QChar(0x200c);
249
*uc++ = QChar(c+base);
252
halant = ((uchar)chars[i] == 0xe8);
254
result.resize(uc - result.unicode());
257
state->state_data[0] = halant;
261
#endif // QT_NO_CODECS