0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtCore module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "qlatincodec_p.h"
|
|
43 |
#include "qlist.h"
|
|
44 |
|
|
45 |
#ifndef QT_NO_TEXTCODEC
|
|
46 |
|
|
47 |
QT_BEGIN_NAMESPACE
|
|
48 |
|
|
49 |
QLatin1Codec::~QLatin1Codec()
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
QString QLatin1Codec::convertToUnicode(const char *chars, int len, ConverterState *) const
|
|
54 |
{
|
|
55 |
if (chars == 0)
|
|
56 |
return QString();
|
|
57 |
|
|
58 |
return QString::fromLatin1(chars, len);
|
|
59 |
}
|
|
60 |
|
|
61 |
|
|
62 |
QByteArray QLatin1Codec::convertFromUnicode(const QChar *ch, int len, ConverterState *state) const
|
|
63 |
{
|
|
64 |
const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
|
|
65 |
QByteArray r(len, Qt::Uninitialized);
|
|
66 |
char *d = r.data();
|
|
67 |
int invalid = 0;
|
|
68 |
for (int i = 0; i < len; ++i) {
|
|
69 |
if (ch[i] > 0xff) {
|
|
70 |
d[i] = replacement;
|
|
71 |
++invalid;
|
|
72 |
} else {
|
|
73 |
d[i] = (char)ch[i].cell();
|
|
74 |
}
|
|
75 |
}
|
|
76 |
if (state) {
|
|
77 |
state->invalidChars += invalid;
|
|
78 |
}
|
|
79 |
return r;
|
|
80 |
}
|
|
81 |
|
|
82 |
QByteArray QLatin1Codec::name() const
|
|
83 |
{
|
|
84 |
return "ISO-8859-1";
|
|
85 |
}
|
|
86 |
|
|
87 |
QList<QByteArray> QLatin1Codec::aliases() const
|
|
88 |
{
|
|
89 |
QList<QByteArray> list;
|
|
90 |
list << "latin1"
|
|
91 |
<< "CP819"
|
|
92 |
<< "IBM819"
|
|
93 |
<< "iso-ir-100"
|
|
94 |
<< "csISOLatin1";
|
|
95 |
return list;
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
int QLatin1Codec::mibEnum() const
|
|
100 |
{
|
|
101 |
return 4;
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
QLatin15Codec::~QLatin15Codec()
|
|
106 |
{
|
|
107 |
}
|
|
108 |
|
|
109 |
QString QLatin15Codec::convertToUnicode(const char* chars, int len, ConverterState *) const
|
|
110 |
{
|
|
111 |
if (chars == 0)
|
|
112 |
return QString();
|
|
113 |
|
|
114 |
QString str = QString::fromLatin1(chars, len);
|
|
115 |
QChar *uc = str.data();
|
|
116 |
while(len--) {
|
|
117 |
switch(uc->unicode()) {
|
|
118 |
case 0xa4:
|
|
119 |
*uc = 0x20ac;
|
|
120 |
break;
|
|
121 |
case 0xa6:
|
|
122 |
*uc = 0x0160;
|
|
123 |
break;
|
|
124 |
case 0xa8:
|
|
125 |
*uc = 0x0161;
|
|
126 |
break;
|
|
127 |
case 0xb4:
|
|
128 |
*uc = 0x017d;
|
|
129 |
break;
|
|
130 |
case 0xb8:
|
|
131 |
*uc = 0x017e;
|
|
132 |
break;
|
|
133 |
case 0xbc:
|
|
134 |
*uc = 0x0152;
|
|
135 |
break;
|
|
136 |
case 0xbd:
|
|
137 |
*uc = 0x0153;
|
|
138 |
break;
|
|
139 |
case 0xbe:
|
|
140 |
*uc = 0x0178;
|
|
141 |
break;
|
|
142 |
default:
|
|
143 |
break;
|
|
144 |
}
|
|
145 |
uc++;
|
|
146 |
}
|
|
147 |
return str;
|
|
148 |
}
|
|
149 |
|
|
150 |
QByteArray QLatin15Codec::convertFromUnicode(const QChar *in, int length, ConverterState *state) const
|
|
151 |
{
|
|
152 |
const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
|
|
153 |
QByteArray r(length, Qt::Uninitialized);
|
|
154 |
char *d = r.data();
|
|
155 |
int invalid = 0;
|
|
156 |
for (int i = 0; i < length; ++i) {
|
|
157 |
uchar c;
|
|
158 |
ushort uc = in[i].unicode();
|
|
159 |
if (uc < 0x0100) {
|
|
160 |
if (uc > 0xa3) {
|
|
161 |
switch(uc) {
|
|
162 |
case 0xa4:
|
|
163 |
case 0xa6:
|
|
164 |
case 0xa8:
|
|
165 |
case 0xb4:
|
|
166 |
case 0xb8:
|
|
167 |
case 0xbc:
|
|
168 |
case 0xbd:
|
|
169 |
case 0xbe:
|
|
170 |
c = replacement;
|
|
171 |
++invalid;
|
|
172 |
break;
|
|
173 |
default:
|
|
174 |
c = (unsigned char) uc;
|
|
175 |
break;
|
|
176 |
}
|
|
177 |
} else {
|
|
178 |
c = (unsigned char) uc;
|
|
179 |
}
|
|
180 |
} else {
|
|
181 |
if (uc == 0x20ac)
|
|
182 |
c = 0xa4;
|
|
183 |
else if ((uc & 0xff00) == 0x0100) {
|
|
184 |
switch(uc) {
|
|
185 |
case 0x0160:
|
|
186 |
c = 0xa6;
|
|
187 |
break;
|
|
188 |
case 0x0161:
|
|
189 |
c = 0xa8;
|
|
190 |
break;
|
|
191 |
case 0x017d:
|
|
192 |
c = 0xb4;
|
|
193 |
break;
|
|
194 |
case 0x017e:
|
|
195 |
c = 0xb8;
|
|
196 |
break;
|
|
197 |
case 0x0152:
|
|
198 |
c = 0xbc;
|
|
199 |
break;
|
|
200 |
case 0x0153:
|
|
201 |
c = 0xbd;
|
|
202 |
break;
|
|
203 |
case 0x0178:
|
|
204 |
c = 0xbe;
|
|
205 |
break;
|
|
206 |
default:
|
|
207 |
c = replacement;
|
|
208 |
++invalid;
|
|
209 |
}
|
|
210 |
} else {
|
|
211 |
c = replacement;
|
|
212 |
++invalid;
|
|
213 |
}
|
|
214 |
}
|
|
215 |
d[i] = (char)c;
|
|
216 |
}
|
|
217 |
if (state) {
|
|
218 |
state->remainingChars = 0;
|
|
219 |
state->invalidChars += invalid;
|
|
220 |
}
|
|
221 |
return r;
|
|
222 |
}
|
|
223 |
|
|
224 |
|
|
225 |
QByteArray QLatin15Codec::name() const
|
|
226 |
{
|
|
227 |
return "ISO-8859-15";
|
|
228 |
}
|
|
229 |
|
|
230 |
QList<QByteArray> QLatin15Codec::aliases() const
|
|
231 |
{
|
|
232 |
QList<QByteArray> list;
|
|
233 |
list << "latin9";
|
|
234 |
return list;
|
|
235 |
}
|
|
236 |
|
|
237 |
int QLatin15Codec::mibEnum() const
|
|
238 |
{
|
|
239 |
return 111;
|
|
240 |
}
|
|
241 |
|
|
242 |
QT_END_NAMESPACE
|
|
243 |
|
|
244 |
#endif // QT_NO_TEXTCODEC
|