📄 qjpunicode.cpp
字号:
/****************************************************************************** $Id: qt/src/3rdparty/tools/qjpunicode.cpp 2.3.8 edited 2004-08-05 $**** Implementation of QJpUnicodeConv 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 QJpUnicodeConv qjpunicode.h \brief The QJpUnicodeConv class provides implementation support for QJisCodec, QSjisCodec, and QEucJpCodec. You should not need to use this class directly. If you do, keep in mind that the function names will change in Qt 3.0: Every function name will get a lower-case first letter: Jisx0212ToUnicode becomes jisx0212ToUnicode, and so on. We apologize for the upheaval. The environment variable \c UNICODEMAP_JP can be used to fine-tune how QJpUnicodeConv, QEucJpCodec, QJisCodec and QSjisCodec do their work. The mapping names are as for the Japanese XML working group's <a href="http://www.y-adagio.com/public/standards/tr_xml_jpf/toc.htm"> XML Japanese Profile</a>, as it names and explains all the widely used mappings. Here are brief descriptions, written by Serika Kurusugawa: <ul> <li> "unicode-0.9" or "unicode-0201" for Unicode style. This assume JISX0201 for 0x00-0x7f. (0.9 is a table version of jisx02xx mapping used for Uniocde spec version 1.1) <li> "unicode-ascii" This assume US-ASCII for 0x00-0x7f, and some chars (JISX0208 0x2140 and JISX0212 0x2237) are different from Unicode 1.1 to avoid conflict. <li> "open-19970715-0201" ("open-0201" for convenience) or "jisx0221-1995" for JISX0221-JISX0201 style. JIS X 0221 is JIS version of Unicode, but a few chars (0x5c, 0x7e, 0x2140, 0x216f, 0x2131) are different from Unicode 1.1. This is used when 0x5c is treated as YEN SIGN. <li> "open-19970715-ascii" ("open-ascii" for convenience) for JISX0221-ASCII style. This is used when 0x5c is treated as REVERSE SOLIDUS. <li> "open-19970715-ms" ("open-ms" for convenience) or "cp932" for Microsoft Windows style. Windows Code Page 932. Some chars (0x2140, 0x2141, 0x2142, 0x215d, 0x2171, 0x2172) are different from Unicode 1.1. <li> "jdk1.1.7" for Sun's JDK style Same as Unicode 1.1, except that JIS 0x2140 is mapped to UFF3C. Either ASCII or JISX0201 can be used for 0x00-0x7f. </ul> In addition, QJpUnicodeConv supports some extensions: "nec-vdc", "ibm-vdc" or "udc". For example, if you want to use Unicode style conversion, but with NEC's extension, set \c UNICODEMAP_JP to <nobr><code>unicode-0.9, nec-vdc</code>.</nobr> (You will probably need to quote that in the shell command.) Most of the code here was originally written by Serika Kurusugawa a.k.a. Junji Takagi, and is includes in Qt with the author's permission, and the grateful thanks of the Trolltech team. Here is the copyright statement for that code: \mustquote Copyright (c) 1999 Serika Kurusugawa, 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.*/#include "qcstring.h"#ifndef QT_NO_JPUNICODE#include <stdlib.h>#include <ctype.h>#include "qjpunicode.h"#define USE_JISX0212#define STRICT#define IsLatin(c) (/*((c) >= 0x00) &&*/ ((c) <= 0x7f))#define IsKana(c) (((c) >= 0xa1) && ((c) <= 0xdf))#define IsJisChar(c) (((c) >= 0x21) && ((c) <= 0x7e))#define IsSjisChar1(c) ((((c) >= 0x81) && ((c) <= 0x9f)) || \ (((c) >= 0xe0) && ((c) <= 0xfc)))#define IsSjisUDC1(c) (((c) >= 0xf0) && ((c) <= 0xfc))#define IsSjisChar2(c) (((c) >= 0x40) && ((c) != 0x7f) && ((c) <= 0xfc))static uint Jisx0208ToSjis(uint h, uint l);staticinline uint Jisx0208ToSjis(uint jis){ return Jisx0208ToSjis((jis & 0xff00) >> 8, (jis & 0x00ff));}static uint SjisToJisx0208(uint h, uint l);#if 0staticinline uint SjisToJisx0208(uint sjis){ return SjisToJisx0208((sjis & 0xff00) >> 8, (sjis & 0x00ff));}#endifstatic uint Jisx0201ToUnicode11(uint h, uint l);static uint Jisx0208ToUnicode11(uint h, uint l);static uint Jisx0212ToUnicode11(uint h, uint l);static uint Unicode11ToJisx0201(uint h, uint l);static uint Unicode11ToJisx0208(uint h, uint l);static uint Unicode11ToJisx0212(uint h, uint l);/* * Unicode 1.1 conversion. *//*! \fn QJpUnicodeConv::QJpUnicodeConv (int r) \internal*//*! \internal */uint QJpUnicodeConv::AsciiToUnicode(uint h, uint l) const{ if ((h == 0) && (l < 0x80)) { return l; } return 0x0000;}/*! \internal */uint QJpUnicodeConv::Jisx0201ToUnicode(uint h, uint l) const{ if (h == 0) { if (IsLatin(l)) { return Jisx0201LatinToUnicode(h, l); } else if (IsKana(l)) { return Jisx0201KanaToUnicode(h, l); } } return 0x0000;}/*! \internal */uint QJpUnicodeConv::Jisx0201LatinToUnicode(uint h, uint l) const{ if ((h == 0) && IsLatin(l)) { return Jisx0201ToUnicode11(h, l); } return 0x0000;}/*! \internal */uint QJpUnicodeConv::Jisx0201KanaToUnicode(uint h, uint l) const{ if ((h == 0) && IsKana(l)) { return Jisx0201ToUnicode11(h, l); } return 0x0000;}/*! \internal */uint QJpUnicodeConv::Jisx0208ToUnicode(uint h, uint l) const{ if (rule & JU_UDC){ if ((0x75 <= h) && (h <= 0x7e) && IsJisChar(l)/*0x21 - 0x7e*/) { // User Defined Char (mapped to Private Use Area) return 0xe000 + (h - 0x75) * 0x5e + (l - 0x21); } } if ((rule & JU_NEC_VDC) == 0) { if ((h == 0x2d) && (IsJisChar(l)/*0x21 - 0x7c*/)) { // NEC Vendor Defined Char return 0x0000; } } return Jisx0208ToUnicode11(h, l);}/*! \internal */uint QJpUnicodeConv::Jisx0212ToUnicode(uint h, uint l) const{ if (rule & JU_UDC){ if ((0x75 <= h) && (h <= 0x7e) && IsJisChar(l)/*0x21 - 0x7e*/) { // User Defined Char (mapped to Private Use Area) return 0xe3ac + (h - 0x75) * 0x5e + (l - 0x21); } } if ((rule & JU_IBM_VDC) == 0){ if (((h == 0x73) && (0x73 <= l) && (l <= 0x7e)) || ((h == 0x74) && (IsJisChar(l)/*0x21 - 0x7e*/))) { // IBM Vendor Defined Char return 0x0000; } } return Jisx0212ToUnicode11(h, l);}/*! \internal */uint QJpUnicodeConv::UnicodeToAscii(uint h, uint l) const{ if ((h == 0) && (l < 0x80)) { return l; } return 0x0000;}/*! \internal */uint QJpUnicodeConv::UnicodeToJisx0201(uint h, uint l) const{ uint jis; if ((jis = UnicodeToJisx0201Latin(h, l)) != 0) { return jis; } else if ((jis = UnicodeToJisx0201Kana(h, l)) != 0) { return jis; } return 0x0000;}/*! \internal */uint QJpUnicodeConv::UnicodeToJisx0201Latin(uint h, uint l) const{ uint jis = Unicode11ToJisx0201(h, l); if (IsLatin(jis)) { return jis; } return 0x0000;}/*! \internal */uint QJpUnicodeConv::UnicodeToJisx0201Kana(uint h, uint l) const{ uint jis = Unicode11ToJisx0201(h, l); if (IsKana(jis)) { return jis; } return 0x0000;}/*! \internal */uint QJpUnicodeConv::UnicodeToJisx0208(uint h, uint l) const{ if (rule & JU_UDC){ uint unicode = (h << 8) | l; if ((0xe000 <= unicode) && (unicode <= 0xe3ab)) { // User Defined Char (mapped to Private Use Area) unicode -= 0xe000; return ((0x75 + unicode / 0x5e ) << 8) | (0x21 + unicode % 0x5e); } } uint jis = Unicode11ToJisx0208(h, l); if ((rule & JU_NEC_VDC) == 0) { if ((0x2d21 <= jis) && (jis <= 0x2d7c)) { // NEC Vendor Defined Char return 0x0000; } } return jis;}/*! \internal */uint QJpUnicodeConv::UnicodeToJisx0212(uint h, uint l) const{ if (rule & JU_UDC){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -