| 1 | /**************************************************************************** | 
|---|
| 2 | ** $Id: qjpunicode.h 2 2005-11-16 15:49:26Z dmik $ | 
|---|
| 3 | ** | 
|---|
| 4 | ** Definition of QJpUnicodeConv class | 
|---|
| 5 | ** | 
|---|
| 6 | ** Created : 990225 | 
|---|
| 7 | ** | 
|---|
| 8 | ** Copyright (C) 1992-2001 Trolltech AS.  All rights reserved. | 
|---|
| 9 | ** | 
|---|
| 10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 
|---|
| 11 | ** | 
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License | 
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file | 
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file. | 
|---|
| 15 | ** | 
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the | 
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 19 | ** packaging of this file. | 
|---|
| 20 | ** | 
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License | 
|---|
| 23 | ** Agreement provided with the Software. | 
|---|
| 24 | ** | 
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 
|---|
| 27 | ** | 
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 
|---|
| 29 | **   information about Qt Commercial License Agreements. | 
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 
|---|
| 32 | ** | 
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are | 
|---|
| 34 | ** not clear to you. | 
|---|
| 35 | ** | 
|---|
| 36 | **********************************************************************/ | 
|---|
| 37 |  | 
|---|
| 38 | // Most of the code here was originally written by Serika Kurusugawa | 
|---|
| 39 | // a.k.a. Junji Takagi, and is included in Qt with the author's permission, | 
|---|
| 40 | // and the grateful thanks of the Trolltech team. | 
|---|
| 41 |  | 
|---|
| 42 | /* | 
|---|
| 43 | * Copyright (C) 1999 Serika Kurusugawa, All rights reserved. | 
|---|
| 44 | * | 
|---|
| 45 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 46 | * modification, are permitted provided that the following conditions | 
|---|
| 47 | * are met: | 
|---|
| 48 | * 1. Redistributions of source code must retain the above copyright | 
|---|
| 49 | *    notice, this list of conditions and the following disclaimer. | 
|---|
| 50 | * 2. Redistributions in binary form must reproduce the above copyright | 
|---|
| 51 | *    notice, this list of conditions and the following disclaimer in the | 
|---|
| 52 | *    documentation and/or other materials provided with the distribution. | 
|---|
| 53 | * | 
|---|
| 54 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | 
|---|
| 55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
|---|
| 56 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
|---|
| 57 | * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 
|---|
| 58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
|---|
| 59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
|---|
| 60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
|---|
| 61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 
|---|
| 62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 
|---|
| 63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
|---|
| 64 | * SUCH DAMAGE. | 
|---|
| 65 | */ | 
|---|
| 66 |  | 
|---|
| 67 | #ifndef QJPUNICODE_H | 
|---|
| 68 | #define QJPUNICODE_H | 
|---|
| 69 |  | 
|---|
| 70 | #ifndef QT_H | 
|---|
| 71 | #include "qglobal.h" | 
|---|
| 72 | #endif // QT_H | 
|---|
| 73 |  | 
|---|
| 74 | #ifndef QT_NO_BIG_CODECS | 
|---|
| 75 |  | 
|---|
| 76 | #if defined(QT_PLUGIN) | 
|---|
| 77 | #define Q_EXPORT_CODECS_JP | 
|---|
| 78 | #else | 
|---|
| 79 | #define Q_EXPORT_CODECS_JP Q_EXPORT | 
|---|
| 80 | #endif | 
|---|
| 81 |  | 
|---|
| 82 | class Q_EXPORT_CODECS_JP QJpUnicodeConv { | 
|---|
| 83 | public: | 
|---|
| 84 | enum Rules { | 
|---|
| 85 | // "ASCII" is ANSI X.3.4-1986, a.k.a. US-ASCII here. | 
|---|
| 86 | Default                 = 0x0000, | 
|---|
| 87 |  | 
|---|
| 88 | Unicode                 = 0x0001, | 
|---|
| 89 | Unicode_JISX0201                = 0x0001, | 
|---|
| 90 | Unicode_ASCII           = 0x0002, | 
|---|
| 91 | JISX0221_JISX0201       = 0x0003, | 
|---|
| 92 | JISX0221_ASCII          = 0x0004, | 
|---|
| 93 | Sun_JDK117              = 0x0005, | 
|---|
| 94 | Microsoft_CP932         = 0x0006, | 
|---|
| 95 |  | 
|---|
| 96 | NEC_VDC         = 0x0100,               // NEC Vender Defined Char | 
|---|
| 97 | UDC                     = 0x0200,               // User Defined Char | 
|---|
| 98 | IBM_VDC         = 0x0400                // IBM Vender Defined Char | 
|---|
| 99 | }; | 
|---|
| 100 | static QJpUnicodeConv *newConverter(int rule); | 
|---|
| 101 |  | 
|---|
| 102 | virtual uint asciiToUnicode(uint h, uint l) const; | 
|---|
| 103 | /*virtual*/ uint jisx0201ToUnicode(uint h, uint l) const; | 
|---|
| 104 | virtual uint jisx0201LatinToUnicode(uint h, uint l) const; | 
|---|
| 105 | /*virtual*/ uint jisx0201KanaToUnicode(uint h, uint l) const; | 
|---|
| 106 | virtual uint jisx0208ToUnicode(uint h, uint l) const; | 
|---|
| 107 | virtual uint jisx0212ToUnicode(uint h, uint l) const; | 
|---|
| 108 |  | 
|---|
| 109 | uint asciiToUnicode(uint ascii) const { | 
|---|
| 110 | return asciiToUnicode((ascii & 0xff00) >> 8, (ascii & 0x00ff)); | 
|---|
| 111 | } | 
|---|
| 112 | uint jisx0201ToUnicode(uint jis) const { | 
|---|
| 113 | return jisx0201ToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); | 
|---|
| 114 | } | 
|---|
| 115 | uint jisx0201LatinToUnicode(uint jis) const { | 
|---|
| 116 | return jisx0201LatinToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); | 
|---|
| 117 | } | 
|---|
| 118 | uint jisx0201KanaToUnicode(uint jis) const { | 
|---|
| 119 | return jisx0201KanaToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); | 
|---|
| 120 | } | 
|---|
| 121 | uint jisx0208ToUnicode(uint jis) const { | 
|---|
| 122 | return jisx0208ToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); | 
|---|
| 123 | } | 
|---|
| 124 | uint jisx0212ToUnicode(uint jis) const { | 
|---|
| 125 | return jisx0212ToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | virtual uint unicodeToAscii(uint h, uint l) const; | 
|---|
| 129 | /*virtual*/ uint unicodeToJisx0201(uint h, uint l) const; | 
|---|
| 130 | virtual uint unicodeToJisx0201Latin(uint h, uint l) const; | 
|---|
| 131 | /*virtual*/ uint unicodeToJisx0201Kana(uint h, uint l) const; | 
|---|
| 132 | virtual uint unicodeToJisx0208(uint h, uint l) const; | 
|---|
| 133 | virtual uint unicodeToJisx0212(uint h, uint l) const; | 
|---|
| 134 |  | 
|---|
| 135 | uint unicodeToAscii(uint unicode) const { | 
|---|
| 136 | return unicodeToAscii((unicode & 0xff00) >> 8, (unicode & 0x00ff)); | 
|---|
| 137 | } | 
|---|
| 138 | uint unicodeToJisx0201(uint unicode) const { | 
|---|
| 139 | return unicodeToJisx0201((unicode & 0xff00) >> 8, (unicode & 0x00ff)); | 
|---|
| 140 | } | 
|---|
| 141 | uint unicodeToJisx0201Latin(uint unicode) const { | 
|---|
| 142 | return unicodeToJisx0201Latin((unicode & 0xff00) >> 8, (unicode & 0x00ff)); | 
|---|
| 143 | } | 
|---|
| 144 | uint unicodeToJisx0201Kana(uint unicode) const { | 
|---|
| 145 | return unicodeToJisx0201Kana((unicode & 0xff00) >> 8, (unicode & 0x00ff)); | 
|---|
| 146 | } | 
|---|
| 147 | uint unicodeToJisx0208(uint unicode) const { | 
|---|
| 148 | return unicodeToJisx0208((unicode & 0xff00) >> 8, (unicode & 0x00ff)); | 
|---|
| 149 | } | 
|---|
| 150 | uint unicodeToJisx0212(uint unicode) const { | 
|---|
| 151 | return unicodeToJisx0212((unicode & 0xff00) >> 8, (unicode & 0x00ff)); | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 | uint sjisToUnicode(uint h, uint l) const; | 
|---|
| 155 | uint unicodeToSjis(uint h, uint l) const; | 
|---|
| 156 |  | 
|---|
| 157 | uint sjisToUnicode(uint sjis) const { | 
|---|
| 158 | return sjisToUnicode((sjis & 0xff00) >> 8, (sjis & 0x00ff)); | 
|---|
| 159 | } | 
|---|
| 160 | uint unicodeToSjis(uint unicode) const { | 
|---|
| 161 | return unicodeToSjis((unicode & 0xff00) >> 8, (unicode & 0x00ff)); | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | protected: | 
|---|
| 165 | QJpUnicodeConv(int r) : rule(r) {} | 
|---|
| 166 |  | 
|---|
| 167 | private: | 
|---|
| 168 | int rule; | 
|---|
| 169 | }; | 
|---|
| 170 |  | 
|---|
| 171 | #endif // QT_NO_BIG_CODECS | 
|---|
| 172 | #endif /* QJPUNICODE_H */ | 
|---|