1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtCore module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 // Most of the code here was originally written by Serika Kurusugawa 41 // a.k.a. Junji Takagi, and is included in Qt with the author's permission, 42 // and the grateful thanks of the Qt team. 43 44 /* 45 * Copyright (C) 1999 Serika Kurusugawa, All rights reserved. 46 * 47 * Redistribution and use in source and binary forms, with or without 48 * modification, are permitted provided that the following conditions 49 * are met: 50 * 1. Redistributions of source code must retain the above copyright 51 * notice, this list of conditions and the following disclaimer. 52 * 2. Redistributions in binary form must reproduce the above copyright 53 * notice, this list of conditions and the following disclaimer in the 54 * documentation and/or other materials provided with the distribution. 55 * 56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 66 * SUCH DAMAGE. 67 */ 68 69 #ifndef QJPUNICODE_P_H 70 #define QJPUNICODE_P_H 71 72 // 73 // W A R N I N G 74 // ------------- 75 // 76 // This file is not part of the Qt API. It exists for the convenience 77 // of other Qt classes. This header file may change from version to 78 // version without notice, or even be removed. 79 // 80 // We mean it. 81 // 82 83 #include <QtCore/private/qglobal_p.h> 84 85 QT_REQUIRE_CONFIG(big_codecs); 86 87 QT_BEGIN_NAMESPACE 88 89 class QJpUnicodeConv { 90 public: ~QJpUnicodeConv()91 virtual ~QJpUnicodeConv() {} 92 enum Rules { 93 // "ASCII" is ANSI X.3.4-1986, a.k.a. US-ASCII here. 94 Default = 0x0000, 95 96 Unicode = 0x0001, 97 Unicode_JISX0201 = 0x0001, 98 Unicode_ASCII = 0x0002, 99 JISX0221_JISX0201 = 0x0003, 100 JISX0221_ASCII = 0x0004, 101 Sun_JDK117 = 0x0005, 102 Microsoft_CP932 = 0x0006, 103 104 NEC_VDC = 0x0100, // NEC Vender Defined Char 105 UDC = 0x0200, // User Defined Char 106 IBM_VDC = 0x0400 // IBM Vender Defined Char 107 }; 108 static QJpUnicodeConv *newConverter(int rule); 109 110 virtual uint asciiToUnicode(uint h, uint l) const; 111 /*virtual*/ uint jisx0201ToUnicode(uint h, uint l) const; 112 virtual uint jisx0201LatinToUnicode(uint h, uint l) const; 113 /*virtual*/ uint jisx0201KanaToUnicode(uint h, uint l) const; 114 virtual uint jisx0208ToUnicode(uint h, uint l) const; 115 virtual uint jisx0212ToUnicode(uint h, uint l) const; 116 asciiToUnicode(uint ascii)117 uint asciiToUnicode(uint ascii) const { 118 return asciiToUnicode((ascii & 0xff00) >> 8, (ascii & 0x00ff)); 119 } jisx0201ToUnicode(uint jis)120 uint jisx0201ToUnicode(uint jis) const { 121 return jisx0201ToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); 122 } jisx0201LatinToUnicode(uint jis)123 uint jisx0201LatinToUnicode(uint jis) const { 124 return jisx0201LatinToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); 125 } jisx0201KanaToUnicode(uint jis)126 uint jisx0201KanaToUnicode(uint jis) const { 127 return jisx0201KanaToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); 128 } jisx0208ToUnicode(uint jis)129 uint jisx0208ToUnicode(uint jis) const { 130 return jisx0208ToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); 131 } jisx0212ToUnicode(uint jis)132 uint jisx0212ToUnicode(uint jis) const { 133 return jisx0212ToUnicode((jis & 0xff00) >> 8, (jis & 0x00ff)); 134 } 135 136 virtual uint unicodeToAscii(uint h, uint l) const; 137 /*virtual*/ uint unicodeToJisx0201(uint h, uint l) const; 138 virtual uint unicodeToJisx0201Latin(uint h, uint l) const; 139 /*virtual*/ uint unicodeToJisx0201Kana(uint h, uint l) const; 140 virtual uint unicodeToJisx0208(uint h, uint l) const; 141 virtual uint unicodeToJisx0212(uint h, uint l) const; 142 unicodeToAscii(uint unicode)143 uint unicodeToAscii(uint unicode) const { 144 return unicodeToAscii((unicode & 0xff00) >> 8, (unicode & 0x00ff)); 145 } unicodeToJisx0201(uint unicode)146 uint unicodeToJisx0201(uint unicode) const { 147 return unicodeToJisx0201((unicode & 0xff00) >> 8, (unicode & 0x00ff)); 148 } unicodeToJisx0201Latin(uint unicode)149 uint unicodeToJisx0201Latin(uint unicode) const { 150 return unicodeToJisx0201Latin((unicode & 0xff00) >> 8, (unicode & 0x00ff)); 151 } unicodeToJisx0201Kana(uint unicode)152 uint unicodeToJisx0201Kana(uint unicode) const { 153 return unicodeToJisx0201Kana((unicode & 0xff00) >> 8, (unicode & 0x00ff)); 154 } unicodeToJisx0208(uint unicode)155 uint unicodeToJisx0208(uint unicode) const { 156 return unicodeToJisx0208((unicode & 0xff00) >> 8, (unicode & 0x00ff)); 157 } unicodeToJisx0212(uint unicode)158 uint unicodeToJisx0212(uint unicode) const { 159 return unicodeToJisx0212((unicode & 0xff00) >> 8, (unicode & 0x00ff)); 160 } 161 162 uint sjisToUnicode(uint h, uint l) const; 163 uint unicodeToSjis(uint h, uint l) const; 164 uint sjisibmvdcToUnicode(uint h, uint l) const; 165 uint unicodeToSjisibmvdc(uint h, uint l) const; 166 uint cp932ToUnicode(uint h, uint l) const; 167 uint unicodeToCp932(uint h, uint l) const; 168 sjisToUnicode(uint sjis)169 uint sjisToUnicode(uint sjis) const { 170 return sjisToUnicode((sjis & 0xff00) >> 8, (sjis & 0x00ff)); 171 } unicodeToSjis(uint unicode)172 uint unicodeToSjis(uint unicode) const { 173 return unicodeToSjis((unicode & 0xff00) >> 8, (unicode & 0x00ff)); 174 } 175 176 protected: QJpUnicodeConv(int r)177 explicit QJpUnicodeConv(int r) : rule(r) {} 178 179 private: 180 int rule; 181 }; 182 183 QT_END_NAMESPACE 184 185 #endif // QJPUNICODE_P_H 186