source: vendor/trolltech/current/src/codecs/qtsciicodec.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 16.2 KB
Line 
1/****************************************************************************
2** $Id: qtsciicodec.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Implementation of QTsciiCodec class
5**
6** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
7**
8** This file is part of the tools module of the Qt GUI Toolkit.
9**
10** This file may be distributed under the terms of the Q Public License
11** as defined by Trolltech AS of Norway and appearing in the file
12** LICENSE.QPL included in the packaging of this file.
13**
14** This file may be distributed and/or modified under the terms of the
15** GNU General Public License version 2 as published by the Free Software
16** Foundation and appearing in the file LICENSE.GPL included in the
17** packaging of this file.
18**
19** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
20** licenses may use this file in accordance with the Qt Commercial License
21** Agreement provided with the Software.
22**
23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25**
26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
27** information about Qt Commercial License Agreements.
28** See http://www.trolltech.com/qpl/ for QPL licensing information.
29** See http://www.trolltech.com/gpl/ for GPL licensing information.
30**
31** Contact info@trolltech.com if any conditions of this licensing are
32** not clear to you.
33**
34**********************************************************************/
35
36// Most of the code here was originally written by Hans Petter Bieker,
37// and is included in Qt with the author's permission, and the grateful
38// thanks of the Trolltech team.
39
40/*! \class QTsciiCodec qtsciicodec.h
41 \reentrant
42 \ingroup i18n
43
44 \brief The QTsciiCodec class provides conversion to and from the Tamil TSCII encoding.
45
46 TSCII, formally the Tamil Standard Code Information Interchange
47 specification, is a commonly used charset for Tamils. The
48 official page for the standard is at
49 \link http://www.tamil.net/tscii/ http://www.tamil.net/tscii/\endlink
50
51 This codec uses the mapping table found at
52 \link http://www.geocities.com/Athens/5180/tsciiset.html
53 http://www.geocities.com/Athens/5180/tsciiset.html\endlink.
54 Tamil uses composed Unicode which might cause some
55 problems if you are using Unicode fonts instead of TSCII fonts.
56
57 Most of the code here was written by Hans Petter Bieker
58 and is included in Qt with the author's permission and the
59 grateful thanks of the Trolltech team.
60 Here is the copyright statement for the code as it was at the
61 point of contribution. Trolltech's subsequent modifications
62 are covered by the usual copyright for Qt.
63
64 \legalese
65
66 Copyright (C) 2000 Hans Petter Bieker. All rights reserved.
67
68 Redistribution and use in source and binary forms, with or without
69 modification, are permitted provided that the following conditions
70 are met:
71 \list 1
72 \i Redistributions of source code must retain the above copyright
73 notice, this list of conditions and the following disclaimer.
74 \i Redistributions in binary form must reproduce the above copyright
75 notice, this list of conditions and the following disclaimer in the
76 documentation and/or other materials provided with the distribution.
77 \endlist
78
79 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
80 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
83 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
86 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 SUCH DAMAGE.
90*/
91
92#include "qtsciicodec.h"
93
94#ifndef QT_NO_CODECS
95
96static unsigned char qt_UnicodeToTSCII(ushort u1, ushort u2, ushort u3);
97static unsigned int qt_TSCIIToUnicode(unsigned int code, uint *s);
98
99#define IsTSCIIChar(c) (((c) >= 0x80) && ((c) <= 0xfd))
100#define QValidChar(u) ((u) ? QChar((u)) : QChar::replacement)
101
102/*! \reimp */
103int QTsciiCodec::mibEnum() const
104{
105 /* There is no MIBEnum for TSCII now */
106 return 2028;
107}
108
109/*! \reimp */
110QCString QTsciiCodec::fromUnicode(const QString& uc, int& lenInOut) const
111{
112 int l = QMIN((int)uc.length(), lenInOut);
113 int rlen = l+1;
114 QCString rstr(rlen);
115 uchar* cursor = (uchar*)rstr.data();
116 for (int i = 0; i < l; i++) {
117 QChar ch = uc[i];
118 uchar j;
119 if ( ch.row() == 0x00 && ch.cell() < 0x80 ) {
120 // ASCII
121 j = ch.cell();
122 } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
123 uc[i + 1].unicode(),
124 uc[i + 2].unicode()))) {
125 // We have to check the combined chars first!
126 i += 2;
127 } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
128 uc[i + 1].unicode(), 0))) {
129 i++;
130 } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(), 0, 0))) {
131 } else {
132 // Error
133 j = '?'; // unknown char
134 }
135 *cursor++ = j;
136 }
137 lenInOut = cursor - (uchar*)rstr.data();
138 *cursor = 0;
139 return rstr;
140}
141
142/*! \reimp */
143QString QTsciiCodec::toUnicode(const char* chars, int len) const
144{
145 QString result;
146 for (int i = 0; i < len; i++) {
147 uchar ch = chars[i];
148 if ( ch < 0x80 ) {
149 // ASCII
150 result += QChar(ch);
151 } else if ( IsTSCIIChar(ch) ) {
152 // TSCII
153 uint s[3];
154 uint u = qt_TSCIIToUnicode(ch, s);
155 uint *p = s;
156 while ( u-- ) {
157 uint c = *p++;
158 result += QValidChar(c);
159 }
160 } else {
161 // Invalid
162 result += QChar::replacement;
163 }
164 }
165
166 return result;
167}
168
169/*! \reimp */
170const char* QTsciiCodec::name() const
171{
172 return "TSCII";
173}
174
175/*! \reimp */
176int QTsciiCodec::heuristicNameMatch(const char* hint) const
177{
178 const char *p = strchr(hint, '.');
179 if (p)
180 p++;
181 else
182 p = hint;
183 if (qstricmp(p, "TSCII") == 0)
184 return 4;
185 return QTextCodec::heuristicNameMatch(hint);
186}
187
188/*! \reimp */
189int QTsciiCodec::heuristicContentMatch(const char* chars, int len) const
190{
191 int score = 0;
192 for (int i=0; i<len; i++) {
193 uchar ch = chars[i];
194 // No nulls allowed.
195 if ( !ch )
196 return -1;
197 if ( ch < 32 && ch != '\t' && ch != '\n' && ch != '\r' ) {
198 // Suspicious
199 if ( score )
200 score--;
201 } else if ( ch < 0x80 ) {
202 // Inconclusive
203 } else if ( IsTSCIIChar(ch) ) {
204 score++;
205 } else {
206 // Invalid
207 return -1;
208 }
209 }
210 return score;
211}
212
213static const int UnToTsLast = 124; // 125 items -- so the last will be 124
214static const ushort UnToTs [][4] = {
215 // *Sorted* list of TSCII maping for unicode chars
216 //FIRST SECOND THIRD TSCII
217 {0x00A0, 0x0000, 0x0000, 0xA0},
218 {0x00A9, 0x0000, 0x0000, 0xA9},
219 {0x0B83, 0x0000, 0x0000, 0xB7},
220 {0x0B85, 0x0000, 0x0000, 0xAB},
221 {0x0B86, 0x0000, 0x0000, 0xAC},
222 {0x0B87, 0x0000, 0x0000, 0xAD},
223 {0x0B88, 0x0000, 0x0000, 0xAE},
224 {0x0B89, 0x0000, 0x0000, 0xAF},
225 {0x0B8A, 0x0000, 0x0000, 0xB0},
226 {0x0B8E, 0x0000, 0x0000, 0xB1},
227 {0x0B8F, 0x0000, 0x0000, 0xB2},
228 {0x0B90, 0x0000, 0x0000, 0xB3},
229 {0x0B92, 0x0000, 0x0000, 0xB4},
230 {0x0B93, 0x0000, 0x0000, 0xB5},
231 {0x0B94, 0x0000, 0x0000, 0xB6},
232 {0x0B95, 0x0000, 0x0000, 0xB8},
233 {0x0B95, 0x0B82, 0x0000, 0xEC},
234 {0x0B95, 0x0BC1, 0x0000, 0xCC},
235 {0x0B95, 0x0BC2, 0x0000, 0xDC},
236 {0x0B99, 0x0000, 0x0000, 0xB9},
237 {0x0B99, 0x0B82, 0x0000, 0xED},
238 {0x0B99, 0x0BC1, 0x0000, 0x99},
239 {0x0B99, 0x0BC2, 0x0000, 0x9B},
240 {0x0B9A, 0x0000, 0x0000, 0xBA},
241 {0x0B9A, 0x0B82, 0x0000, 0xEE},
242 {0x0B9A, 0x0BC1, 0x0000, 0xCD},
243 {0x0B9A, 0x0BC2, 0x0000, 0xDD},
244 {0x0B9C, 0x0000, 0x0000, 0x83},
245 {0x0B9C, 0x0B82, 0x0000, 0x88},
246 {0x0B9E, 0x0000, 0x0000, 0xBB},
247 {0x0B9E, 0x0B82, 0x0000, 0xEF},
248 {0x0B9E, 0x0BC1, 0x0000, 0x9A},
249 {0x0B9E, 0x0BC2, 0x0000, 0x9C},
250 {0x0B9F, 0x0000, 0x0000, 0xBC},
251 {0x0B9F, 0x0B82, 0x0000, 0xF0},
252 {0x0B9F, 0x0BBF, 0x0000, 0xCA},
253 {0x0B9F, 0x0BC0, 0x0000, 0xCB},
254 {0x0B9F, 0x0BC1, 0x0000, 0xCE},
255 {0x0B9F, 0x0BC2, 0x0000, 0xDE},
256 {0x0BA1, 0x0B82, 0x0000, 0xF2},
257 {0x0BA3, 0x0000, 0x0000, 0xBD},
258 {0x0BA3, 0x0B82, 0x0000, 0xF1},
259 {0x0BA3, 0x0BC1, 0x0000, 0xCF},
260 {0x0BA3, 0x0BC2, 0x0000, 0xDF},
261 {0x0BA4, 0x0000, 0x0000, 0xBE},
262 {0x0BA4, 0x0BC1, 0x0000, 0xD0},
263 {0x0BA4, 0x0BC2, 0x0000, 0xE0},
264 {0x0BA8, 0x0000, 0x0000, 0xBF},
265 {0x0BA8, 0x0B82, 0x0000, 0xF3},
266 {0x0BA8, 0x0BC1, 0x0000, 0xD1},
267 {0x0BA8, 0x0BC2, 0x0000, 0xE1},
268 {0x0BA9, 0x0000, 0x0000, 0xC9},
269 {0x0BA9, 0x0B82, 0x0000, 0xFD},
270 {0x0BA9, 0x0BC1, 0x0000, 0xDB},
271 {0x0BA9, 0x0BC2, 0x0000, 0xEB},
272 {0x0BAA, 0x0000, 0x0000, 0xC0},
273 {0x0BAA, 0x0B82, 0x0000, 0xF4},
274 {0x0BAA, 0x0BC1, 0x0000, 0xD2},
275 {0x0BAA, 0x0BC2, 0x0000, 0xE2},
276 {0x0BAE, 0x0000, 0x0000, 0xC1},
277 {0x0BAE, 0x0B82, 0x0000, 0xF5},
278 {0x0BAE, 0x0BC1, 0x0000, 0xD3},
279 {0x0BAE, 0x0BC2, 0x0000, 0xE3},
280 {0x0BAF, 0x0000, 0x0000, 0xC2},
281 {0x0BAF, 0x0B82, 0x0000, 0xF6},
282 {0x0BAF, 0x0BC1, 0x0000, 0xD4},
283 {0x0BAF, 0x0BC2, 0x0000, 0xE4},
284 {0x0BB0, 0x0000, 0x0000, 0xC3},
285 {0x0BB0, 0x0B82, 0x0000, 0xF7},
286 {0x0BB0, 0x0BC1, 0x0000, 0xD5},
287 {0x0BB0, 0x0BC2, 0x0000, 0xE5},
288 {0x0BB1, 0x0000, 0x0000, 0xC8},
289 {0x0BB1, 0x0B82, 0x0000, 0xFC},
290 {0x0BB1, 0x0BC1, 0x0000, 0xDA},
291 {0x0BB1, 0x0BC2, 0x0000, 0xEA},
292 {0x0BB2, 0x0000, 0x0000, 0xC4},
293 {0x0BB2, 0x0B82, 0x0000, 0xF8},
294 {0x0BB2, 0x0BC1, 0x0000, 0xD6},
295 {0x0BB2, 0x0BC2, 0x0000, 0xE6},
296 {0x0BB3, 0x0000, 0x0000, 0xC7},
297 {0x0BB3, 0x0B82, 0x0000, 0xFB},
298 {0x0BB3, 0x0BC1, 0x0000, 0xD9},
299 {0x0BB3, 0x0BC2, 0x0000, 0xE9},
300 {0x0BB4, 0x0000, 0x0000, 0xC6},
301 {0x0BB4, 0x0B82, 0x0000, 0xFA},
302 {0x0BB4, 0x0BC1, 0x0000, 0xD8},
303 {0x0BB4, 0x0BC2, 0x0000, 0xE8},
304 {0x0BB5, 0x0000, 0x0000, 0xC5},
305 {0x0BB5, 0x0B82, 0x0000, 0xF9},
306 {0x0BB5, 0x0BC1, 0x0000, 0xD7},
307 {0x0BB5, 0x0BC2, 0x0000, 0xE7},
308 {0x0BB7, 0x0000, 0x0000, 0x84},
309 {0x0BB7, 0x0B82, 0x0000, 0x89},
310 {0x0BB8, 0x0000, 0x0000, 0x85},
311 {0x0BB8, 0x0B82, 0x0000, 0x8A},
312 {0x0BB9, 0x0000, 0x0000, 0x86},
313 {0x0BB9, 0x0B82, 0x0000, 0x8B},
314 {0x0BBE, 0x0000, 0x0000, 0xA1},
315 {0x0BBF, 0x0000, 0x0000, 0xA2},
316 {0x0BC0, 0x0000, 0x0000, 0xA3},
317 {0x0BC1, 0x0000, 0x0000, 0xA4},
318 {0x0BC2, 0x0000, 0x0000, 0xA5},
319 {0x0BC6, 0x0000, 0x0000, 0xA6},
320 {0x0BC7, 0x0000, 0x0000, 0xA7},
321 {0x0BC8, 0x0000, 0x0000, 0xA8},
322 {0x0BCC, 0x0000, 0x0000, 0xAA},
323 {0x0BE6, 0x0000, 0x0000, 0x80},
324 {0x0BE7, 0x0000, 0x0000, 0x81},
325 {0x0BE7, 0x0BB7, 0x0000, 0x87},
326 {0x0BE7, 0x0BB7, 0x0B82, 0x8C},
327 {0x0BE8, 0x0000, 0x0000, 0x8D},
328 {0x0BE9, 0x0000, 0x0000, 0x8E},
329 {0x0BEA, 0x0000, 0x0000, 0x8F},
330 {0x0BEB, 0x0000, 0x0000, 0x90},
331 {0x0BEC, 0x0000, 0x0000, 0x95},
332 {0x0BED, 0x0000, 0x0000, 0x96},
333 {0x0BEE, 0x0000, 0x0000, 0x97},
334 {0x0BEF, 0x0000, 0x0000, 0x98},
335 {0x0BF0, 0x0000, 0x0000, 0x9D},
336 {0x0BF1, 0x0000, 0x0000, 0x9E},
337 {0x0BF2, 0x0000, 0x0000, 0x9F},
338 {0x2018, 0x0000, 0x0000, 0x91},
339 {0x2019, 0x0000, 0x0000, 0x92},
340 {0x201C, 0x0000, 0x0000, 0x93},
341 {0x201C, 0x0000, 0x0000, 0x94}
342};
343
344static const ushort TsToUn [][3] = {
345 // Starting at 0x80
346 {0x0BE6, 0x0000, 0x0000},
347 {0x0BE7, 0x0000, 0x0000},
348 {0x0000, 0x0000, 0x0000}, // unknown
349 {0x0B9C, 0x0000, 0x0000},
350 {0x0BB7, 0x0000, 0x0000},
351 {0x0BB8, 0x0000, 0x0000},
352 {0x0BB9, 0x0000, 0x0000},
353 {0x0BE7, 0x0BB7, 0x0000},
354 {0x0B9C, 0x0B82, 0x0000},
355 {0x0BB7, 0x0B82, 0x0000},
356 {0x0BB8, 0x0B82, 0x0000},
357 {0x0BB9, 0x0B82, 0x0000},
358 {0x0BE7, 0x0BB7, 0x0B82},
359 {0x0BE8, 0x0000, 0x0000},
360 {0x0BE9, 0x0000, 0x0000},
361 {0x0BEA, 0x0000, 0x0000},
362 {0x0BEB, 0x0000, 0x0000},
363 {0x2018, 0x0000, 0x0000},
364 {0x2019, 0x0000, 0x0000},
365 {0x201C, 0x0000, 0x0000},
366 {0x201C, 0x0000, 0x0000}, // two of the same??
367 {0x0BEC, 0x0000, 0x0000},
368 {0x0BED, 0x0000, 0x0000},
369 {0x0BEE, 0x0000, 0x0000},
370 {0x0BEF, 0x0000, 0x0000},
371 {0x0B99, 0x0BC1, 0x0000},
372 {0x0B9E, 0x0BC1, 0x0000},
373 {0x0B99, 0x0BC2, 0x0000},
374 {0x0B9E, 0x0BC2, 0x0000},
375 {0x0BF0, 0x0000, 0x0000},
376 {0x0BF1, 0x0000, 0x0000},
377 {0x0BF2, 0x0000, 0x0000},
378 {0x00A0, 0x0000, 0x0000},
379 {0x0BBE, 0x0000, 0x0000},
380 {0x0BBF, 0x0000, 0x0000},
381 {0x0BC0, 0x0000, 0x0000},
382 {0x0BC1, 0x0000, 0x0000},
383 {0x0BC2, 0x0000, 0x0000},
384 {0x0BC6, 0x0000, 0x0000},
385 {0x0BC7, 0x0000, 0x0000},
386 {0x0BC8, 0x0000, 0x0000},
387 {0x00A9, 0x0000, 0x0000},
388 {0x0BCC, 0x0000, 0x0000},
389 {0x0B85, 0x0000, 0x0000},
390 {0x0B86, 0x0000, 0x0000},
391 {0x0B87, 0x0000, 0x0000},
392 {0x0B88, 0x0000, 0x0000},
393 {0x0B89, 0x0000, 0x0000},
394 {0x0B8A, 0x0000, 0x0000},
395 {0x0B8E, 0x0000, 0x0000},
396 {0x0B8F, 0x0000, 0x0000},
397 {0x0B90, 0x0000, 0x0000},
398 {0x0B92, 0x0000, 0x0000},
399 {0x0B93, 0x0000, 0x0000},
400 {0x0B94, 0x0000, 0x0000},
401 {0x0B83, 0x0000, 0x0000},
402 {0x0B95, 0x0000, 0x0000},
403 {0x0B99, 0x0000, 0x0000},
404 {0x0B9A, 0x0000, 0x0000},
405 {0x0B9E, 0x0000, 0x0000},
406 {0x0B9F, 0x0000, 0x0000},
407 {0x0BA3, 0x0000, 0x0000},
408 {0x0BA4, 0x0000, 0x0000},
409 {0x0BA8, 0x0000, 0x0000},
410 {0x0BAA, 0x0000, 0x0000},
411 {0x0BAE, 0x0000, 0x0000},
412 {0x0BAF, 0x0000, 0x0000},
413 {0x0BB0, 0x0000, 0x0000},
414 {0x0BB2, 0x0000, 0x0000},
415 {0x0BB5, 0x0000, 0x0000},
416 {0x0BB4, 0x0000, 0x0000},
417 {0x0BB3, 0x0000, 0x0000},
418 {0x0BB1, 0x0000, 0x0000},
419 {0x0BA9, 0x0000, 0x0000},
420 {0x0B9F, 0x0BBF, 0x0000},
421 {0x0B9F, 0x0BC0, 0x0000},
422 {0x0B95, 0x0BC1, 0x0000},
423 {0x0B9A, 0x0BC1, 0x0000},
424 {0x0B9F, 0x0BC1, 0x0000},
425 {0x0BA3, 0x0BC1, 0x0000},
426 {0x0BA4, 0x0BC1, 0x0000},
427 {0x0BA8, 0x0BC1, 0x0000},
428 {0x0BAA, 0x0BC1, 0x0000},
429 {0x0BAE, 0x0BC1, 0x0000},
430 {0x0BAF, 0x0BC1, 0x0000},
431 {0x0BB0, 0x0BC1, 0x0000},
432 {0x0BB2, 0x0BC1, 0x0000},
433 {0x0BB5, 0x0BC1, 0x0000},
434 {0x0BB4, 0x0BC1, 0x0000},
435 {0x0BB3, 0x0BC1, 0x0000},
436 {0x0BB1, 0x0BC1, 0x0000},
437 {0x0BA9, 0x0BC1, 0x0000},
438 {0x0B95, 0x0BC2, 0x0000},
439 {0x0B9A, 0x0BC2, 0x0000},
440 {0x0B9F, 0x0BC2, 0x0000},
441 {0x0BA3, 0x0BC2, 0x0000},
442 {0x0BA4, 0x0BC2, 0x0000},
443 {0x0BA8, 0x0BC2, 0x0000},
444 {0x0BAA, 0x0BC2, 0x0000},
445 {0x0BAE, 0x0BC2, 0x0000},
446 {0x0BAF, 0x0BC2, 0x0000},
447 {0x0BB0, 0x0BC2, 0x0000},
448 {0x0BB2, 0x0BC2, 0x0000},
449 {0x0BB5, 0x0BC2, 0x0000},
450 {0x0BB4, 0x0BC2, 0x0000},
451 {0x0BB3, 0x0BC2, 0x0000},
452 {0x0BB1, 0x0BC2, 0x0000},
453 {0x0BA9, 0x0BC2, 0x0000},
454 {0x0B95, 0x0B82, 0x0000},
455 {0x0B99, 0x0B82, 0x0000},
456 {0x0B9A, 0x0B82, 0x0000},
457 {0x0B9E, 0x0B82, 0x0000},
458 {0x0B9F, 0x0B82, 0x0000},
459 {0x0BA3, 0x0B82, 0x0000},
460 {0x0BA1, 0x0B82, 0x0000},
461 {0x0BA8, 0x0B82, 0x0000},
462 {0x0BAA, 0x0B82, 0x0000},
463 {0x0BAE, 0x0B82, 0x0000},
464 {0x0BAF, 0x0B82, 0x0000},
465 {0x0BB0, 0x0B82, 0x0000},
466 {0x0BB2, 0x0B82, 0x0000},
467 {0x0BB5, 0x0B82, 0x0000},
468 {0x0BB4, 0x0B82, 0x0000},
469 {0x0BB3, 0x0B82, 0x0000},
470 {0x0BB1, 0x0B82, 0x0000},
471 {0x0BA9, 0x0B82, 0x0000}
472};
473
474static int cmp(const ushort *s1, const ushort *s2, size_t len)
475{
476 int diff = 0;
477
478 while (len-- && (diff = *s1++ - *s2++) == 0)
479 ;
480
481 return diff;
482}
483
484static unsigned char qt_UnicodeToTSCII(ushort u1, ushort u2, ushort u3)
485{
486 ushort s[3];
487 s[0] = u1;
488 s[1] = u2;
489 s[2] = u3;
490
491 int a = 0; // start pos
492 int b = UnToTsLast; // end pos
493
494 // do a binary search for the composed unicode in the list
495 while (a <= b) {
496 int w = (a + b) / 2;
497 int j = cmp(UnToTs[w], s, 3);
498
499 if (j == 0)
500 // found it
501 return UnToTs[w][3];
502
503 if (j < 0)
504 a = w + 1;
505 else
506 b = w - 1;
507 }
508
509 return 0;
510}
511
512static unsigned int qt_TSCIIToUnicode(uint code, uint *s)
513{
514 int len = 0;
515 for (int i = 0; i < 3; i++) {
516 uint u = TsToUn[code & 0x7f][i];
517 s[i] = u;
518 if (s[i]) len = i + 1;
519 }
520
521 return len;
522}
523
524#endif
525
Note: See TracBrowser for help on using the repository browser.