⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qeuckrcodec.cpp

📁 qt-embedded-2.3.8.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************** $Id: qt/src/3rdparty/tools/qeuckrcodec.cpp   2.3.8   edited 2004-08-05 $**** Implementation of QEucKrCodec class**** Created : 990225**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of the tools module of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************//*! \class QEucKrCodec qeuckrcodec.h  \brief Provides conversion to and from EUC-KR character sets  The QEucKrCodec class subclasses QTextCodec 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 Qt.)  \mustquote  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: <ol>  <li> Redistributions of source code must retain the above copyright     notice, this list of conditions and the following disclaimer.  <li> 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.  </ol>  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 CONSEQUENTIAL  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;    QTextDecoder* makeDecoder() const;    QCString fromUnicode(const QString& uc, int& len_in_out) const;    QString toUnicode(const char* chars, int len) const;    int heuristicContentMatch(const char* chars, int len) const;    int heuristicNameMatch(const char* hint) const;*/#include "qeuckrcodec.h"#ifndef QT_NO_EUCKRCODECunsigned int qt_Ksc5601ToUnicode(unsigned int code);unsigned int qt_UnicodeToKsc5601(unsigned int unicode);#define	IsEucChar(c)	(((c) >= 0xa1) && ((c) <= 0xfe))#define	QValidChar(u)	((u) ? QChar((ushort)(u)) : QChar::replacement)/*!  \reimp*/int QEucKrCodec::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*/QCString QEucKrCodec::fromUnicode(const QString& uc, int& len_in_out) const{  int l = QMIN((int)uc.length(),len_in_out);  int rlen = l*3+1;  QCString rstr(rlen);  uchar* cursor = (uchar*)rstr.data();  for (int i=0; i<l; i++) {    QChar ch = uc[i];    uint j;    if ( ch.row() == 0x00 && ch.cell() < 0x80 ) {      // ASCII      *cursor++ = ch.cell();    } else if ((j = qt_UnicodeToKsc5601((ch.row() << 8) | ch.cell())) ) {      // KSC 5601      *cursor++ = (j >> 8)   | 0x80;      *cursor++ = (j & 0xff) | 0x80;    } else if ( ch.unicode() == 0xa0 ) {	    *cursor++ = ' ';    } else {      // Error      *cursor++ = '?';	// unknown char    }  }  len_in_out = cursor - (uchar*)rstr.data();  rstr.truncate(len_in_out);  return rstr;}/*!  \reimp*/QString QEucKrCodec::toUnicode(const char* chars, int len) const{  QString result;  for (int i=0; i<len; i++) {    uchar ch = chars[i];    if ( ch < 0x80 ) {      // ASCII      result += QChar(ch);    } else if ( IsEucChar(ch) ) {      // KSC 5601      if ( i < len-1 ) {	uchar c2 = chars[++i];	if ( IsEucChar(c2) ) {	  uint u = qt_Ksc5601ToUnicode((ch << 8) | c2);	  result += QValidChar(u);	} else {	  i--;	  result += QChar::replacement;	}      } else {	result += QChar::replacement;      }    } else {      // Invalid      result += QChar::replacement;    }  }  return result;}/*!  \reimp*/const char* QEucKrCodec::name() const{  return "eucKR";}/*!  \reimp*/int QEucKrCodec::heuristicNameMatch(const char* hint) const{  int score = 0;  bool ko = FALSE;  if (qstrnicmp(hint, "ko_KR", 5) == 0 ||      qstrnicmp(hint, "korean", 5) == 0) {    score += 3;    ko = TRUE;  } else if (qstrnicmp(hint, "ko", 2) == 0) {    score += 2;    ko = TRUE;  }  const char *p;  if (ko) {    p = strchr(hint, '.');    if (p == 0) {      return score;    }    p++;  } else {    p = hint;  }  if (p) {    if (qstricmp(p, "eucKR") == 0) {      return score + 4;    }    else if (qstricmp(p, "euc") == 0 && ko) {      return score + 4;    }  }  return QTextCodec::heuristicNameMatch(hint);}/*!  \reimp*/int QEucKrCodec::heuristicContentMatch(const char* chars, int len) const{  int score = 0;  for (int i=0; i<len; i++) {    uchar ch = chars[i];    // No nulls allowed.    if ( !ch )      return -1;    if ( ch < 32 && ch != '\t' && ch != '\n' && ch != '\r' ) {      // Suspicious      if ( score )	score--;    } else if ( ch < 0x80 ) {      // Inconclusive    } else if ( IsEucChar(ch) ) {      // KSC 5601      if ( i < len-1 ) {	uchar c2 = chars[++i];	if ( !IsEucChar(c2) )	  return -1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -