/****************************************************************************
**
** Implementation of TQEucKrCodec class
**
** Created : 990225
**
** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the tools module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file. Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/
/*! \class TQEucKrCodec ntqeuckrcodec.h
\reentrant
\ingroup i18n
\brief The TQEucKrCodec class provides conversion to and from EUC-KR character sets.
The TQEucKrCodec class subclasses TQTextCodec to provide support for
EUC-KR, the main legacy encoding for UNIX machines in Korea.
It was largely written by Mizi Research Inc. Here is the copyright
statement for the code as it was at the point of contribution.
Trolltech's subsequent modifications are covered by the usual
copyright for TQt.
\legalese
Copyright (C) 1999-2000 Mizi Research Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSETQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* these must be made \internal
virtual int mibEnum() const;
const char* name() const;
TQTextDecoder* makeDecoder() const;
TQCString fromUnicode(const TQString& uc, int& lenInOut) const;
TQString toUnicode(const char* chars, int len) const;
int heuristicContentMatch(const char* chars, int len) const;
int heuristicNameMatch(const char* hint) const;
*/
#include "ntqeuckrcodec.h"
#ifndef QT_NO_BIG_CODECS
unsigned int qt_Ksc5601ToUnicode(unsigned int code);
unsigned int qt_UnicodeToKsc5601(unsigned int unicode);
#define IsEucChar(c) (((c) >= 0xa1) && ((c) <= 0xfe))
#define TQValidChar(u) ((u) ? TQChar((ushort)(u)) : TQChar::replacement)
/*!
\reimp
*/
int TQEucKrCodec::mibEnum() const
{
/*
* Name: EUC-KR (preferred MIME name) [RFC1557,Choi]
* MIBenum: 38
* Source: RFC-1557 (see also KS_C_5861-1992)
* Alias: csEUCKR
*/
/* mibEnum for other codeset related with Korean.
KS_C_5601-1987 36, ISO2022-KRi 37 */
return 38;
}
/*!
\reimp
*/
TQCString TQEucKrCodec::fromUnicode(const TQString& uc, int& lenInOut) const
{
int l = TQMIN((int)uc.length(),lenInOut);
int rlen = l*3+1;
TQCString rstr(rlen);
uchar* cursor = (uchar*)rstr.data();
for (int i=0; i> 8) | 0x80;
*cursor++ = (j & 0xff) | 0x80;
} else {
// Error
*cursor++ = '?'; // unknown char
}
}
lenInOut = cursor - (uchar*)rstr.data();
rstr.truncate(lenInOut);
return rstr;
}
/*!
\reimp
*/
TQString TQEucKrCodec::toUnicode(const char* chars, int len) const
{
TQString result;
for (int i=0; i> 8;
int ch2 = code & 0x00ff;
int idx;
if (ch1 < 0x80 || (ch1 - 0x80) <= 0x20 || (ch1 - 0x80) >= 0x7e
|| (ch1 - 0x80) == 0x49)
return 0;
if (ch2 < 0x80 || (ch2 - 0x80) <= 0x20 || (ch2 - 0x80) >= 0x7f)
return 0;
idx = (ch1 - 0x80 - 0x21) * 94 + (ch2 - 0x80 - 0x21);
/* Hangul : row 16 - row 40 : 1410 = 15 * 94 ,
3760 = 40 * 94 */
if (idx >= 1410 && idx < 1410 + 2350)
return (ksc5601_hangul_to_unicode[idx - 1410]);
else if (idx >= 3854)
/* Hanja : row 42 - row 93 : 3854 = 94 * (42-1) */
return (ksc5601_hanja_to_unicode[idx - 3854]);
else if(idx <= 1114)
return (ksc5601_symbol_to_unicode[idx]);
return 0;
}
static unsigned short unicode2ksc(unsigned short unicode)
{
int lo, hi, mid, c2;
unsigned char s[2];
lo = mid = c2 = 0;
if (unicode >= 0xac00 && unicode <= 0xd7a3) {
// Hangul
hi = 2349;
while (lo <= hi) { // binary search
mid = (lo + hi) / 2;
c2 = ksc5601_hangul_to_unicode[mid];
if(unicode < c2)
hi = mid - 1;
else if(unicode > c2)
lo = mid + 1;
else { // unicode == c2
s[0] = (mid / 94) + 0x30;
s[1] = (mid % 94) + 0x21;
return ( (s[0] << 8) | s[1] );
}
}
} else if ((unicode >= 0x4e00 && unicode <= 0x9fff)
|| (unicode >= 0xf900 && unicode <= 0xfa0b)) {
// Hanja
hi = 4887;
while (lo <= hi) { // binary search
mid = (lo + hi) / 2;
c2 = unicode_to_ksc5601_hanja[mid].unicode;
if(unicode < c2)
hi = mid - 1;
else if(unicode > c2)
lo = mid + 1;
else { // unicode == c2
return unicode_to_ksc5601_hanja[mid].kscode;
}
}
} else {
// Symbol
hi = 985;
while (lo <= hi) { // binary search
mid = (lo + hi) / 2;
c2 = unicode_to_ksc5601_symbol[mid].unicode;
if(unicode < c2)
hi = mid - 1;
else if(unicode > c2)
lo = mid + 1;
else { // unicode == c2
return unicode_to_ksc5601_symbol[mid].kscode;
}
}
}
return 0;
}
#endif