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