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